Very slight streaming improvements

This commit is contained in:
nsde 2023-08-11 21:21:38 +02:00
parent 64b57c6784
commit 7ae9918758

View file

@ -140,9 +140,6 @@ async def stream(
chunk = chunk.replace(os.getenv('MAGIC_WORD', 'novaOSScheckKeyword'), payload['model']) chunk = chunk.replace(os.getenv('MAGIC_WORD', 'novaOSScheckKeyword'), payload['model'])
chunk = chunk.replace(os.getenv('MAGIC_USER_WORD', 'novaOSSuserKeyword'), str(user['_id'])) chunk = chunk.replace(os.getenv('MAGIC_USER_WORD', 'novaOSSuserKeyword'), str(user['_id']))
if not chunk.strip():
send = False
if is_chat and '{' in chunk: if is_chat and '{' in chunk:
data = json.loads(chunk.split('data: ')[1]) data = json.loads(chunk.split('data: ')[1])
chunk = chunk.replace(data['id'], chat_id) chunk = chunk.replace(data['id'], chat_id)
@ -160,7 +157,7 @@ async def stream(
if data['choices'][0]['delta'] == {'role': 'assistant'}: if data['choices'][0]['delta'] == {'role': 'assistant'}:
send = False send = False
if send: if send and chunk.strip():
final_chunk = chunk.strip().replace('data: [DONE]', '') + '\n\n' final_chunk = chunk.strip().replace('data: [DONE]', '') + '\n\n'
yield final_chunk yield final_chunk