From 7ae9918758c00f5aca8db0b5168d977ae6dc9acf Mon Sep 17 00:00:00 2001 From: nsde Date: Fri, 11 Aug 2023 21:21:38 +0200 Subject: [PATCH] Very slight streaming improvements --- api/streaming.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/api/streaming.py b/api/streaming.py index 50a4979..09dc000 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -140,9 +140,6 @@ async def stream( chunk = chunk.replace(os.getenv('MAGIC_WORD', 'novaOSScheckKeyword'), payload['model']) chunk = chunk.replace(os.getenv('MAGIC_USER_WORD', 'novaOSSuserKeyword'), str(user['_id'])) - if not chunk.strip(): - send = False - if is_chat and '{' in chunk: data = json.loads(chunk.split('data: ')[1]) chunk = chunk.replace(data['id'], chat_id) @@ -160,7 +157,7 @@ async def stream( if data['choices'][0]['delta'] == {'role': 'assistant'}: send = False - if send: + if send and chunk.strip(): final_chunk = chunk.strip().replace('data: [DONE]', '') + '\n\n' yield final_chunk