Skip to content

Commit

Permalink
fix: utf-8 streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr0p42 committed Feb 18, 2025
1 parent 15eb4b2 commit 43ea5f5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/abi/services/agent/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ async def stream_completion(query: CompletionQuery):
new_agent.state.set_thread_id(query.thread_id)
return EventSourceResponse(
new_agent.stream_invoke(query.prompt),
media_type='text/event-stream'
media_type='text/event-stream; charset=utf-8'
)

def stream_invoke(self, prompt: str):
Expand Down Expand Up @@ -429,12 +429,12 @@ def run_invoke():
if isinstance(message, ToolUsageEvent):
yield {
"event": "tool_usage",
"data": message.payload.tool_calls[0]['name']
"data": str(message.payload.tool_calls[0]['name'])
}
elif isinstance(message, ToolResponseEvent):
yield {
"event": "tool_response",
"data": message.payload.content
"data": str(message.payload.content)
}
elif isinstance(message, FinalStateEvent):
final_state = message.payload
Expand All @@ -454,11 +454,11 @@ def run_invoke():
for char in response:
buffer += char
if char in ['\n', '\r']:
if buffer.strip(): # Only send non-empty lines
yield {
"event": "message",
"data": buffer.rstrip()
}
# if buffer.strip(): # Only send non-empty lines
yield {
"event": "message",
"data": buffer.rstrip()
}
buffer = ""

# Don't forget remaining text
Expand Down

0 comments on commit 43ea5f5

Please sign in to comment.