generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

stream=True returns all chunks at the same time [in Colab]

Open sykp241095 opened this issue 1 year ago • 1 comments

Description of the bug:

I have read the docs here https://ai.google.dev/api/python/google/generativeai/GenerativeModel to learn that use stream=True could return chunks of response one by one, but when I was trying with the following simple code, it doesn't work, it return chunks, but it seems like to return all the chunks at the same time:

import google.generativeai as genai


genai.configure(api_key='....')
model = genai.GenerativeModel('models/gemini-pro')

response = model.generate_content('generate a long story, more than 200 words, multiple graphs with breakline', stream=True)


for chunk in response:
    print(chunk.text)

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

sykp241095 avatar May 08 '24 11:05 sykp241095

@sykp241095 thanks for reporting.

This is a limitation of Colab, long story. Try anywhere except Colab and you should get the chunks back as they are generated. Let me know if that works for you.

MarkDaoust avatar May 09 '24 23:05 MarkDaoust

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] avatar May 29 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!

github-actions[bot] avatar Jun 12 '24 01:06 github-actions[bot]