Unable to Make Function Calling Work with Multimodal Live API
Current Issue
I am unable to get function calling to work with the multimodal live API. The API keeps returning executable code and attempting to execute it, as shown in this response format:
{
"modelTurn": {
"parts": [
{
"executableCode": {
"language": "PYTHON",
"code": "..." // code
}
}
]
}
}
Configuration Code
Function Declaration
add_item = FunctionDeclaration(
name="add_item",
description="Add an item to the inventory list. Takes a complete item object containing all required fields.",
parameters={
"type": "OBJECT",
"properties": {
"item": {
"type": "OBJECT",
"description": "Complete item information",
"properties": {
"Item": {
"type": "STRING",
"description": "Name of the detected item",
},
"Make": {
"type": "STRING",
"description": "Manufacturer name or NA",
},
"Model": {
"type": "STRING",
"description": "Model identifier or NA",
},
"Year": {
"type": "STRING",
"description": "Manufacturing year or NA",
},
"Serial_Number": {
"type": "STRING",
"description": "Unique identifier or NA",
},
"Description": {
"type": "STRING",
"description": "Includes cleanliness assessment, color and other general details",
},
"Approximate_price": {
"type": "STRING",
"description": "Web-searched current market value (with currency symbol)",
},
"where_was_this_detected": {
"type": "STRING",
"description": "Location + timestamp in HH:MM:ss format",
},
"questions": {
"type": "STRING",
"description": "Missing or uncertain information, price variations, or 'None'",
},
},
"required": [
"Item",
"Make",
"Model",
"Year",
"Serial_Number",
"Description",
"Approximate_price",
"where_was_this_detected",
"questions",
],
}
},
"required": ["item"],
},
)
Tool Configuration
add_item_tool = Tool(function_declarations=[add_item])
Live API Connection Configuration
live_connect_config = LiveConnectConfig(
response_modalities=["TEXT"],
tools=[add_item_tool],
system_instruction=Content(parts=[{"text": SYSTEM_INSTRUCTION}]),
)