Module: Gemini::FunctionCallingHelper

Defined in:
lib/gemini/function_calling_helper.rb

Class Method Summary collapse

Class Method Details

.build_continuation(original_contents:, model_response:, function_responses:) ⇒ Array

Function Callレスポンスから継続用のcontentsを構築Gemini 3では関数呼び出しの継続時にThought Signatureが必須

Examples:

contents = Gemini::FunctionCallingHelper.build_continuation(
  original_contents: [{ role: "user", parts: [{ text: "東京の天気を教えて" }] }],
  model_response: response,
  function_responses: [
    { name: "get_weather", response: { temperature: 20, condition: "晴れ" } }
  ]
)

Parameters:

  • original_contents (Array)

    元の会話履歴

  • model_response (Gemini::Response)

    モデルの応答(function call含む)

  • function_responses (Array<Hash>)

    関数の結果の配列各要素は { name: “function_name”, response: { … } } の形式

Returns:

  • (Array)

    継続リクエスト用のcontents配列



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gemini/function_calling_helper.rb', line 22

def self.build_continuation(original_contents:, model_response:, function_responses:)
  # 元の会話履歴
  contents = original_contents.dup

  # モデルの応答(Signature付き)
  contents << {
    role: "model",
    parts: model_response.build_function_call_parts_with_signature
  }

  # 関数の結果
  function_response_parts = function_responses.map do |fr|
    { functionResponse: fr }
  end

  contents << {
    role: "user",
    parts: function_response_parts
  }

  contents
end