diff --git a/changelog/4152.fixed.md b/changelog/4152.fixed.md new file mode 100644 index 000000000..e752bb1ac --- /dev/null +++ b/changelog/4152.fixed.md @@ -0,0 +1 @@ +- Fixed a crash in OpenAI LLM processing when the provider returns `chunk.choices[0].delta.audio = None`, which caused `'NoneType' object has no attribute 'get'` errors during audio transcript handling. diff --git a/src/pipecat/services/openai/base_llm.py b/src/pipecat/services/openai/base_llm.py index fe735daeb..c06ed3afd 100644 --- a/src/pipecat/services/openai/base_llm.py +++ b/src/pipecat/services/openai/base_llm.py @@ -545,8 +545,10 @@ class BaseOpenAILLMService(LLMService): # When gpt-4o-audio / gpt-4o-mini-audio is used for llm or stt+llm # we need to get LLMTextFrame for the transcript - elif hasattr(chunk.choices[0].delta, "audio") and chunk.choices[0].delta.audio.get( - "transcript" + elif ( + hasattr(chunk.choices[0].delta, "audio") + and chunk.choices[0].delta.audio + and chunk.choices[0].delta.audio.get("transcript") ): await self.push_frame(LLMTextFrame(chunk.choices[0].delta.audio["transcript"]))