改进虚空终端

这个提交包含在:
qingxu fu
2023-09-03 00:53:57 +08:00
父节点 0b70e9df7b
当前提交 e666b5269e
共有 4 个文件被更改,包括 32 次插入12 次删除

查看文件

@@ -228,7 +228,7 @@ ALLOW_RESET_CONFIG = False
├── THEME 色彩主题 ├── THEME 色彩主题
├── AUTO_CLEAR_TXT 是否在提交时自动清空输入框 ├── AUTO_CLEAR_TXT 是否在提交时自动清空输入框
├── ADD_WAIFU 加一个live2d装饰 ├── ADD_WAIFU 加一个live2d装饰
├── ALLOW_RESET_CONFIG 是否允许通过自然语言描述修改本页的配置,该功能具有一定的危险性
插件在线服务配置依赖关系示意图 插件在线服务配置依赖关系示意图

查看文件

@@ -268,7 +268,7 @@ def get_crazy_functions():
"Group": "学术", "Group": "学术",
"Color": "stop", "Color": "stop",
"AsButton": False, # 加入下拉菜单中 "AsButton": False, # 加入下拉菜单中
"Info": "下载arxiv论文并翻译摘要 | 输入参数为arxiv编号如1812.10695", # "Info": "下载arxiv论文并翻译摘要 | 输入参数为arxiv编号如1812.10695",
"Function": HotReload(下载arxiv论文并翻译摘要) "Function": HotReload(下载arxiv论文并翻译摘要)
} }
}) })

查看文件

@@ -37,6 +37,15 @@ def get_recent_file_prompt_support(chatbot):
prompt += f"Only use it when necessary, otherwise, you can ignore this file." prompt += f"Only use it when necessary, otherwise, you can ignore this file."
return prompt return prompt
def get_inputs_show_user(inputs, plugin_arr_enum_prompt):
# remove plugin_arr_enum_prompt from inputs string
inputs_show_user = inputs.replace(plugin_arr_enum_prompt, "")
inputs_show_user += plugin_arr_enum_prompt[:200] + '...'
inputs_show_user += '\n...\n'
inputs_show_user += '...\n'
inputs_show_user += '...}'
return inputs_show_user
def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention): def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention):
plugin_arr_enum_prompt, plugin_arr_dict = read_avail_plugin_enum() plugin_arr_enum_prompt, plugin_arr_dict = read_avail_plugin_enum()
class Plugin(BaseModel): class Plugin(BaseModel):
@@ -59,14 +68,14 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
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:
msg = "抱歉,当前的大语言模型无法理解您的需求。" msg = "抱歉,当前的大语言模型无法理解您的需求。"
msg += "请求的Prompt为\n" + wrap_code(inputs) 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)
msg += "但您可以尝试再试一次\n" msg += "但您可以尝试再试一次\n"
yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2)
return return
if plugin_sel.plugin_selection not in plugin_arr_dict: if plugin_sel.plugin_selection not in plugin_arr_dict:
msg = "抱歉, 找不到合适插件执行该任务, 当前的大语言模型可能无法理解您的需求。" msg = "抱歉, 找不到合适插件执行该任务, 当前的大语言模型可能无法理解您的需求。"
msg += "请求的Prompt为\n" + wrap_code(inputs) 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)
msg += "但您可以尝试再试一次\n" msg += "但您可以尝试再试一次\n"
yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2)

查看文件

@@ -50,7 +50,7 @@ def analyze_intention_with_simple_rules(txt):
is_certain = True is_certain = True
user_intention.intention_type = 'Chat' user_intention.intention_type = 'Chat'
if '用插件' in txt: if '用插件' in txt:
is_certain = True is_certain = True
user_intention.intention_type = 'ExecutePlugin' user_intention.intention_type = 'ExecutePlugin'
@@ -71,15 +71,22 @@ explain_msg = """
请用**自然语言**描述您需要做什么。 请用**自然语言**描述您需要做什么。
1. 如果涉及文件处理, 请务必描述文件所在路径(把文件拖拽到文件上传区亦可)。 1. 您可以打开插件下拉菜单以了解本项目的各种能力,然后用自然语言描述您的需要,例如:
- 「请调用插件,为我翻译PDF论文,论文我刚刚放到上传区了。」
- 「请调用插件翻译PDF论文,地址为https://www.nature.com/articles/s41586-019-1724-z.pdf」
- 「生成一张图片,图中鲜花怒放,绿草如茵,用插件实现。」
- 「用插件翻译README,Github网址是https://github.com/facebookresearch/co-tracker」
- 「给爷翻译Arxiv论文,arxiv论文的ID是1812.10695,记得用插件,不要自己瞎搞!」
- 「我不喜欢当前的界面颜色,修改配置,把主题THEME更换为THEME="High-Contrast"。」
- 「请问Transformer网络的结构是怎样的?」
2. 您可以打开插件下拉菜单以了解本项目的各种能力 2. 如果您使用「调用插件xxx」、「修改配置xxx」、「请问」等关键词,您的意图可以被识别的更准确
3. 如果您使用“调用插件xxx”、“修改配置xxx”、“请问”等关键词,您的意图可以被识别的更准确。 3. 使用GPT4等强模型时,您的意图可以被识别的更准确。
4. 使用GPT4等强模型时,您的意图可以被识别的更准确 4. 现在,如果需要处理文件,请您上传文件(将文件拖动到文件上传区),或者描述文件所在的路径
5. 现在,请您给出指令(或先上传文件,再给指令) 5. 如果不需要上传文件,现在您只需要再次重复一次您的指令即可
""" """
@@ -89,10 +96,14 @@ explain_msg = """
def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
# 获取当前虚空终端状态 # 获取当前虚空终端状态
state = VoidTerminalState.get_state(chatbot) state = VoidTerminalState.get_state(chatbot)
appendix_msg = ""
# 用简单的关键词检测用户意图 # 用简单的关键词检测用户意图
is_certain, _ = analyze_intention_with_simple_rules(txt) is_certain, _ = analyze_intention_with_simple_rules(txt)
if txt.startswith('private_upload/') and len(txt) == 34:
state.set_state(chatbot=chatbot, key='has_provided_explaination', value=False)
appendix_msg = "\n\n**很好,您已经上传了文件**,现在请您描述您的需求。"
if is_certain or (state.has_provided_explaination): if is_certain or (state.has_provided_explaination):
# 如果意图明确,跳过提示环节 # 如果意图明确,跳过提示环节
state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True) state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True)
@@ -104,7 +115,7 @@ def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt
# 如果意图模糊,提示 # 如果意图模糊,提示
state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True) state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True)
state.lock_plugin(chatbot=chatbot) state.lock_plugin(chatbot=chatbot)
chatbot.append(("虚空终端状态:", explain_msg)) chatbot.append(("虚空终端状态:", explain_msg+appendix_msg))
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
return return