simondby
commited on
Commit
·
c38b1a2
1
Parent(s):
be245fc
update
Browse files
app.py
CHANGED
@@ -25,7 +25,9 @@ def gen_sys_prompt():
|
|
25 |
tz = pytz.timezone('Asia/Shanghai')
|
26 |
now = datetime.datetime.now(tz)
|
27 |
timestamp = now.strftime("%Y年%m月%d日 %H:%M:%S")
|
28 |
-
sys_prompt = f"
|
|
|
|
|
29 |
return sys_prompt
|
30 |
|
31 |
# get timestamp
|
@@ -196,7 +198,8 @@ def openai_request(inputs, top_p, temperature, max_tokens, user_key, session_id,
|
|
196 |
# print(f"chat_id: {chat_id}")
|
197 |
print(f"user: {logged_in_user}")
|
198 |
print(f"apiKey: {api_key}")
|
199 |
-
|
|
|
200 |
print(f"user: {inputs}")
|
201 |
|
202 |
|
@@ -319,7 +322,7 @@ def openai_request(inputs, top_p, temperature, max_tokens, user_key, session_id,
|
|
319 |
chat_id=chat_id,
|
320 |
api_key=api_key,
|
321 |
round=chat_round,
|
322 |
-
system=system_prompt.replace("'","\'").replace('"','\"').replace('\n',''),
|
323 |
user=inputs.replace("'","\'").replace('"','\"').replace('\n',''),
|
324 |
assistant=history_write.replace('\n',''),
|
325 |
messages='',
|
@@ -477,10 +480,10 @@ with gr.Blocks(css=css_styles,title="Chatbot🚀"
|
|
477 |
# templateApplyBtn = gr.Button("⬇️ 引用prompt")
|
478 |
|
479 |
# load / save chat
|
480 |
-
with gr.Accordion(label="导入/导出", open=
|
481 |
|
482 |
# hint
|
483 |
-
gr.Markdown("注意:导出末尾不含 `.json` 则自动添加时间戳`_mmdd_hhmi`,文件名一致会进行覆盖!")
|
484 |
|
485 |
with gr.Row():
|
486 |
# load
|
@@ -495,18 +498,18 @@ with gr.Blocks(css=css_styles,title="Chatbot🚀"
|
|
495 |
|
496 |
|
497 |
# parameters: inputs, top_p, temperature, top_k, repetition_penalty
|
498 |
-
with gr.Accordion("参数配置", open=
|
499 |
gr.Markdown("""
|
500 |
* [GPT-3参数详解](https://blog.csdn.net/jarodyv/article/details/128984602)
|
501 |
* [API文档](https://platform.openai.com/docs/api-reference/chat/create)
|
502 |
""")
|
503 |
-
|
|
|
|
|
504 |
interactive=True, label="Top-p (核采样)",
|
505 |
info="0.1意味着只考虑包含最高10%概率质量的token。较小时,更加紧凑连贯,但缺乏创造性。较大时,更加多样化,但会出现语法错误和不连贯。")
|
506 |
-
temperature = gr.Slider(minimum=-0, maximum=2.0, value=
|
507 |
step=0.1, interactive=True, label="采样温度",info="越高 → 不确定性、创造性越高↑")
|
508 |
-
max_tokens = gr.Slider(minimum=100, maximum=1500, value=500,
|
509 |
-
step=10, label="最大token数",info="每次回答最大token数,数值过大可能长篇大论,看起来不像正常聊天")
|
510 |
# context_length = gr.Slider(minimum=1, maximum=5, value=2,
|
511 |
# step=1, label="记忆轮数", info="每次用于记忆的对话轮数。注意:数值过大可能会导致token数巨大!")
|
512 |
presence_penalty = gr.Slider( minimum=-2.0, maximum=2.0, value=0, step=0.1, interactive=True, label="出现惩罚系数", info="越高 → 增加谈论新主题的可能性" )
|
|
|
25 |
tz = pytz.timezone('Asia/Shanghai')
|
26 |
now = datetime.datetime.now(tz)
|
27 |
timestamp = now.strftime("%Y年%m月%d日 %H:%M:%S")
|
28 |
+
sys_prompt = f"""你的目的是如实解答用户问题,对于不知道的问题,你需要回复你不知道。
|
29 |
+
现在是{timestamp},有些信息可能已经过时。
|
30 |
+
表格的效果展示直接以HTML格式输出而非markdown格式。"""
|
31 |
return sys_prompt
|
32 |
|
33 |
# get timestamp
|
|
|
198 |
# print(f"chat_id: {chat_id}")
|
199 |
print(f"user: {logged_in_user}")
|
200 |
print(f"apiKey: {api_key}")
|
201 |
+
sys_prompt_print = system_prompt.replace("\n","").replace(" ","")
|
202 |
+
print(f"system: {sys_prompt_print}")
|
203 |
print(f"user: {inputs}")
|
204 |
|
205 |
|
|
|
322 |
chat_id=chat_id,
|
323 |
api_key=api_key,
|
324 |
round=chat_round,
|
325 |
+
system=system_prompt.replace("'","\'").replace('"','\"').replace('\n','').replace(' ',''),
|
326 |
user=inputs.replace("'","\'").replace('"','\"').replace('\n',''),
|
327 |
assistant=history_write.replace('\n',''),
|
328 |
messages='',
|
|
|
480 |
# templateApplyBtn = gr.Button("⬇️ 引用prompt")
|
481 |
|
482 |
# load / save chat
|
483 |
+
with gr.Accordion(label="导入/导出", open=False):
|
484 |
|
485 |
# hint
|
486 |
+
# gr.Markdown("注意:导出末尾不含 `.json` 则自动添加时间戳`_mmdd_hhmi`,文件名一致会进行覆盖!")
|
487 |
|
488 |
with gr.Row():
|
489 |
# load
|
|
|
498 |
|
499 |
|
500 |
# parameters: inputs, top_p, temperature, top_k, repetition_penalty
|
501 |
+
with gr.Accordion("参数配置", open=True):
|
502 |
gr.Markdown("""
|
503 |
* [GPT-3参数详解](https://blog.csdn.net/jarodyv/article/details/128984602)
|
504 |
* [API文档](https://platform.openai.com/docs/api-reference/chat/create)
|
505 |
""")
|
506 |
+
max_tokens = gr.Slider(minimum=100, maximum=2000, value=500,
|
507 |
+
step=10, label="最大token数",info="每次回答最大token数,数值过大可能长篇大论,看起来不像正常聊天")
|
508 |
+
top_p = gr.Slider(minimum=-0, maximum=1.0, value=0.5, step=0.05,
|
509 |
interactive=True, label="Top-p (核采样)",
|
510 |
info="0.1意味着只考虑包含最高10%概率质量的token。较小时,更加紧凑连贯,但缺乏创造性。较大时,更加多样化,但会出现语法错误和不连贯。")
|
511 |
+
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1,
|
512 |
step=0.1, interactive=True, label="采样温度",info="越高 → 不确定性、创造性越高↑")
|
|
|
|
|
513 |
# context_length = gr.Slider(minimum=1, maximum=5, value=2,
|
514 |
# step=1, label="记忆轮数", info="每次用于记忆的对话轮数。注意:数值过大可能会导致token数巨大!")
|
515 |
presence_penalty = gr.Slider( minimum=-2.0, maximum=2.0, value=0, step=0.1, interactive=True, label="出现惩罚系数", info="越高 → 增加谈论新主题的可能性" )
|