Upload app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,12 @@ def predict(openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counte
|
|
13 |
"Content-Type": "application/json",
|
14 |
"Authorization": f"Bearer {openai_gpt4_key}" # 用户将提供自己的 OPENAI_API_KEY
|
15 |
}
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
if system_msg.strip() == '':
|
18 |
initial_message = [{"role": "user", "content": f"{inputs}"},]
|
19 |
multi_turn_message = []
|
@@ -33,8 +38,9 @@ def predict(openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counte
|
|
33 |
"presence_penalty":0,
|
34 |
"frequency_penalty":0,
|
35 |
}
|
36 |
-
|
37 |
-
|
|
|
38 |
messages=multi_turn_message # 类型为 - [{"role": "system", "content": system_msg},]
|
39 |
for data in chatbot:
|
40 |
user = {}
|
@@ -59,14 +65,14 @@ def predict(openai_gpt4_key, system_msg, inputs, top_p, temperature, chat_counte
|
|
59 |
"stream": True,
|
60 |
"presence_penalty":0,
|
61 |
"frequency_penalty":0,}
|
62 |
-
|
63 |
-
|
64 |
|
65 |
history.append(inputs)
|
66 |
-
print(f"
|
67 |
# 使用 requests.post 方法向 API 端点发出 POST 请求,传递 stream=True
|
68 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
69 |
-
print(f"
|
70 |
token_counter = 0
|
71 |
partial_words = ""
|
72 |
|
@@ -134,7 +140,7 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
134 |
)
|
135 |
with gr.Accordion(label="系统消息:", open=False):
|
136 |
system_msg = gr.Textbox(label="指示 AI 助手设置其行为", info=system_msg_info, value="", placeholder="在这里输入..")
|
137 |
-
accordion_msg = gr.HTML(value="🚧
|
138 |
|
139 |
chatbot = gr.Chatbot(label='GPT4', elem_id="chatbot")
|
140 |
inputs = gr.Textbox(placeholder="嗨!", label="输入文本并按 Enter 键")
|
|
|
13 |
"Content-Type": "application/json",
|
14 |
"Authorization": f"Bearer {openai_gpt4_key}" # 用户将提供自己的 OPENAI_API_KEY
|
15 |
}
|
16 |
+
|
17 |
+
if inputs.strip() == '':
|
18 |
+
inputs = "你好呀,简单介绍下你自己"
|
19 |
+
print(f"用户消息: {inputs}")
|
20 |
+
print(f"系统消息: {system_msg}")
|
21 |
+
|
22 |
if system_msg.strip() == '':
|
23 |
initial_message = [{"role": "user", "content": f"{inputs}"},]
|
24 |
multi_turn_message = []
|
|
|
38 |
"presence_penalty":0,
|
39 |
"frequency_penalty":0,
|
40 |
}
|
41 |
+
chat_counter+=1
|
42 |
+
print(f"聊天计数 - {chat_counter}")
|
43 |
+
else: # 如果 chat_counter 不等于 0
|
44 |
messages=multi_turn_message # 类型为 - [{"role": "system", "content": system_msg},]
|
45 |
for data in chatbot:
|
46 |
user = {}
|
|
|
65 |
"stream": True,
|
66 |
"presence_penalty":0,
|
67 |
"frequency_penalty":0,}
|
68 |
+
chat_counter+=1
|
69 |
+
print(f"聊天计数 - {chat_counter}")
|
70 |
|
71 |
history.append(inputs)
|
72 |
+
print(f"日志:发送数据 - {payload}")
|
73 |
# 使用 requests.post 方法向 API 端点发出 POST 请求,传递 stream=True
|
74 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
75 |
+
print(f"日志:响应代码 - {response}")
|
76 |
token_counter = 0
|
77 |
partial_words = ""
|
78 |
|
|
|
140 |
)
|
141 |
with gr.Accordion(label="系统消息:", open=False):
|
142 |
system_msg = gr.Textbox(label="指示 AI 助手设置其行为", info=system_msg_info, value="", placeholder="在这里输入..")
|
143 |
+
accordion_msg = gr.HTML(value="🚧 要设置系统消息,你必须刷新页面", visible=False)
|
144 |
|
145 |
chatbot = gr.Chatbot(label='GPT4', elem_id="chatbot")
|
146 |
inputs = gr.Textbox(placeholder="嗨!", label="输入文本并按 Enter 键")
|