Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,19 +33,22 @@ async def chat(request: Request):
|
|
33 |
|
34 |
response_text_chunk = ''
|
35 |
|
36 |
-
|
|
|
37 |
try:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
except StopIteration:
|
43 |
-
|
44 |
|
45 |
if ask == 'clear':
|
46 |
os.system("cls")
|
47 |
|
48 |
-
return
|
49 |
|
50 |
except Exception as e:
|
51 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
33 |
|
34 |
response_text_chunk = ''
|
35 |
|
36 |
+
async def generate_chunks():
|
37 |
+
nonlocal response_text_chunk
|
38 |
try:
|
39 |
+
while True:
|
40 |
+
chunk = next(output_stream)
|
41 |
+
if chunk.get('choices') and chunk['choices'][0].get('text'):
|
42 |
+
response_text_chunk += chunk['choices'][0]['text']
|
43 |
+
typewrite(response_text_chunk, delay=0.00)
|
44 |
+
yield {"response": response_text_chunk}
|
45 |
except StopIteration:
|
46 |
+
pass
|
47 |
|
48 |
if ask == 'clear':
|
49 |
os.system("cls")
|
50 |
|
51 |
+
return generate_chunks()
|
52 |
|
53 |
except Exception as e:
|
54 |
raise HTTPException(status_code=500, detail=str(e))
|