Manofem commited on
Commit
290f8e2
·
1 Parent(s): 8c77d9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -33,19 +33,22 @@ async def chat(request: Request):
33
 
34
  response_text_chunk = ''
35
 
36
- while True:
 
37
  try:
38
- chunk = next(output_stream)
39
- if chunk.get('choices') and chunk['choices'][0].get('text'):
40
- response_text_chunk += chunk['choices'][0]['text']
41
- typewrite(response_text_chunk, delay=0.00)
 
 
42
  except StopIteration:
43
- break
44
 
45
  if ask == 'clear':
46
  os.system("cls")
47
 
48
- return {"response": response_text_chunk}
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))