Function Calling with generateContent() causes error: "ensure that function response turn comes immediately after a function call turn" #267
Labels
component:js sdk
Issue/PR related to JavaScript SDK
status:triaged
Issue/PR triaged to the corresponding sub-team
type:help
Support-related issues
Description of the bug:
I have followed this tutorial and have got it working, however as soon as I switch from using
chat.sendMessage
togenerateContent
, I get the error:GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [400 Bad Request] Please ensure that function response turn comes immediately after a function call turn.
at the point:
My environment:
const {GoogleGenerativeAI} = require("@google/generative-ai");
Many thanks for your help!
Actual vs expected behavior:
Actual:
Get the error:
GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [400 Bad Request] Please ensure that function response turn comes immediately after a function call turn.
Expected:
Execute the function correctly. (eg. return
OK. I've dimmed the lights to 50% and set the color temperature to warm. Let me know if you want to adjust the lighting further.
)Any other information you'd like to share?
Code comparison
When using
chat.sendMessage
When using
generateContent
I have also tried specifying the version to be v1beta to no benefit as follows:
The text was updated successfully, but these errors were encountered: