Skip to content

Commit

Permalink
Handle function calls in response
Browse files Browse the repository at this point in the history
  • Loading branch information
nfiacco committed Jun 12, 2024
1 parent 18ff7b0 commit 6d2af02
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion demospace/livekit/openai_assistant/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,22 @@ def _add_chunk_to_stream(
async def _handle_response_stream(
self, stream: openai.AsyncAssistantEventHandler, llm_stream: LLMStream
) -> None:
gathering_function_call = False
function_call = ""
async for chunk in stream:
self._active_run = stream.current_run
if chunk.event == "thread.message.delta":
self._add_chunk_to_stream(llm_stream, chunk)
if "\n\n" in chunk.data.delta.content[0].text.value:
if gathering_function_call:
gathering_function_call = False
logging.info(f"Function call: {function_call}")
# await send_asset(function_call, self._room)
else:
gathering_function_call = True
elif gathering_function_call:
function_call += chunk.data.delta.content[0].text.value
else:
self._add_chunk_to_stream(llm_stream, chunk)
elif chunk.event == "thread.run.completed":
self._active_run = None
llm_stream.push_text(None)
Expand Down

0 comments on commit 6d2af02

Please sign in to comment.