Skip to content

Commit

Permalink
Add separator when LLM starts streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Frank committed Sep 26, 2024
1 parent eca5311 commit 553c2bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/neuroagent/agents/simple_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ async def astream(
streamed_response = self.agent.astream_events(
{"messages": query}, version="v2", config=config
)
is_streaming = False
async for event in streamed_response:
kind = event["event"]

# newline everytime model starts streaming.
if kind == "on_chat_model_start":
yield "\n\n"
# check for the model stream.
if kind == "on_chat_model_stream":
# check if we are calling the tools.
Expand All @@ -95,6 +92,9 @@ async def astream(

content = data_chunk.content
if content:
if not is_streaming:
yield "\n<begin_llm_response>\n"
is_streaming = True
yield content
yield "\n"

Expand Down
4 changes: 2 additions & 2 deletions tests/agents/test_simple_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ async def test_astream(fake_llm_with_tools, httpx_mock):

msg_list = "".join([el async for el in response])
assert (
msg_list == "\n\n\nCalling tool : get-morpho-tool with arguments :"
' {"brain_region_id":"http://api.brain-map.org/api/v2/data/Structure/549"}\n\nGreat'
msg_list == "\nCalling tool : get-morpho-tool with arguments :"
' {"brain_region_id":"http://api.brain-map.org/api/v2/data/Structure/549"}\n<begin_llm_response>\nGreat'
" answer\n"
)

Expand Down

0 comments on commit 553c2bd

Please sign in to comment.