[GH-ISSUE #9364] Streaming documentation error #31874

Closed
opened 2026-04-22 12:39:08 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @sancelot on GitHub (Feb 26, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9364

What is the issue?

Hi,
The streaming demo in documentation does not work, you have to use asyncio.sleep

https://www.gradio.app/main/docs/gradio/chatbot#demos

import gradio as gr
import random
import asyncio

with gr.Blocks() as demo:
    chatbot = gr.Chatbot(type="messages")
    msg = gr.Textbox()
    clear = gr.Button("Clear")

    def user(user_message, history: list):
        return "", history + [{"role": "user", "content": user_message}]

    async def bot(history: list):
        bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
        history.append({"role": "assistant", "content": ""})
        for character in bot_message:
            history[-1]['content'] += str(character)
            await asyncio.sleep(1)
            yield history

    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    clear.click(lambda: None, None, chatbot, queue=False)

if __name__ == "__main__":
    demo.launch()

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @sancelot on GitHub (Feb 26, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9364 ### What is the issue? Hi, The streaming demo in documentation does not work, you have to use asyncio.sleep https://www.gradio.app/main/docs/gradio/chatbot#demos ``` import gradio as gr import random import asyncio with gr.Blocks() as demo: chatbot = gr.Chatbot(type="messages") msg = gr.Textbox() clear = gr.Button("Clear") def user(user_message, history: list): return "", history + [{"role": "user", "content": user_message}] async def bot(history: list): bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) history.append({"role": "assistant", "content": ""}) for character in bot_message: history[-1]['content'] += str(character) await asyncio.sleep(1) yield history msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( bot, chatbot, chatbot ) clear.click(lambda: None, None, chatbot, queue=False) if __name__ == "__main__": demo.launch() ``` ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the bug label 2026-04-22 12:39:08 -05:00
Author
Owner

@rick-github commented on GitHub (Feb 26, 2025):

See here for filing gradio issues.

<!-- gh-comment-id:2685420187 --> @rick-github commented on GitHub (Feb 26, 2025): See [here](https://github.com/gradio-app/gradio/issues/new/choose) for filing gradio issues.
Author
Owner

@manualsh commented on GitHub (Mar 3, 2025):

+1

Same for Streamlit. Currently only OpenAI supports streaming for streamlit.

<!-- gh-comment-id:2693462266 --> @manualsh commented on GitHub (Mar 3, 2025): +1 Same for Streamlit. Currently only OpenAI supports streaming for streamlit.
Author
Owner

@sancelot commented on GitHub (Mar 3, 2025):

@manualsh it works using dedicated async python3 syntax. Nothing related to any llm.only a documentation example to correct....

<!-- gh-comment-id:2693477957 --> @sancelot commented on GitHub (Mar 3, 2025): @manualsh it works using dedicated async python3 syntax. Nothing related to any llm.only a documentation example to correct....
Author
Owner

@rick-github commented on GitHub (Mar 3, 2025):

If this is not related to ollama, please close this issue. If it is related to ollama, explain how.

<!-- gh-comment-id:2693480747 --> @rick-github commented on GitHub (Mar 3, 2025): If this is not related to ollama, please close this issue. If it is related to ollama, explain how.
Author
Owner

@sancelot commented on GitHub (Mar 3, 2025):

Oh very sorry . This is a gradio bug I filled in the wrong project

<!-- gh-comment-id:2693585533 --> @sancelot commented on GitHub (Mar 3, 2025): Oh very sorry . This is a gradio bug I filled in the wrong project
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31874