Module: Raif::Concerns::Llms::Google::ResponseToolCalls

Extended by:
ActiveSupport::Concern
Included in:
Llms::Google
Defined in:
app/models/raif/concerns/llms/google/response_tool_calls.rb

Instance Method Summary collapse

Instance Method Details

#extract_response_tool_calls(resp) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/raif/concerns/llms/google/response_tool_calls.rb', line 6

def extract_response_tool_calls(resp)
  parts = resp&.dig("candidates", 0, "content", "parts")
  return if parts.blank?

  # Find any functionCall parts
  function_calls = parts.select { |part| part.key?("functionCall") }

  return if function_calls.blank?

  function_calls.map do |part|
    function_call = part["functionCall"]
    tool_call = {
      # Google doesn't provide a unique ID for function calls, so we generate one
      "provider_tool_call_id" => SecureRandom.uuid,
      "name" => function_call["name"],
      "arguments" => function_call["args"]
    }

    # Capture thoughtSignature if present (required for Gemini 2.5+ thinking models)
    if part["thoughtSignature"].present?
      tool_call["provider_metadata"] = { "thought_signature" => part["thoughtSignature"] }
    end

    tool_call
  end
end