fix minor bugs

This commit is contained in:
qingxu fu 2023-09-03 16:20:05 +08:00
parent 79080290c6
commit 843113ba0f
4 changed files with 17 additions and 13 deletions

View File

@ -43,6 +43,7 @@ PYDANTIC_FORMAT_INSTRUCTIONS_SIMPLE = """The output should be formatted as a JSO
{schema} {schema}
```""" ```"""
class JsonStringError(Exception): ...
class GptJsonIO(): class GptJsonIO():
@ -105,6 +106,6 @@ class GptJsonIO():
except Exception as e: except Exception as e:
# 没辙了,放弃治疗 # 没辙了,放弃治疗
logging.info('Repaire json fail.') logging.info('Repaire json fail.')
raise RuntimeError('Cannot repair json.', str(e)) raise JsonStringError('Cannot repair json.', str(e))
return result return result

View File

@ -2,7 +2,7 @@ from pydantic import BaseModel, Field
from typing import List from typing import List
from toolbox import update_ui_lastest_msg, disable_auto_promotion from toolbox import update_ui_lastest_msg, disable_auto_promotion
from request_llm.bridge_all import predict_no_ui_long_connection from request_llm.bridge_all import predict_no_ui_long_connection
from crazy_functions.json_fns.pydantic_io import GptJsonIO from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError
import copy, json, pickle, os, sys, time import copy, json, pickle, os, sys, time
@ -69,7 +69,7 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
try: try:
gpt_reply = run_gpt_fn(inputs, "") gpt_reply = run_gpt_fn(inputs, "")
plugin_sel = gpt_json_io.generate_output_auto_repair(gpt_reply, run_gpt_fn) plugin_sel = gpt_json_io.generate_output_auto_repair(gpt_reply, run_gpt_fn)
except: except JsonStringError:
msg = f"抱歉, {llm_kwargs['llm_model']}无法理解您的需求。" msg = f"抱歉, {llm_kwargs['llm_model']}无法理解您的需求。"
msg += "请求的Prompt为\n" + wrap_code(get_inputs_show_user(inputs, plugin_arr_enum_prompt)) msg += "请求的Prompt为\n" + wrap_code(get_inputs_show_user(inputs, plugin_arr_enum_prompt))
msg += "语言模型回复为:\n" + wrap_code(gpt_reply) msg += "语言模型回复为:\n" + wrap_code(gpt_reply)

View File

@ -23,9 +23,7 @@ Please describe in natural language what you want to do.
explain_msg = """ explain_msg = """
## 虚空终端插件说明: ## 虚空终端插件说明:
请用**自然语言**描述您需要做什么 1. 请用**自然语言**描述您需要做什么例如
1. 您可以打开插件下拉菜单以了解本项目的各种能力然后用自然语言描述您的需要例如
- 请调用插件为我翻译PDF论文论文我刚刚放到上传区了 - 请调用插件为我翻译PDF论文论文我刚刚放到上传区了
- 请调用插件翻译PDF论文地址为https://www.nature.com/articles/s41586-019-1724-z.pdf - 请调用插件翻译PDF论文地址为https://www.nature.com/articles/s41586-019-1724-z.pdf
- 生成一张图片图中鲜花怒放绿草如茵用插件实现 - 生成一张图片图中鲜花怒放绿草如茵用插件实现
@ -34,13 +32,15 @@ explain_msg = """
- 我不喜欢当前的界面颜色修改配置把主题THEME更换为THEME="High-Contrast" - 我不喜欢当前的界面颜色修改配置把主题THEME更换为THEME="High-Contrast"
- 请问Transformer网络的结构是怎样的 - 请问Transformer网络的结构是怎样的
2. 如果您使用调用插件xxx修改配置xxx请问等关键词您的意图可以被识别的更准确 2. 您可以打开插件下拉菜单以了解本项目的各种能力
3. 建议使用 GPT3.5 或更强的模型弱模型可能无法理解您的想法该插件诞生时间不长欢迎您前往Github反馈问题 3. 如果您使用调用插件xxx修改配置xxx请问等关键词您的意图可以被识别的更准确
4. 现在如果需要处理文件请您上传文件将文件拖动到文件上传区或者描述文件所在的路径 4. 建议使用 GPT3.5 或更强的模型弱模型可能无法理解您的想法该插件诞生时间不长欢迎您前往Github反馈问题
5. 如果不需要上传文件现在您只需要再次重复一次您的指令即可 5. 现在如果需要处理文件请您上传文件将文件拖动到文件上传区或者描述文件所在的路径
6. 如果不需要上传文件现在您只需要再次重复一次您的指令即可
""" """
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@ -50,7 +50,7 @@ from toolbox import update_ui_lastest_msg, disable_auto_promotion
from request_llm.bridge_all import predict_no_ui_long_connection from request_llm.bridge_all import predict_no_ui_long_connection
from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from crazy_functions.crazy_utils import input_clipping from crazy_functions.crazy_utils import input_clipping
from crazy_functions.json_fns.pydantic_io import GptJsonIO from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError
from crazy_functions.vt_fns.vt_state import VoidTerminalState from crazy_functions.vt_fns.vt_state import VoidTerminalState
from crazy_functions.vt_fns.vt_modify_config import modify_configuration_hot from crazy_functions.vt_fns.vt_modify_config import modify_configuration_hot
from crazy_functions.vt_fns.vt_modify_config import modify_configuration_reboot from crazy_functions.vt_fns.vt_modify_config import modify_configuration_reboot
@ -148,10 +148,11 @@ def 虚空终端主路由(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
">> " + (txt+rf_req).rstrip('\n').replace('\n','\n>> ') + '\n\n' + gpt_json_io.format_instructions ">> " + (txt+rf_req).rstrip('\n').replace('\n','\n>> ') + '\n\n' + gpt_json_io.format_instructions
run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection( run_gpt_fn = lambda inputs, sys_prompt: predict_no_ui_long_connection(
inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[]) inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[])
analyze_res = run_gpt_fn(inputs, "")
try: try:
user_intention = gpt_json_io.generate_output_auto_repair(run_gpt_fn(inputs, ""), run_gpt_fn) user_intention = gpt_json_io.generate_output_auto_repair(analyze_res, run_gpt_fn)
lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 意图={explain_intention_to_user[user_intention.intention_type]}", lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 意图={explain_intention_to_user[user_intention.intention_type]}",
except: except JsonStringError as e:
yield from update_ui_lastest_msg( yield from update_ui_lastest_msg(
lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 失败 当前语言模型({llm_kwargs['llm_model']})不能理解您的意图", chatbot=chatbot, history=history, delay=0) lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 失败 当前语言模型({llm_kwargs['llm_model']})不能理解您的意图", chatbot=chatbot, history=history, delay=0)
return return

View File

@ -60,6 +60,8 @@ def ArgsGeneralWrapper(f):
# 引入一个有cookie的chatbot # 引入一个有cookie的chatbot
cookies.update({ cookies.update({
'top_p':top_p, 'top_p':top_p,
'api_key': cookies['api_key'],
'llm_model': llm_model,
'temperature':temperature, 'temperature':temperature,
}) })
llm_kwargs = { llm_kwargs = {