Replace only first occurrence of data: in response

This commit is contained in:
monosans 2023-10-08 16:13:28 +03:00
parent a6af7bd1a4
commit 83df730edb
No known key found for this signature in database
2 changed files with 2 additions and 2 deletions

View file

@ -153,7 +153,7 @@ async def respond(
chunk = chunk.decode('utf8').strip() chunk = chunk.decode('utf8').strip()
if 'azure' in provider_name: if 'azure' in provider_name:
chunk = chunk.strip().replace('data: ', '') chunk = chunk.strip().replace('data: ', '', 1)
if not chunk or chunk_no == 1: if not chunk or chunk_no == 1:
continue continue

View file

@ -100,7 +100,7 @@ async def test_chat_stream_gpt3() -> float:
async for chunk in response.aiter_text(): async for chunk in response.aiter_text():
for subchunk in chunk.split('\n\n'): for subchunk in chunk.split('\n\n'):
chunk = subchunk.replace('data: ', '').strip() chunk = subchunk.replace('data: ', '', 1).strip()
if chunk == '[DONE]': if chunk == '[DONE]':
break break