Streaming Markdown in chatbot Component Fix (#9780)

* fix

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Dawood Khan 2024-10-21 21:55:54 -04:00 committed by GitHub
parent 61cd768490
commit a72e1a9768
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Streaming Markdown in chatbot Component Fix

View File

@ -445,12 +445,10 @@ class Chatbot(Component):
) -> str | FileMessage | ComponentMessage | None:
if chat_message is None:
return None
elif isinstance(chat_message, FileMessage):
if isinstance(chat_message, (FileMessage, ComponentMessage, str)):
return chat_message
elif isinstance(chat_message, FileData):
return FileMessage(file=chat_message)
elif isinstance(chat_message, ComponentMessage):
return chat_message
elif isinstance(chat_message, GradioComponent):
chat_message.unrender()
component = import_component_and_data(type(chat_message).__name__)
@ -471,9 +469,6 @@ class Chatbot(Component):
elif isinstance(chat_message, (tuple, list)):
filepath = str(chat_message[0])
return self._create_file_message(chat_message, filepath)
elif isinstance(chat_message, str):
chat_message = inspect.cleandoc(chat_message)
return chat_message
else:
raise ValueError(f"Invalid message for Chatbot component: {chat_message}")
@ -508,6 +503,11 @@ class Chatbot(Component):
f"Invalid message for Chatbot component: {message}", visible=False
)
msg.content = (
inspect.cleandoc(msg.content)
if isinstance(msg.content, str)
else msg.content
)
return msg
def postprocess(