修复写入错误的库文件,增加统计单次对话耗时

This commit is contained in:
w_xiaolizu
2023-06-04 22:40:10 +08:00
parent b11807f35d
commit 7b83ba6c47
2 changed files with 8 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import logging
import traceback
import requests
import importlib
import func_box
# config_private.py放自己的秘密如API和代理网址
# 读取时首先看是否存在私密的config_private配置文件不受git管控如果有则覆盖原config文件
@ -190,11 +191,14 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
break
# 处理数据流的主体
chunkjson = json.loads(chunk_decoded[6:])
status_text = f"finish_reason: {chunkjson['choices'][0]['finish_reason']}"
# 如果这里抛出异常一般是文本过长详情见get_full_error的输出
gpt_replying_buffer = gpt_replying_buffer + json.loads(chunk_decoded[6:])['choices'][0]["delta"]["content"]
history[-1] = gpt_replying_buffer
chatbot[-1] = (history[-2], history[-1])
count_time = round(time.time() - llm_kwargs['start_time'], 3)
status_text = f"finish_reason: {chunkjson['choices'][0]['finish_reason']}\t" \
f"本次对话耗时: {func_box.html_tag_color(tag=f'{count_time}s')}"
yield from update_ui(chatbot=chatbot, history=history, msg=status_text) # 刷新界面
except Exception as e:

View File

@ -53,6 +53,7 @@ def ArgsGeneralWrapper(f):
chatbot, history, system_prompt, models, plugin_advanced_arg, ipaddr: gr.Request, *args):
""""""
# 引入一个有cookie的chatbot
start_time = time.time()
cookies.update({
'top_p':top_p,
'temperature':temperature,
@ -63,7 +64,8 @@ def ArgsGeneralWrapper(f):
'top_p':top_p,
'max_length': max_length,
'temperature': temperature,
'ipaddr': ipaddr.client.host
'ipaddr': ipaddr.client.host,
'start_time': start_time
}
plugin_kwargs = {
"advanced_arg": plugin_advanced_arg