Upload app.py
Browse files
app.py
CHANGED
@@ -90,6 +90,7 @@ def predict(openai_gptapi_key, model, system_msg, inputs, top_p, temperature, ma
|
|
90 |
partial_words = ""
|
91 |
|
92 |
counter=0
|
|
|
93 |
for chunk in response.iter_lines():
|
94 |
# 跳过第一个块
|
95 |
if counter == 0:
|
@@ -97,7 +98,6 @@ def predict(openai_gptapi_key, model, system_msg, inputs, top_p, temperature, ma
|
|
97 |
continue
|
98 |
# 检查每行是否非空
|
99 |
if chunk.decode() :
|
100 |
-
complete_response = ""
|
101 |
chunk = chunk.decode()
|
102 |
# 将每行解码为响应数据,因为响应数据是以字节形式返回的
|
103 |
if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
|
@@ -107,10 +107,10 @@ def predict(openai_gptapi_key, model, system_msg, inputs, top_p, temperature, ma
|
|
107 |
else:
|
108 |
history[-1] = partial_words
|
109 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # 转换为列表的元组
|
110 |
-
complete_response = " ".join([item[1] for item in chat])
|
111 |
token_counter+=1
|
112 |
yield chat, history, chat_counter, response # 类似于 {chatbot: chat, state: history}
|
113 |
-
|
|
|
114 |
|
115 |
# 重置文本框
|
116 |
def reset_textbox():
|
|
|
90 |
partial_words = ""
|
91 |
|
92 |
counter=0
|
93 |
+
partial_words = ""
|
94 |
for chunk in response.iter_lines():
|
95 |
# 跳过第一个块
|
96 |
if counter == 0:
|
|
|
98 |
continue
|
99 |
# 检查每行是否非空
|
100 |
if chunk.decode() :
|
|
|
101 |
chunk = chunk.decode()
|
102 |
# 将每行解码为响应数据,因为响应数据是以字节形式返回的
|
103 |
if len(chunk) > 12 and "content" in json.loads(chunk[6:])['choices'][0]['delta']:
|
|
|
107 |
else:
|
108 |
history[-1] = partial_words
|
109 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # 转换为列表的元组
|
|
|
110 |
token_counter+=1
|
111 |
yield chat, history, chat_counter, response # 类似于 {chatbot: chat, state: history}
|
112 |
+
|
113 |
+
print(f"[{current_time}] 聊天:模型回复 - {partial_words}")
|
114 |
|
115 |
# 重置文本框
|
116 |
def reset_textbox():
|