Skip to content

Discrepancy between how history is treated for streaming/non-streaming gr.ChatInterface #10823

@abidlabs

Description

@abidlabs

Not exactly a bug but it turns out that if you modify the history inside the chat function of gr.ChatInterface, the behavior is different depending on if its a streaming/non-streaming gr.ChatInterface

As @hysts pointed out, this stems from the fact that when a generator is passed, the original history is passed to the generator first, but history is overwritten by _append_message_to_history before actually executing the generator, so the history inside the generator and the one outside of it become two different objects, and the changes to the history inside the generator doesn't affect the history outside.

if self.is_async:
generator = self.fn(*inputs)
else:
generator = await anyio.to_thread.run_sync(
self.fn, *inputs, limiter=self.limiter
)
generator = utils.SyncToAsyncIterator(generator, self.limiter)
history = self._append_message_to_history(message, history, "user")
additional_outputs = None
try:
first_response = await utils.async_iteration(generator)

this implementation difference seems very confusing and error prone.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working💬 ChatbotRelated to the Chatbot component

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions