Hiren122 commited on
Commit
5ce2545
·
verified ·
1 Parent(s): cbed94a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -167,14 +167,14 @@ def chat_completions():
167
  if d.get('stream'):
168
  def gen():
169
  cid = f"chatcmpl-{uuid.uuid4().hex[:24]}"
170
- yield f"data: {json.dumps({'id': cid, 'object': 'chat.completion.chunk', 'choices': [{'delta': {'role': 'assistant'}}]})}\n\n"
171
  with requests.post(f"{COGNIX_BASE_URL}/api/chat", json=payload, headers=get_headers(), stream=True) as r:
172
  for line in r.iter_lines(decode_unicode=True):
173
  if not line: continue
174
  cont, pty = parse_cognix_stream_chunk(line)
175
  if pty == "stop": break
176
  if cont:
177
- yield f"data: {json.dumps({'id': cid, 'object': 'chat.completion.chunk', 'choices': [{'delta': {'content': cont}}]})}\n\n"
178
  yield "data: [DONE]\n\n"
179
  return Response(gen(), content_type='text/event-stream')
180
 
 
167
  if d.get('stream'):
168
  def gen():
169
  cid = f"chatcmpl-{uuid.uuid4().hex[:24]}"
170
+ yield f"data: {json.dumps({'id': cid, 'object': 'chat.completion.chunk', 'choices': [{'index': 0, 'delta': {'role': 'assistant'}}]})}\n\n"
171
  with requests.post(f"{COGNIX_BASE_URL}/api/chat", json=payload, headers=get_headers(), stream=True) as r:
172
  for line in r.iter_lines(decode_unicode=True):
173
  if not line: continue
174
  cont, pty = parse_cognix_stream_chunk(line)
175
  if pty == "stop": break
176
  if cont:
177
+ yield f"data: {json.dumps({'id': cid, 'object': 'chat.completion.chunk', 'choices': [{'index': 0, 'delta': {'content': cont}}]})}\n\n"
178
  yield "data: [DONE]\n\n"
179
  return Response(gen(), content_type='text/event-stream')
180