Update app.py
#1
by
Haoyuan03
- opened
app.py
CHANGED
@@ -7,7 +7,7 @@ openai.api_key = os.getenv("key")
|
|
7 |
|
8 |
|
9 |
# 如果你只打算通过 prompt 来定制机器人的行为,只需要修改这段 prompt 就够了。
|
10 |
-
prompt = '
|
11 |
|
12 |
history = {}
|
13 |
|
@@ -30,6 +30,7 @@ def chat(p, qid, uid):
|
|
30 |
return ["text", response]
|
31 |
|
32 |
|
|
|
33 |
def callapi(p, msgs):
|
34 |
if (len(msgs) > 8): #简单 hard-code 8 回合对话。如果需要更精准的,应该计算 token 数
|
35 |
msgs = msgs[-8:]
|
@@ -54,7 +55,7 @@ def callapi(p, msgs):
|
|
54 |
iface = gr.Interface(fn=chat,
|
55 |
inputs=["text", "text", "text"],
|
56 |
outputs=["text", "text"],
|
57 |
-
description="""
|
58 |
已添加多轮对话的极简示范,能将该 uid 的最近八条消息一起发给openai。本实现是内存中的,一旦重启即被清空。如需可持久的多轮对话,需要改用数据库等方式。
|
59 |
注意:duplicate 本项目后,需要将你自己的 openai apikey 设置到 settings 的 Repository Secrets 里,否则运行会报错。[了解详情](https://huggingface.co/spaces/baixing/hackathon_chatbot_openai_api/blob/main/%E6%B7%BB%E5%8A%A0%20secret%20%E7%9A%84%E6%96%B9%E6%B3%95.jpg)
|
60 |
[对话测试](https://huggingface.co/spaces/BaixingAI/hackathon_test) [参考文档](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/bot-api.md) [Q & A](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/qna.md)
|
|
|
7 |
|
8 |
|
9 |
# 如果你只打算通过 prompt 来定制机器人的行为,只需要修改这段 prompt 就够了。
|
10 |
+
prompt = '请你调用有关口腔知识的数据库,现在你是一个幽默的口腔咨询师,使用幽默愉快的语气、方式和词汇帮助向你询问口腔问题的人们,解决他们的难题让你感到十分高兴。要一步一步引导出问你问题的人真正的需要,模仿苏格拉底式导师,像口腔医生一样回答问题,但要让人轻易的明白你的描述,可以举例子和讲笑话。你必须掌握有关口腔的所有知识,需要的话可以有牙膏的推荐、刷牙方式等生活细节。'
|
11 |
|
12 |
history = {}
|
13 |
|
|
|
30 |
return ["text", response]
|
31 |
|
32 |
|
33 |
+
|
34 |
def callapi(p, msgs):
|
35 |
if (len(msgs) > 8): #简单 hard-code 8 回合对话。如果需要更精准的,应该计算 token 数
|
36 |
msgs = msgs[-8:]
|
|
|
55 |
iface = gr.Interface(fn=chat,
|
56 |
inputs=["text", "text", "text"],
|
57 |
outputs=["text", "text"],
|
58 |
+
description="""这是一个幽默的口腔咨询师在和你对话。
|
59 |
已添加多轮对话的极简示范,能将该 uid 的最近八条消息一起发给openai。本实现是内存中的,一旦重启即被清空。如需可持久的多轮对话,需要改用数据库等方式。
|
60 |
注意:duplicate 本项目后,需要将你自己的 openai apikey 设置到 settings 的 Repository Secrets 里,否则运行会报错。[了解详情](https://huggingface.co/spaces/baixing/hackathon_chatbot_openai_api/blob/main/%E6%B7%BB%E5%8A%A0%20secret%20%E7%9A%84%E6%96%B9%E6%B3%95.jpg)
|
61 |
[对话测试](https://huggingface.co/spaces/BaixingAI/hackathon_test) [参考文档](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/bot-api.md) [Q & A](https://huggingface.co/spaces/baixing/hackathon_test/blob/main/qna.md)
|