Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from collections import defaultdict
|
|
7 |
from copy import deepcopy
|
8 |
import threading
|
9 |
import time
|
|
|
10 |
immersion = False
|
11 |
bot_settings=[
|
12 |
{
|
@@ -70,19 +71,10 @@ chapter_name2chapter_info={
|
|
70 |
'幻影计划':{
|
71 |
"stream":True,
|
72 |
'background':"“大蛇组织”是一个神秘的恐怖组织,这个组织由一群极端分子组成,他们采用各种极端手段来达到自己的目的。大蛇组织的结构高度严密,成员之间通过秘密的网络进行联系。他们有着严格的等级制度,只有少数核心成员了解组织的全貌。T城霓虹俱乐部的贵宾室是该组织已知的一个据点。",
|
73 |
-
|
74 |
-
"task":"玩家需要打消保安的疑虑混入贵宾室**",
|
75 |
-
"condidations":'''
|
76 |
-
- 如果玩家成功获得VIP会员卡,且保安验证是真卡,则任务成功
|
77 |
-
- 如果玩家成功让保安相信你是大蛇组织的成员,则任务成功
|
78 |
-
- 如果玩家和保安动手打架,则任务失败
|
79 |
-
- 如果保安给内部汇报异常信息,则任务失败
|
80 |
-
- 其他情况,如果玩家合理的进入了贵宾室,则任务成功
|
81 |
-
''',
|
82 |
-
"inference_ep":"ep-20240514024405-7pf8j",
|
83 |
"chat_ep":"ep-20240514024405-7pf8j",
|
84 |
"task_ep":"ep-20240514024405-7pf8j",
|
85 |
-
|
86 |
}
|
87 |
}
|
88 |
# 定义一个全局变量来控制循环
|
@@ -144,33 +136,33 @@ def respond( query, history, chapter, candidates, story_ep, chat_ep, token, imme
|
|
144 |
})
|
145 |
history.append(["我: "+query, None])
|
146 |
yield "", history
|
147 |
-
|
148 |
req_data['bot_settings']=[candidate for candidate in candidates]
|
149 |
-
|
150 |
-
|
151 |
-
# 离线
|
152 |
# 仅仅只是拿到任务模型的结果
|
153 |
while True:
|
154 |
if 'restrict_bot' in req_data:
|
155 |
del req_data['restrict_bot']
|
156 |
-
|
157 |
-
req_data['stream']=True
|
158 |
-
#ret=requests.get(url='http://0.0.0.0:8081/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
|
159 |
ret=requests.get(url='http://scp1ceqsiv4mii2mol0qg.apigateway-cn-beijing.volceapi.com/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
|
160 |
-
|
161 |
-
|
|
|
|
|
162 |
print(content)
|
163 |
-
next_bot_names=
|
|
|
|
|
164 |
global immersion
|
165 |
print("immersion: ", immersion)
|
166 |
bot_contents = defaultdict(str)
|
|
|
167 |
for next_bot_name in next_bot_names:
|
168 |
next_bot_name=next_bot_name.replace(' ', "")
|
169 |
req_data['restrict_bot']=next_bot_name
|
170 |
# 独自请求某个角色
|
171 |
ret=requests.get(url='http://scp1ceqsiv4mii2mol0qg.apigateway-cn-beijing.volceapi.com/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
|
172 |
-
#ret=requests.get(url='http://0.0.0.0:8081/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
|
173 |
-
|
174 |
content=''
|
175 |
history.append([
|
176 |
None, f"{next_bot_name}: "
|
@@ -183,27 +175,26 @@ def respond( query, history, chapter, candidates, story_ep, chat_ep, token, imme
|
|
183 |
except Exception as e:
|
184 |
break
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
history[-1][-1] +=content_tmp
|
189 |
yield "", history
|
190 |
bot_contents[next_bot_name]+=content_tmp
|
191 |
content=""
|
192 |
content+=line
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
# history.append(
|
201 |
-
# [None, f"{k}: {v}"]
|
202 |
-
# )
|
203 |
if not immersion:
|
204 |
break
|
205 |
else:
|
206 |
-
time.sleep(
|
|
|
|
|
207 |
css = """
|
208 |
.container {
|
209 |
height: 100vh;
|
|
|
7 |
from copy import deepcopy
|
8 |
import threading
|
9 |
import time
|
10 |
+
import random
|
11 |
immersion = False
|
12 |
bot_settings=[
|
13 |
{
|
|
|
71 |
'幻影计划':{
|
72 |
"stream":True,
|
73 |
'background':"“大蛇组织”是一个神秘的恐怖组织,这个组织由一群极端分子组成,他们采用各种极端手段来达到自己的目的。大蛇组织的结构高度严密,成员之间通过秘密的网络进行联系。他们有着严格的等级制度,只有少数核心成员了解组织的全貌。T城霓虹俱乐部的贵宾室是该组织已知的一个据点。",
|
74 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
"chat_ep":"ep-20240514024405-7pf8j",
|
76 |
"task_ep":"ep-20240514024405-7pf8j",
|
77 |
+
|
78 |
}
|
79 |
}
|
80 |
# 定义一个全局变量来控制循环
|
|
|
136 |
})
|
137 |
history.append(["我: "+query, None])
|
138 |
yield "", 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 |
# 仅仅只是拿到任务模型的结果
|
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)
|
159 |
bot_contents = defaultdict(str)
|
160 |
+
req_data['stream']=True
|
161 |
for next_bot_name in next_bot_names:
|
162 |
next_bot_name=next_bot_name.replace(' ', "")
|
163 |
req_data['restrict_bot']=next_bot_name
|
164 |
# 独自请求某个角色
|
165 |
ret=requests.get(url='http://scp1ceqsiv4mii2mol0qg.apigateway-cn-beijing.volceapi.com/api/v2/assistant/chat', headers=header, data=json.dumps(req_data), stream=True)
|
|
|
|
|
166 |
content=''
|
167 |
history.append([
|
168 |
None, f"{next_bot_name}: "
|
|
|
175 |
except Exception as e:
|
176 |
break
|
177 |
|
178 |
+
print(f'\n\n{next_bot_name}: ', end='', flush=True)
|
179 |
+
print(content_tmp, end='', flush=True)
|
180 |
+
history[-1][-1] += content_tmp
|
181 |
yield "", history
|
182 |
bot_contents[next_bot_name]+=content_tmp
|
183 |
content=""
|
184 |
content+=line
|
185 |
|
186 |
+
for k, v in bot_contents.items(): ## 叠加历史对话
|
187 |
+
req_data['chat_history'].append({
|
188 |
+
'bot_name':k,
|
189 |
+
'type':'assistant',
|
190 |
+
'content':v
|
191 |
+
})
|
|
|
|
|
|
|
192 |
if not immersion:
|
193 |
break
|
194 |
else:
|
195 |
+
time.sleep(3)
|
196 |
+
continue
|
197 |
+
return history
|
198 |
css = """
|
199 |
.container {
|
200 |
height: 100vh;
|