Skip to content

Commit

Permalink
fix streaming message bug
Browse files Browse the repository at this point in the history
  • Loading branch information
phact committed May 31, 2024
1 parent 14d0650 commit ae7c882
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions impl/routes_v2/threads_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ async def run_event_stream(run, message_id, astradb):
#event_json = event.json()
#yield f"data: {event_json}\n\n"

async for event in stream_message_events(astradb, run.thread_id, None, "desc", None, None, run):
async for event in stream_message_events(astradb, run.thread_id, 1, "desc", None, None, run):
yield event


Expand All @@ -475,9 +475,6 @@ async def stream_message_events(astradb, thread_id, limit, order, after, before,
logger.info(f"fetching messages for thread {thread_id}")
messages = await get_and_process_assistant_messages(astradb, thread_id, limit, order, after, before)

first_id = messages[0].id
last_id = messages[len(messages) - 1].id

current_message = None
last_message_length = 0

Expand Down Expand Up @@ -1363,7 +1360,7 @@ def get_messages_by_thread(astradb, thread_id, limit=None, order=None, after=Non
async def get_and_process_assistant_messages(astradb, thread_id, limit, order, after, before):
messages = get_and_process_messages(astradb, thread_id, limit, order, after, before)

if messages[0].run_id is None:
if len(messages) == 0 or messages[0].run_id is None:
await asyncio.sleep(1)
return await get_and_process_assistant_messages(astradb, thread_id, limit, order, after, before)
return messages
Expand Down

0 comments on commit ae7c882

Please sign in to comment.