Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions gradio/external_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ def chat_fn(message, history):
history = []
history.append({"role": "user", "content": message})
try:
out = ""
out_chunks = []
append = out_chunks.append # Localize for faster loop execution
for chunk in client.chat_completion(messages=history, stream=True):
out += chunk.choices[0].delta.content or "" if chunk.choices else ""
yield out
if chunk.choices:
content = chunk.choices[0].delta.content
if content:
append(content)
yield "".join(out_chunks)
except Exception as e:
handle_hf_error(e)

Expand Down