mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 18:53:58 +01:00
Very slight streaming improvements
This commit is contained in:
parent
64b57c6784
commit
7ae9918758
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue