peiji commited on
Commit
4ab622a
1 Parent(s): 4b1ac9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -105,7 +105,7 @@ def make_chat_history(history):
105
  })
106
 
107
  return chat_history
108
- def respond( query, history, chapter, candidates, story_ep, chat_ep, token, immersion_btn):
109
  global state
110
  candidates = [json.loads(bot_info) for bot_info in candidates]
111
  chat_history=make_chat_history(history)
@@ -139,20 +139,27 @@ def respond( query, history, chapter, candidates, story_ep, chat_ep, token, imme
139
 
140
  req_data['bot_settings']=[candidate for candidate in candidates]
141
  assistants = [candidate['bot_name'] for candidate in candidates if candidate['type'] == 'assistant' ]
142
-
 
 
 
 
143
  # 仅仅只是拿到任务模型的结果
144
  while True:
145
- if 'restrict_bot' in req_data:
146
- del req_data['restrict_bot']
147
  req_data['stream']=False
148
- ret=requests.get(url='http://scp1ceqsiv4mii2mol0qg.apigateway-cn-beijing.volceapi.com/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
149
- try:
150
- content=json.loads(ret.json()['choices'][0]['message']['content'])
151
- except:
152
- continue
153
- print(content)
154
- next_bot_names=content['next_bot_names']
155
- next_bot_names=[bot_name for bot_name in content['next_bot_names'] if bot_name.replace(' ', "") in assistants]
 
 
 
 
156
 
157
  global immersion
158
  print("immersion: ", immersion)
@@ -193,6 +200,8 @@ def respond( query, history, chapter, candidates, story_ep, chat_ep, token, imme
193
  break
194
  else:
195
  time.sleep(3)
 
 
196
  continue
197
  return history
198
  css = """
 
105
  })
106
 
107
  return chat_history
108
+ def respond(query, history, chapter, candidates, story_ep, chat_ep, token, immersion_btn):
109
  global state
110
  candidates = [json.loads(bot_info) for bot_info in candidates]
111
  chat_history=make_chat_history(history)
 
139
 
140
  req_data['bot_settings']=[candidate for candidate in candidates]
141
  assistants = [candidate['bot_name'] for candidate in candidates if candidate['type'] == 'assistant' ]
142
+
143
+ for candidate in candidates:
144
+ if '@' in query and candidate in query:
145
+ req_data['restrict_bot']=candidate
146
+ break
147
  # 仅仅只是拿到任务模型的结果
148
  while True:
149
+
 
150
  req_data['stream']=False
151
+ if 'restrict_bot' not in req_data or len(requests['restrict_bot']) == 0:
152
+
153
+ ret=requests.get(url='http://scp1ceqsiv4mii2mol0qg.apigateway-cn-beijing.volceapi.com/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
154
+ try:
155
+ content=json.loads(ret.json()['choices'][0]['message']['content'])
156
+ except:
157
+ continue
158
+ print(content)
159
+ next_bot_names=content['next_bot_names']
160
+ next_bot_names=[bot_name for bot_name in content['next_bot_names'] if bot_name.replace(' ', "") in assistants]
161
+ else:
162
+ next_bot_names=req_data['restrict_bot']
163
 
164
  global immersion
165
  print("immersion: ", immersion)
 
200
  break
201
  else:
202
  time.sleep(3)
203
+ if 'restrict_bot' in req_data:
204
+ del req_data['restrict_bot']
205
  continue
206
  return history
207
  css = """