Skip to content

Commit f3cc2ad

Browse files
authored
Hotfix: Workaround for stream bug (#664)
* Adding anchors * Rm fund notice * Account for bug * rm unrelated change
1 parent 7b7e6ce commit f3cc2ad

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

app/backend/approaches/chatreadretrieveread.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ async def run_with_streaming(
232232
extra_info, chat_coroutine = await self.run_until_final_call(history, overrides, should_stream=True)
233233
yield extra_info
234234
async for event in await chat_coroutine:
235-
yield event
235+
# "2023-07-01-preview" API version has a bug where first response has empty choices
236+
if event["choices"]:
237+
yield event
236238

237239
def get_messages_from_history(
238240
self,

tests/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ async def mock_acreate(*args, **kwargs):
3232
def mock_openai_chatcompletion(monkeypatch):
3333
class AsyncChatCompletionIterator:
3434
def __init__(self, answer):
35-
self.num = 1
35+
self.num = 2
3636
self.answer = answer
3737

3838
def __aiter__(self):
3939
return self
4040

4141
async def __anext__(self):
42-
if self.num == 1:
43-
self.num = 0
42+
if self.num == 2:
43+
self.num -= 1
44+
# Emulate the first response being empty - bug with "2023-07-01-preview"
45+
return openai.util.convert_to_openai_object({"choices": []})
46+
elif self.num == 1:
47+
self.num -= 1
4448
return openai.util.convert_to_openai_object({"choices": [{"delta": {"content": self.answer}}]})
4549
else:
4650
raise StopAsyncIteration

0 commit comments

Comments
 (0)