Update app.py
Browse files
app.py
CHANGED
|
@@ -49,14 +49,9 @@ async def chat(request: ChatRequest):
|
|
| 49 |
decoded_line = line.decode('utf-8')
|
| 50 |
# Check if the line starts with "data: "
|
| 51 |
if decoded_line.startswith("data: "):
|
| 52 |
-
# Extract the JSON part
|
| 53 |
-
json_data = decoded_line[6:] # Remove "data: " prefix
|
| 54 |
-
# Parse the JSON
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if 'choices' in parsed_data and len(parsed_data['choices']) > 0:
|
| 59 |
-
content = parsed_data['choices'][0]['delta'].get('content', '')
|
| 60 |
if content:
|
| 61 |
yield f"{json.dumps({'response': content})}\n\n"
|
| 62 |
except json.JSONDecodeError:
|
|
@@ -70,4 +65,4 @@ async def chat(request: ChatRequest):
|
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
import uvicorn
|
| 73 |
-
uvicorn.run(app, host="0.0.0.0", port=8083)
|
|
|
|
| 49 |
decoded_line = line.decode('utf-8')
|
| 50 |
# Check if the line starts with "data: "
|
| 51 |
if decoded_line.startswith("data: "):
|
|
|
|
|
|
|
|
|
|
| 52 |
try:
|
| 53 |
+
data = json.loads(line[len('data: '):])
|
| 54 |
+
content = data.get("choices", [{}])[0].get("delta", {}).get("content", '')
|
|
|
|
|
|
|
| 55 |
if content:
|
| 56 |
yield f"{json.dumps({'response': content})}\n\n"
|
| 57 |
except json.JSONDecodeError:
|
|
|
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
import uvicorn
|
| 68 |
+
uvicorn.run(app, host="0.0.0.0", port=8083)
|