Spaces:
Runtime error
Runtime error
mkw18
commited on
Commit
•
227cc8d
1
Parent(s):
b4d276b
add api
Browse files
app.py
CHANGED
@@ -66,33 +66,34 @@ def showInput(input, chatbot):
|
|
66 |
def predict(input, chatbot, messages, idx, answer):
|
67 |
chatbot.append((parse_text(input), ""))
|
68 |
messages.append({"role": 'user', "content": input})
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
response=completion.choices[0].message.content.strip()
|
75 |
-
messages.append({"role": "assistant", "content": response})
|
76 |
-
# data = {'predict': messages, 'idx': idx}
|
77 |
-
# response=str(requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content, encoding="utf-8")
|
78 |
-
# chatbot[-1] = (parse_text(input), parse_text(response))
|
79 |
-
# messages.append({"role": "assistant", "content": response})
|
80 |
-
messages1 = messages + [{"role": 'user', "content": '我猜到汤底了吗?请回答是或否。'}]
|
81 |
-
completion1 = openai.ChatCompletion.create(
|
82 |
-
model="gpt-3.5-turbo",
|
83 |
-
messages=messages1,
|
84 |
-
# logit_bias={42468: 5, 28938: 5}
|
85 |
-
)
|
86 |
-
response1=completion1.choices[0].message.content.strip()
|
87 |
-
if '不' in response1 or '否' in response1 or '没' in response1:
|
88 |
-
response = response
|
89 |
-
finish = False
|
90 |
else:
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
return chatbot, messages
|
97 |
|
98 |
|
|
|
66 |
def predict(input, chatbot, messages, idx, answer):
|
67 |
chatbot.append((parse_text(input), ""))
|
68 |
messages.append({"role": 'user', "content": input})
|
69 |
+
data = {'predict': messages, 'idx': idx, 'isfinished': False, 'answer': answer}
|
70 |
+
response=str(requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content, encoding="utf-8")
|
71 |
+
if not response == 'timeout':
|
72 |
+
chatbot[-1] = (parse_text(input), parse_text(response))
|
73 |
+
messages.append({"role": "assistant", "content": response})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
else:
|
75 |
+
completion = openai.ChatCompletion.create(
|
76 |
+
model="gpt-3.5-turbo",
|
77 |
+
messages=messages,
|
78 |
+
logit_bias={42468: 10, 28938: 10}
|
79 |
+
)
|
80 |
+
response=completion.choices[0].message.content.strip()
|
81 |
+
messages.append({"role": "assistant", "content": response})
|
82 |
+
messages1 = messages + [{"role": 'user', "content": '我猜到汤底了吗?请回答是或否。'}]
|
83 |
+
completion1 = openai.ChatCompletion.create(
|
84 |
+
model="gpt-3.5-turbo",
|
85 |
+
messages=messages1,
|
86 |
+
)
|
87 |
+
response1=completion1.choices[0].message.content.strip()
|
88 |
+
if '不' in response1 or '否' in response1 or '没' in response1:
|
89 |
+
response = response
|
90 |
+
finish = False
|
91 |
+
else:
|
92 |
+
response += f'恭喜您已经猜到汤底,汤底是:{answer}\n点击"New Game"按钮开始下一局游戏。'
|
93 |
+
finish = True
|
94 |
+
data = {'predict': messages, 'idx': idx, 'isfinished': finish, 'answer': answer}
|
95 |
+
requests.post(os.environ.get("URL"), data=json.dumps(data, ensure_ascii=False).encode('utf-8'))
|
96 |
+
chatbot[-1] = (parse_text(input), parse_text(response))
|
97 |
return chatbot, messages
|
98 |
|
99 |
|