Skip to content

Commit

Permalink
Update webui.py
Browse files Browse the repository at this point in the history
  • Loading branch information
neurogen-dev authored Jul 27, 2023
1 parent b7e5c57 commit 0f4696d
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,34 +579,46 @@ def chat_completions():
}

def stream():
nonlocal response
completion_data = {
'id': '',
'object': 'chat.completion.chunk',
'created': 0,
'model': 'gpt-3.5-turbo-0301',
'choices': [
{
'delta': {
'content': ""
},
'index': 0,
'finish_reason': None
}
]
}

for token in response:
completion_id = ''.join(
random.choices('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', k=28))
completion_timestamp = int(time.time())
completion_id = ''.join(random.choices(
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', k=28))

completion_data = {
'id': f'chatcmpl-{completion_id}',
'object': 'chat.completion.chunk',
'created': completion_timestamp,
'model': model,
'choices': [
{
'delta': {
'content': token
},
'index': 0,
'finish_reason': None
}
]
}

completion_data['id'] = f'chatcmpl-{completion_id}'
completion_data['created'] = completion_timestamp
completion_data['choices'][0]['delta']['content'] = token
if token.startswith("an error occured"):
completion_data['choices'][0]['delta']['content'] = "Server Response Error, please try again.\n"
completion_data['choices'][0]['delta']['stop'] = "error"
yield 'data: %s\n\ndata: [DONE]\n\n' % json.dumps(completion_data, separators=(',' ':'))
return
yield 'data: %s\n\n' % json.dumps(completion_data, separators=(',' ':'))
time.sleep(0.1)

completion_data['choices'][0]['finish_reason'] = "stop"
completion_data['choices'][0]['delta']['content'] = ""
yield 'data: %s\n\n' % json.dumps(completion_data, separators=(',' ':'))
yield 'data: [DONE]\n\n'

return app.response_class(stream(), mimetype='text/event-stream')



@app.route("/v1/dashboard/billing/subscription")
@app.route("/dashboard/billing/subscription")
def billing_subscription():
Expand Down

0 comments on commit 0f4696d

Please sign in to comment.