Skip to content

Commit

Permalink
Hotfix: Workaround for stream bug (#664)
Browse files Browse the repository at this point in the history
* Adding anchors

* Rm fund notice

* Account for bug

* rm unrelated change
  • Loading branch information
pamelafox authored Sep 22, 2023
1 parent 7b7e6ce commit f3cc2ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/backend/approaches/chatreadretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ async def run_with_streaming(
extra_info, chat_coroutine = await self.run_until_final_call(history, overrides, should_stream=True)
yield extra_info
async for event in await chat_coroutine:
yield event
# "2023-07-01-preview" API version has a bug where first response has empty choices
if event["choices"]:
yield event

def get_messages_from_history(
self,
Expand Down
10 changes: 7 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ async def mock_acreate(*args, **kwargs):
def mock_openai_chatcompletion(monkeypatch):
class AsyncChatCompletionIterator:
def __init__(self, answer):
self.num = 1
self.num = 2
self.answer = answer

def __aiter__(self):
return self

async def __anext__(self):
if self.num == 1:
self.num = 0
if self.num == 2:
self.num -= 1
# Emulate the first response being empty - bug with "2023-07-01-preview"
return openai.util.convert_to_openai_object({"choices": []})
elif self.num == 1:
self.num -= 1
return openai.util.convert_to_openai_object({"choices": [{"delta": {"content": self.answer}}]})
else:
raise StopAsyncIteration
Expand Down

0 comments on commit f3cc2ad

Please sign in to comment.