From 7b83ba6c47f641cf441f418d71efe33f49524610 Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Sun, 4 Jun 2023 22:40:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=99=E5=85=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E5=BA=93=E6=96=87=E4=BB=B6=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BB=9F=E8=AE=A1=E5=8D=95=E6=AC=A1=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E8=80=97=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request_llm/bridge_chatgpt.py | 6 +++++- toolbox.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/request_llm/bridge_chatgpt.py b/request_llm/bridge_chatgpt.py index fdcb55f..2f0e376 100644 --- a/request_llm/bridge_chatgpt.py +++ b/request_llm/bridge_chatgpt.py @@ -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: diff --git a/toolbox.py b/toolbox.py index 54b5aea..8b9044d 100644 --- a/toolbox.py +++ b/toolbox.py @@ -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