Skip to content

Commit

Permalink
Fixes for function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nfiacco committed Jun 12, 2024
1 parent 88c8c01 commit d07a135
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion demospace/livekit/openai_assistant/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,25 @@ def _add_text_to_stream(self, llm_stream: LLMStream, text: str, role: str) -> No
async def _handle_response_stream(
self, stream: openai.AsyncAssistantEventHandler, llm_stream: LLMStream
) -> None:
gathering_function_call = False
function_args = ""
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" in chunk.data.delta.content[0].text.value:
self._add_text_to_stream(llm_stream, "\n", "assistant")
function_args += "{"
gathering_function_call = True
elif "\n})" in chunk.data.delta.content[0].text.value:
function_args += "}"
logging.info(f"Manually sending asset: {function_args}")
await send_asset(function_args, self._room)
function_args = ""
gathering_function_call = False
elif gathering_function_call:
function_args += 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 d07a135

Please sign in to comment.