Spaces:
Running
Running
Update app.py
Browse files
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 |
|