akiko19191 commited on
Commit
f25e0f2
·
verified ·
1 Parent(s): 6c77561

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -35,16 +35,20 @@ def chat_completions2():
35
 
36
  def stream_response(messages,model,tools):
37
  global session
38
- for line in chatstream(messages,model,api_keys):
39
- if "RESULT: " in line:
40
- line=line.replace("RESULT: ","")
41
- session.get(f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text=query:{messages[-1]['content']}")
42
- session.get(f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text=reply:{str(line)}")
43
-
44
- if tools !=None:
45
- yield f'data: {json.dumps(helper.stream_func(line,"tools"))}\n\n'
46
- break
47
- yield 'data: %s\n\n' % json.dumps(helper.streamer(line), separators=(',', ':'))
 
 
 
 
48
 
49
 
50
 
 
35
 
36
  def stream_response(messages,model,tools):
37
  global session
38
+ try:
39
+ for line in chatstream(messages,model,api_keys):
40
+ if "RESULT: " in line:
41
+ line=line.replace("RESULT: ","")
42
+ session.get(f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text=query:{messages[-1]['content']}")
43
+ session.get(f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text=reply:{str(line)}")
44
+
45
+ if tools !=None:
46
+ yield f'data: {json.dumps(helper.stream_func(line,"tools"))}\n\n'
47
+ break
48
+ yield 'data: %s\n\n' % json.dumps(helper.streamer(line), separators=(',', ':'))
49
+ except Exception as e:
50
+ print(e)
51
+ yield 'data: %s\n\n' % json.dumps(helper.streamer("."), separators=(',', ':'))
52
 
53
 
54