From d0ce65a4452f4ff81fc53745e0ed3ee90f1aa0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Monnom?= Date: Tue, 3 Sep 2024 18:48:09 -0700 Subject: [PATCH] skip processing of choice.delta when it is None (#705) --- .changeset/yellow-berries-play.md | 5 +++++ .../livekit-plugins-openai/livekit/plugins/openai/llm.py | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/yellow-berries-play.md diff --git a/.changeset/yellow-berries-play.md b/.changeset/yellow-berries-play.md new file mode 100644 index 000000000..2f94493c3 --- /dev/null +++ b/.changeset/yellow-berries-play.md @@ -0,0 +1,5 @@ +--- +"livekit-plugins-openai": patch +--- + +skip processing of choice.delta when it is None diff --git a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py index e531932db..8dcb67a65 100644 --- a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py +++ b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py @@ -349,6 +349,11 @@ async def __anext__(self): def _parse_choice(self, choice: Choice) -> llm.ChatChunk | None: delta = choice.delta + # https://github.com/livekit/agents/issues/688 + # the delta can be None when using Azure OpenAI using content filtering + if delta is None: + return None + if delta.tool_calls: # check if we have functions to calls for tool in delta.tool_calls: