Skip to content

Make Chatbot progress timer stop at last (not first) assistant message #11637

@jedick

Description

@jedick
  • I have searched to see if a similar issue already exists.
  • Problem: When interacting with gr.Chatbot(), the progress timer stops after the first assistant message.
  • Why this is a problem: Stopping the timer prematurely gives the user the false impression that the interaction has completed.
  • Solution: The progress timer should keep going until the assistant stops responding.
  • Additional context: This behavior shows up during consecutive yield statements for agent interactions: https://www.gradio.app/guides/agents-and-tool-usage

Reproduction (see demo at HF Spaces: jedick/chatbot-progress):

import gradio as gr
import time


def interact_with_agent(prompt, messages=[]):
    """Simulate generation of two assistant messages after delays"""
    time.sleep(2)
    messages.append(
        gr.ChatMessage(
            role="assistant", content="Progress timer stops here (or becomes invisible)"
        )
    )
    yield messages
    time.sleep(2)
    messages.append(
        gr.ChatMessage(role="assistant", content="But I want it to stop here")
    )
    yield messages


def str_to_message(content, role="user"):
    return [gr.ChatMessage(role=role, content=content)]


with gr.Blocks() as demo:
    chatbot = gr.Chatbot(
        type="messages",
    )
    input = gr.Textbox(
        "Start the simulation with two assistant messages after 2-second delays",
        autofocus=True,
    )
    input.submit(
        # Update chatbot UI with user message immediately
        str_to_message,
        input,
        chatbot,
    ).then(
        # Update chatbot UI with assistant messages
        interact_with_agent,
        [input, chatbot],
        chatbot,
    )

demo.launch()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions