You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 26, 2026. It is now read-only.
import google.ai.generativelanguage as glm
import datetimetime
import os
client = glm.GenerativeServiceClient(transport='rest', client_options={"api_key":os.environ['GOOGLE_API_KEY']})
times= [datetime.datetime.now()]
stream = client.stream_generate_content(
model='models/gemini-1.5-pro',
contents=[{'parts':[{'text':'Tell me a story about a talking cat named Bob.'}]}])
for chunk in stream:
print(chunk.candidates[0].content.parts)
print('#'*120)
times.append(datetime.datetime.now())
for time in times:
print(time)
Look at the output times, it's not streaming, It waits 10s, and then outputs all the chunks at once.
This problem goes away (the times are evenly spaced because the output is actually streaming) if:
You use transport=GRPC, or
In google.ai.generativelanguage you set "stream=True" in the generated code here.
Environment details
Steps to reproduce
Look at the output times, it's not streaming, It waits 10s, and then outputs all the chunks at once.
This problem goes away (the times are evenly spaced because the output is actually streaming) if:
transport=GRPC, orgoogle.ai.generativelanguageyou set "stream=True" in the generated code here.