Module: LLM::Google::Utils

Defined in:
lib/llm/providers/google/utils.rb

Instance Method Summary collapse

Instance Method Details

#tool_id(part:, cindex:, pindex:) ⇒ String

Returns a stable internal tool-call ID for a call.

Gemini responses may omit a direct tool-call ID, but llm.rb expects one for matching a pending call with its return. The call's own ID is preferred, then the candidate and part indexes, which are stable within a response.

Parameters:

  • part (Hash) —

    A content part that holds a functionCall

  • cindex (Integer) —

    The candidate index

  • pindex (Integer) —

    The part index within the candidate

Returns:

  • (String)


21
22
23
24
25
# File 'lib/llm/providers/google/utils.rb', line 21

def tool_id(part:, cindex:, pindex:)
  id = part.dig("functionCall", "id").to_s
  return "google_#{id}" unless id.empty?
  "google_call_#{cindex}_#{pindex}"
end