-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
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.
gradio/gradio/chat_interface.py
Lines 888 to 899 in dfda39f
| 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.