Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/langchain/llm/response/google_gemini_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def role
end

def tool_calls
if raw_response.dig("candidates", 0, "content") && raw_response.dig("candidates", 0, "content", "parts", 0).has_key?("functionCall")
if raw_response.dig("candidates", 0, "content", "parts") && raw_response.dig("candidates", 0, "content", "parts", 0).has_key?("functionCall")
raw_response.dig("candidates", 0, "content", "parts")
else
[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"candidates": [
{
"content": {
"role": "model"
},
"finishReason": "MAX_TOKENS",
"index": 0
}
]
}
11 changes: 11 additions & 0 deletions spec/lib/langchain/llm/response/google_gemini_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
it "returns tool_calls" do
expect(response.tool_calls).to eq([{"functionCall" => {"name" => "calculator__execute", "args" => {"input" => "2+2"}}}])
end

context 'when output has reached max tokens' do
let(:raw_response) {
JSON.parse File.read("spec/fixtures/llm/google_gemini/chat_with_tool_calls_max_tokens.json")
}
let(:response) { described_class.new(raw_response) }

it "returns tool_calls" do
expect(response.tool_calls).to eq([])
end
end
end

describe "#embeddings" do
Expand Down