From f8e649a1f7fd59abc0db3251863b12ee08b4894d Mon Sep 17 00:00:00 2001 From: Robert Nasuti Date: Sun, 22 Oct 2023 15:45:15 -0600 Subject: [PATCH] Fix bug in playground for Azure OpenAI (#493) * Fix bug in playground for Azure OpenAI * Update openai.py Use hasattr instead of checking for choices in response --- backend/chainlit/playground/providers/openai.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/chainlit/playground/providers/openai.py b/backend/chainlit/playground/providers/openai.py index 9ac3cd469b..45e6d3d045 100644 --- a/backend/chainlit/playground/providers/openai.py +++ b/backend/chainlit/playground/providers/openai.py @@ -145,8 +145,11 @@ async def create_completion(self, request): async def create_event_stream(): async for stream_resp in response: - token = stream_resp.choices[0]["delta"].get("content", "") - yield token + if hasattr(stream_resp, 'choices') and len(stream_resp.choices) > 0: + token = stream_resp.choices[0]["delta"].get("content", "") + yield token + else: + continue return StreamingResponse(create_event_stream())