googleapis / googleapis/python-genai
Function call args are not streamed in chunks
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
During streaming, when a function call's args are very long, they are still returned as a single chunk, not streamed into separate chunks. To reproduce, use this code
```
import google.genai as genai
tool_definition = {
"name": "get_weather",
"description": "Get the weather in a city",
"parameters": {
"properties": {
"city1": {
"description": "The city to get the weather for city1",
"type": "string",
},
"city2": {
"description": "The city to get the weather for city2",
"type": "string",
},
"city3": {
"description": "The city to get the weather for city3",
"type": "string",
},
"city4": {
"description": "The city to get the weather for city4",
"type": "string",
},
"city5": {
"description": "The city to get the weather for city5",
"type": "string",
},
"city6": {
"description": "The city to get the weather for city6",
"type": "string",
},
"city7": {
"description": "The city to get the weather for city7",
"type": "string",
},
"city8": {
"description": "The city to get the weather for city8",
"type": "string",
},
"city9": {
"description": "The city to get the weather for city9",
"type": "string",
},
"city10": {
"description": "The city to get the weather for city10",
"type": "string",
},
"city11": {
"description": "The city to get the weather for city11",
"type": "string",
},
"city12": {
"description": "The city to get the weather for city12",
"type": "string",
},
"city13": {
"description": "The city to get the weather for city13",
"type": "string",
},
"city14": {
"description": "The city to get the weather for city14",
"type": "string",
},
"city15": {
"description": "The city to get the weather for city15",
"type": "string",
},
"city16": {
"description": "The city to get the weather for city16",
"type": "string",
},
"city17": {
"description": "The city to get the weather for city17",
"type": "string",
},
"city18": {
"description": "The city to get the weather for city18",
"type": "string",
},
"city19": {
"description": "The city to get the weather for city19",
"type": "string",
},
"city20": {
"description": "The city to get the weather for city20",
"type": "string",
},
},
"required": [
"city1",
"city2",
"city3",
"city4",
"city5",
"city6",
"city7",
"city8",
"city9",
"city10",
"city11",
"city12",
"city13",
"city14",
"city15",
"city16",
"city17",
"city18",
"city19",
"city20",
],
"type": "object",
},
}
client = genai.Client()
response = client.models.generate_content_stream(
model="gemini-2.5-flash",
contents=[
{
"role": "user",
"parts": [
{
"text": "whats the weather in the city of Tokyo, San Francisco, London, Rome, Napoli, Los Angeles, Osaka, Helsinki, Moscow, Geneva, Zurich, Paris, Marseilles, Nice, Genoa, Bologna, Matera, Bari, Milano, Venezia?"
}
],
}
],
config={"tools": [{"function_declarations": [tool_definition]}]},
)
for chunk in response:
print(chunk.model_dump_json(indent=4))
print("-" * 100)
```
Streaming long function args of a SINGLE function call into separate chunks is supported by all other major AI providers (openai, anthropic, etc.)
Contributor guide
Assessment
This issue has not been assessed yet.