From e666b5269e1c861b0160c91b1c1016415cefc8d5 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sun, 3 Sep 2023 00:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=99=9A=E7=A9=BA=E7=BB=88?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- crazy_functional.py | 2 +- crazy_functions/vt_fns/vt_call_plugin.py | 13 ++++++++++-- crazy_functions/虚空终端.py | 27 +++++++++++++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/config.py b/config.py index 6442ad8..d2f35c4 100644 --- a/config.py +++ b/config.py @@ -228,7 +228,7 @@ ALLOW_RESET_CONFIG = False ├── THEME 色彩主题 ├── AUTO_CLEAR_TXT 是否在提交时自动清空输入框 ├── ADD_WAIFU 加一个live2d装饰 - +├── ALLOW_RESET_CONFIG 是否允许通过自然语言描述修改本页的配置,该功能具有一定的危险性 插件在线服务配置依赖关系示意图 diff --git a/crazy_functional.py b/crazy_functional.py index 8fed5f8..05e4466 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -268,7 +268,7 @@ def get_crazy_functions(): "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 - "Info": "下载arxiv论文并翻译摘要 | 输入参数为arxiv编号如1812.10695", + # "Info": "下载arxiv论文并翻译摘要 | 输入参数为arxiv编号如1812.10695", "Function": HotReload(下载arxiv论文并翻译摘要) } }) diff --git a/crazy_functions/vt_fns/vt_call_plugin.py b/crazy_functions/vt_fns/vt_call_plugin.py index 09b136f..1f84d23 100644 --- a/crazy_functions/vt_fns/vt_call_plugin.py +++ b/crazy_functions/vt_fns/vt_call_plugin.py @@ -37,6 +37,15 @@ def get_recent_file_prompt_support(chatbot): prompt += f"Only use it when necessary, otherwise, you can ignore this file." 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): plugin_arr_enum_prompt, plugin_arr_dict = read_avail_plugin_enum() 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) except: 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" yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) return if plugin_sel.plugin_selection not in plugin_arr_dict: 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" yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) diff --git a/crazy_functions/虚空终端.py b/crazy_functions/虚空终端.py index 6304bd7..c4f2b2f 100644 --- a/crazy_functions/虚空终端.py +++ b/crazy_functions/虚空终端.py @@ -50,7 +50,7 @@ def analyze_intention_with_simple_rules(txt): is_certain = True user_intention.intention_type = 'Chat' - if '调用插件' in txt: + if '用插件' in txt: is_certain = True 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): # 获取当前虚空终端状态 state = VoidTerminalState.get_state(chatbot) + appendix_msg = "" # 用简单的关键词检测用户意图 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): # 如果意图明确,跳过提示环节 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.lock_plugin(chatbot=chatbot) - chatbot.append(("虚空终端状态:", explain_msg)) + chatbot.append(("虚空终端状态:", explain_msg+appendix_msg)) yield from update_ui(chatbot=chatbot, history=history) return