mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-05 11:10:03 +08:00
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:
parent
61cd768490
commit
a72e1a9768
5
.changeset/early-eels-repair.md
Normal file
5
.changeset/early-eels-repair.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Streaming Markdown in chatbot Component Fix
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user