From a208782049eb81cd9a2e5f040f7f45cfa4bea164 Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Wed, 30 Aug 2023 14:46:34 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 4 +- crazy_functional.py | 698 ++++++++++++++++++++------------------------ main.py | 64 +++- themes/default.css | 5 + themes/green.css | 6 +- 5 files changed, 378 insertions(+), 399 deletions(-) diff --git a/config.py b/config.py index 0983d22..3664c15 100644 --- a/config.py +++ b/config.py @@ -67,6 +67,8 @@ WEB_PORT = -1 # 如果OpenAI不响应(网络卡顿、代理失败、KEY失效),重试的次数限制 MAX_RETRY = 2 +# 插件分类默认选项 +default_plugin = ['学术优化', '多功能插件', '代码解析'] # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓ @@ -100,7 +102,7 @@ AUTO_CLEAR_TXT = False # 色彩主体,可选 ["Default", "Chuanhu-Small-and-Beautiful"] -THEME = "Default" +THEME = "Chuanhu-Small-and-Beautiful" # 加一个live2d装饰 diff --git a/crazy_functional.py b/crazy_functional.py index fcc4e52..99aad8a 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -1,8 +1,16 @@ from toolbox import HotReload # HotReload 的意思是热更新,修改函数插件后,不需要重启程序,代码直接生效 +function_plugins = {} + def get_crazy_functions(): - from crazy_functions.读文章写摘要 import 读文章写摘要 + get_functions_学术优化() + get_functions_文档读取() + get_functions_代码解析() + get_functions_多功能插件() + return function_plugins + +def get_functions_代码解析(): from crazy_functions.生成函数注释 import 批量生成函数注释 from crazy_functions.解析项目源代码 import 解析项目本身 from crazy_functions.解析项目源代码 import 解析一个Python项目 @@ -14,37 +22,257 @@ def get_crazy_functions(): from crazy_functions.解析项目源代码 import 解析一个前端项目 from crazy_functions.高级功能函数模板 import 高阶功能模板函数 from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文 - from crazy_functions.Latex全文润色 import Latex英文润色 - from crazy_functions.询问多个大语言模型 import 同时问询 from crazy_functions.解析项目源代码 import 解析一个Lua项目 from crazy_functions.解析项目源代码 import 解析一个CSharp项目 - from crazy_functions.总结word文档 import 总结word文档 from crazy_functions.解析JupyterNotebook import 解析ipynb文件 - from crazy_functions.对话历史存档 import 对话历史存档 - from crazy_functions.对话历史存档 import 载入对话历史存档 - from crazy_functions.对话历史存档 import 删除所有本地对话历史记录 - from crazy_functions.辅助功能 import 清除缓存 - from crazy_functions.批量Markdown翻译 import Markdown英译中 - from crazy_functions.批量总结PDF文档 import 批量总结PDF文档 - from crazy_functions.批量翻译PDF文档_多线程 import 批量翻译PDF文档 - from crazy_functions.谷歌检索小助手 import 谷歌检索小助手 - from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入 - from crazy_functions.Latex全文润色 import Latex中文润色 - from crazy_functions.Latex全文润色 import Latex英文纠错 - from crazy_functions.Latex全文翻译 import Latex中译英 - from crazy_functions.Latex全文翻译 import Latex英译中 + from crazy_functions.解析项目源代码 import 解析任意code项目 from crazy_functions.批量Markdown翻译 import Markdown中译英 - - - function_plugins = { + function_plugins['代码解析'] = { "解析整个Python项目": { - "Color": "stop", + "Color": "primary", "AsButton": True, "Info": "解析一个Python项目的所有源文件(.py) | 输入参数为路径", "Function": HotReload(解析一个Python项目) }, + "解析整个C++项目头文件": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个C++项目的所有头文件(.h/.hpp) | 输入参数为路径", + "Function": HotReload(解析一个C项目的头文件) + }, + "解析整个C++项目(.cpp/.hpp/.c/.h)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个C++项目的所有源文件(.cpp/.hpp/.c/.h)| 输入参数为路径", + "Function": HotReload(解析一个C项目) + }, + "解析整个Go项目": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个Go项目的所有源文件 | 输入参数为路径", + "Function": HotReload(解析一个Golang项目) + }, + "解析整个Rust项目": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个Rust项目的所有源文件 | 输入参数为路径", + "Function": HotReload(解析一个Rust项目) + }, + "解析整个Java项目": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个Java项目的所有源文件 | 输入参数为路径", + "Function": HotReload(解析一个Java项目) + }, + "解析整个前端项目(js,ts,css等)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个前端项目的所有源文件(js,ts,css等) | 输入参数为路径", + "Function": HotReload(解析一个前端项目) + }, + "解析整个Lua项目": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个Lua项目的所有源文件 | 输入参数为路径", + "Function": HotReload(解析一个Lua项目) + }, + "解析整个CSharp项目": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Info": "解析一个CSharp项目的所有源文件 | 输入参数为路径", + "Function": HotReload(解析一个CSharp项目) + }, + "解析Jupyter Notebook文件": { + "Color": "primary", + "AsButton": False, + "Info": "解析Jupyter Notebook文件 | 输入参数为路径", + "Function": HotReload(解析ipynb文件), + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示 + }, + "批量生成函数注释": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(批量生成函数注释) + }, + "[多线程Demo] 解析此项目本身(源码自译解)": { + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(解析项目本身) + }, + "[插件demo] 历史上的今天": { + "AsButton": True, + "Function": HotReload(高阶功能模板函数) + }, + "批量Markdown中译英(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Markdown中译英) + }, + "解析项目源代码(手动指定和筛选源代码文件类型)": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "输入时用逗号隔开, *代表通配符, 加了^代表不匹配; 不输入代表全部匹配。例如: \"*.c, ^*.cpp, config.toml, ^*.toml\"", + # 高级参数输入区的显示提示 + "Function": HotReload(解析任意code项目) + }, + + } + + +def get_functions_文档读取(): + from crazy_functions.读文章写摘要 import 读文章写摘要 + from crazy_functions.总结word文档 import 总结word文档 + from crazy_functions.批量总结PDF文档 import 批量总结PDF文档 + from crazy_functions.批量翻译PDF文档_多线程 import 批量翻译PDF文档 + from crazy_functions.批量Markdown翻译 import Markdown英译中 + from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入 + from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言 + function_plugins['文档读取'] = { + "批量总结PDF文档": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(批量总结PDF文档) + }, + "理解PDF文档内容 (模仿ChatPDF)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(理解PDF文档内容标准文件输入) + }, + "精准翻译PDF论文": { + "Color": "primary", + "AsButton": True, # 加入下拉菜单中 + "Function": HotReload(批量翻译PDF文档) + }, + "批量总结Word文档": { + "Color": "primary", + "AsButton": True, + "Info": "批量总结word文档 | 输入参数为路径", + "Function": HotReload(总结word文档) + }, + "读Tex论文写摘要": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(读文章写摘要) + }, + "翻译README或.MD": { + "Color": "primary", + "AsButton": True, + "Info": "将Markdown翻译为中文 | 输入参数为路径或URL", + "Function": HotReload(Markdown英译中) + }, + "翻译Markdown或README(支持Github链接)": { + "Color": "primary", + "AsButton": False, + "Function": HotReload(Markdown英译中) + }, + "Markdown翻译(手动指定语言)": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "请输入要翻译成哪种语言,默认为Chinese。", + "Function": HotReload(Markdown翻译指定语言) + }, + } + +def get_functions_学术优化(): + from crazy_functions.谷歌检索小助手 import 谷歌检索小助手 + from crazy_functions.Latex全文润色 import Latex中文润色 + from crazy_functions.Latex全文润色 import Latex英文纠错 + from crazy_functions.Latex全文翻译 import Latex中译英 + from crazy_functions.Latex全文翻译 import Latex英译中 + from crazy_functions.Latex全文润色 import Latex英文润色 + from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要 + from crazy_functions.Latex输出PDF结果 import Latex英文纠错加PDF对比 + from crazy_functions.Latex输出PDF结果 import Latex翻译中文并重新编译PDF + function_plugins['学术优化'] = { + "英文Latex项目全文纠错(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英文纠错) + }, + "中文Latex项目全文润色(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex中文润色) + }, + "Latex项目全文中译英(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex中译英) + }, + "Latex项目全文英译中(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英译中) + }, + "谷歌学术检索助手(输入谷歌学术搜索页url)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(谷歌检索小助手) + }, + "英文Latex项目全文润色(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英文润色) + }, + "Arixv论文精细翻译(输入arxivID)[需Latex]": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": + "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + + "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + + 'If the term "agent" is used in this section, it should be translated to "智能体". ', + "Function": HotReload(Latex翻译中文并重新编译PDF) + }, + "Latex英文纠错+高亮修正位置 [需Latex]": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "如果有必要, 请在此处追加更细致的矫错指令(使用英文)。", + "Function": HotReload(Latex英文纠错加PDF对比) + }, + + } + function_plugins['学术优化'].update({ + "一键下载arxiv论文并翻译摘要(先在input输入编号,如1812.10695)": { + "Color": "primary", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(下载arxiv论文并翻译摘要) + } + }) + +def get_functions_多功能插件(): + from crazy_functions.询问多个大语言模型 import 同时问询 + from crazy_functions.对话历史存档 import 对话历史存档 + from crazy_functions.对话历史存档 import 载入对话历史存档 + from crazy_functions.对话历史存档 import 删除所有本地对话历史记录 + from crazy_functions.辅助功能 import 清除缓存 + from crazy_functions.联网的ChatGPT import 连接网络回答问题 + from crazy_functions.联网的ChatGPT_bing版 import 连接bing搜索回答问题 + from crazy_functions.询问多个大语言模型 import 同时问询_指定模型 + from crazy_functions.图片生成 import 图片生成 + from crazy_functions.总结音视频 import 总结音视频 + from crazy_functions.数学动画生成manim import 动画生成 + from crazy_functions.Langchain知识库 import 知识库问答 + from crazy_functions.Langchain知识库 import 读取知识库作答 + from crazy_functions.交互功能函数模板 import 交互功能模板函数 + from crazy_functions.语音助手 import 语音助手 + from crazy_functions.虚空终端 import 自动终端 + function_plugins['多功能插件'] = { + "询问多个GPT模型": { + "Color": "primary", + "AsButton": True, + "Function": HotReload(同时问询) + }, + "保存当前的对话": { + "AsButton": True, + "Info": "保存当前的对话 | 不需要输入参数", + "Function": HotReload(对话历史存档) + }, "载入对话历史存档(先上传存档或输入路径)": { - "Color": "stop", + "Color": "primary", "AsButton": False, "Info": "载入对话历史存档 | 输入参数为路径", "Function": HotReload(载入对话历史存档) @@ -55,392 +283,84 @@ def get_crazy_functions(): "Function": HotReload(删除所有本地对话历史记录) }, "清除所有缓存文件(谨慎操作)": { - "Color": "stop", + "Color": "primary", "AsButton": False, # 加入下拉菜单中 "Info": "清除所有缓存文件,谨慎操作 | 不需要输入参数", "Function": HotReload(清除缓存) }, - "批量总结Word文档": { - "Color": "stop", - "AsButton": True, - "Info": "批量总结word文档 | 输入参数为路径", - "Function": HotReload(总结word文档) - }, - "解析整个C++项目头文件": { - "Color": "stop", + "连接网络回答问题(输入问题后点击该插件,需要访问谷歌)": { + "Color": "primary", "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个C++项目的所有头文件(.h/.hpp) | 输入参数为路径", - "Function": HotReload(解析一个C项目的头文件) + "Function": HotReload(连接网络回答问题) }, - "解析整个C++项目(.cpp/.hpp/.c/.h)": { - "Color": "stop", + "连接网络回答问题(中文Bing版,输入问题后点击该插件)": { + "Color": "primary", "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个C++项目的所有源文件(.cpp/.hpp/.c/.h)| 输入参数为路径", - "Function": HotReload(解析一个C项目) + "Function": HotReload(连接bing搜索回答问题) }, - "解析整个Go项目": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个Go项目的所有源文件 | 输入参数为路径", - "Function": HotReload(解析一个Golang项目) - }, - "解析整个Rust项目": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个Rust项目的所有源文件 | 输入参数为路径", - "Function": HotReload(解析一个Rust项目) - }, - "解析整个Java项目": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个Java项目的所有源文件 | 输入参数为路径", - "Function": HotReload(解析一个Java项目) - }, - "解析整个前端项目(js,ts,css等)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个前端项目的所有源文件(js,ts,css等) | 输入参数为路径", - "Function": HotReload(解析一个前端项目) - }, - "解析整个Lua项目": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个Lua项目的所有源文件 | 输入参数为路径", - "Function": HotReload(解析一个Lua项目) - }, - "解析整个CSharp项目": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Info": "解析一个CSharp项目的所有源文件 | 输入参数为路径", - "Function": HotReload(解析一个CSharp项目) - }, - "解析Jupyter Notebook文件": { - "Color": "stop", + "询问多个GPT模型(手动指定询问哪些模型)": { + "Color": "primary", "AsButton": False, - "Info": "解析Jupyter Notebook文件 | 输入参数为路径", - "Function": HotReload(解析ipynb文件), "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示 + "ArgsReminder": "支持任意数量的llm接口,用&符号分隔。例如chatglm&gpt-3.5-turbo&api2d-gpt-4", # 高级参数输入区的显示提示 + "Function": HotReload(同时问询_指定模型) }, - "读Tex论文写摘要": { - "Color": "stop", - "AsButton": True, - "Function": HotReload(读文章写摘要) - }, - "翻译README或.MD": { - "Color": "stop", - "AsButton": True, - "Info": "将Markdown翻译为中文 | 输入参数为路径或URL", - "Function": HotReload(Markdown英译中) - }, - "翻译Markdown或README(支持Github链接)": { - "Color": "stop", + "图片生成(先切换模型到openai或api2d)": { + "Color": "primary", "AsButton": False, - "Function": HotReload(Markdown英译中) + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 + "Info": "图片生成 | 输入参数字符串,提供图像的内容", + "Function": HotReload(图片生成) }, - "批量生成函数注释": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(批量生成函数注释) + "批量总结音视频(输入路径或上传压缩包)": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "调用openai api 使用whisper-1模型, 目前支持的格式:mp4, m4a, wav, mpga, mpeg, mp3。此处可以输入解析提示,例如:解析为简体中文(默认)。", + "Info": "批量总结音频或视频 | 输入参数为路径", + "Function": HotReload(总结音视频) }, - "保存当前的对话": { + "数学动画生成(Manim)": { + "Color": "primary", + "AsButton": False, + "Function": HotReload(动画生成) + }, + "构建知识库(请先上传文件素材)": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "待注入的知识库名称id, 默认为default", + "Function": HotReload(知识库问答) + }, + "知识库问答": { + "Color": "primary", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "待提取的知识库名称id, 默认为default, 您需要首先调用构建知识库", + "Function": HotReload(读取知识库作答) + }, + "交互功能模板函数": { + "Color": "primary", + "AsButton": False, + "Function": HotReload(交互功能模板函数) + }, + "实时音频采集": { + "Color": "primary", "AsButton": True, - "Info": "保存当前的对话 | 不需要输入参数", - "Function": HotReload(对话历史存档) - }, - "[多线程Demo] 解析此项目本身(源码自译解)": { - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(解析项目本身) - }, - "[插件demo] 历史上的今天": { - "AsButton": True, - "Function": HotReload(高阶功能模板函数) - }, - "精准翻译PDF论文": { - "Color": "stop", - "AsButton": True, # 加入下拉菜单中 - "Function": HotReload(批量翻译PDF文档) - }, - "询问多个GPT模型": { - "Color": "stop", - "AsButton": True, - "Function": HotReload(同时问询) - }, - "批量总结PDF文档": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(批量总结PDF文档) - }, - "谷歌学术检索助手(输入谷歌学术搜索页url)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(谷歌检索小助手) - }, - "理解PDF文档内容 (模仿ChatPDF)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(理解PDF文档内容标准文件输入) - }, - "英文Latex项目全文润色(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英文润色) - }, - "英文Latex项目全文纠错(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英文纠错) - }, - "中文Latex项目全文润色(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex中文润色) - }, - "Latex项目全文中译英(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex中译英) - }, - "Latex项目全文英译中(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英译中) - }, - "批量Markdown中译英(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Markdown中译英) + "Function": HotReload(语音助手) }, + "自动终端": { + "Color": "primary", + "AsButton": False, + "Function": HotReload(自动终端) + } } - - # -=--=- 尚未充分测试的实验性插件 & 需要额外依赖的插件 -=--=- - try: - from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要 - function_plugins.update({ - "一键下载arxiv论文并翻译摘要(先在input输入编号,如1812.10695)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(下载arxiv论文并翻译摘要) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.联网的ChatGPT import 连接网络回答问题 - function_plugins.update({ - "连接网络回答问题(输入问题后点击该插件,需要访问谷歌)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(连接网络回答问题) - } - }) - from crazy_functions.联网的ChatGPT_bing版 import 连接bing搜索回答问题 - function_plugins.update({ - "连接网络回答问题(中文Bing版,输入问题后点击该插件)": { - "Color": "stop", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(连接bing搜索回答问题) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.解析项目源代码 import 解析任意code项目 - function_plugins.update({ - "解析项目源代码(手动指定和筛选源代码文件类型)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "输入时用逗号隔开, *代表通配符, 加了^代表不匹配; 不输入代表全部匹配。例如: \"*.c, ^*.cpp, config.toml, ^*.toml\"", # 高级参数输入区的显示提示 - "Function": HotReload(解析任意code项目) - }, - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.询问多个大语言模型 import 同时问询_指定模型 - function_plugins.update({ - "询问多个GPT模型(手动指定询问哪些模型)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "支持任意数量的llm接口,用&符号分隔。例如chatglm&gpt-3.5-turbo&api2d-gpt-4", # 高级参数输入区的显示提示 - "Function": HotReload(同时问询_指定模型) - }, - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.图片生成 import 图片生成 - function_plugins.update({ - "图片生成(先切换模型到openai或api2d)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 - "Info": "图片生成 | 输入参数字符串,提供图像的内容", - "Function": HotReload(图片生成) - }, - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.总结音视频 import 总结音视频 - function_plugins.update({ - "批量总结音视频(输入路径或上传压缩包)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "调用openai api 使用whisper-1模型, 目前支持的格式:mp4, m4a, wav, mpga, mpeg, mp3。此处可以输入解析提示,例如:解析为简体中文(默认)。", - "Info": "批量总结音频或视频 | 输入参数为路径", - "Function": HotReload(总结音视频) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.数学动画生成manim import 动画生成 - function_plugins.update({ - "数学动画生成(Manim)": { - "Color": "stop", - "AsButton": False, - "Function": HotReload(动画生成) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言 - function_plugins.update({ - "Markdown翻译(手动指定语言)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "请输入要翻译成哪种语言,默认为Chinese。", - "Function": HotReload(Markdown翻译指定语言) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.Langchain知识库 import 知识库问答 - function_plugins.update({ - "构建知识库(请先上传文件素材)": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "待注入的知识库名称id, 默认为default", - "Function": HotReload(知识库问答) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.Langchain知识库 import 读取知识库作答 - function_plugins.update({ - "知识库问答": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "待提取的知识库名称id, 默认为default, 您需要首先调用构建知识库", - "Function": HotReload(读取知识库作答) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.交互功能函数模板 import 交互功能模板函数 - function_plugins.update({ - "交互功能模板函数": { - "Color": "stop", - "AsButton": False, - "Function": HotReload(交互功能模板函数) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.Latex输出PDF结果 import Latex英文纠错加PDF对比 - function_plugins.update({ - "Latex英文纠错+高亮修正位置 [需Latex]": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "如果有必要, 请在此处追加更细致的矫错指令(使用英文)。", - "Function": HotReload(Latex英文纠错加PDF对比) - } - }) - from crazy_functions.Latex输出PDF结果 import Latex翻译中文并重新编译PDF - function_plugins.update({ - "Arixv论文精细翻译(输入arxivID)[需Latex]": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": - "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + - "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + - 'If the term "agent" is used in this section, it should be translated to "智能体". ', - "Function": HotReload(Latex翻译中文并重新编译PDF) - } - }) - function_plugins.update({ - "本地Latex论文精细翻译(上传Latex项目)[需Latex]": { - "Color": "stop", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": - "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + - "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + - 'If the term "agent" is used in this section, it should be translated to "智能体". ', - "Function": HotReload(Latex翻译中文并重新编译PDF) - } - }) - except: - print('Load function plugin failed') - - try: - from toolbox import get_conf - ENABLE_AUDIO, = get_conf('ENABLE_AUDIO') - if ENABLE_AUDIO: - from crazy_functions.语音助手 import 语音助手 - function_plugins.update({ - "实时音频采集": { - "Color": "stop", - "AsButton": True, - "Function": HotReload(语音助手) - } - }) - except: - print('Load function plugin failed') - - try: - from crazy_functions.虚空终端 import 自动终端 - function_plugins.update({ - "自动终端": { - "Color": "stop", - "AsButton": False, - "Function": HotReload(自动终端) - } - }) - except: - print('Load function plugin failed') - # try: # from crazy_functions.chatglm微调工具 import 微调数据集生成 - # function_plugins.update({ + # function_plugins['多功能'].update({ # "黑盒模型学习: 微调数据集生成 (先上传数据集)": { - # "Color": "stop", + # "Color": "primary", # "AsButton": False, # "AdvancedArgs": True, # "ArgsReminder": "针对数据集输入(如 绿帽子*深蓝色衬衫*黑色运动裤)给出指令,例如您可以将以下命令复制到下方: --llm_to_learn=azure-gpt-3.5 --prompt_prefix='根据下面的服装类型提示,想象一个穿着者,对这个人外貌、身处的环境、内心世界、过去经历进行描写。要求:100字以内,用第二人称。' --system_prompt=''", @@ -449,4 +369,4 @@ def get_crazy_functions(): # }) # except: # print('Load function plugin failed') - return function_plugins + diff --git a/main.py b/main.py index 0f8ea07..4ecb2f7 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 def main(): import gradio as gr - if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt" + # if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt" from request_llm.bridge_all import predict from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 @@ -34,7 +34,13 @@ def main(): # 高级函数插件 from crazy_functional import get_crazy_functions - crazy_fns = get_crazy_functions() + default_plugin, = get_conf('default_plugin') + crazy_fns_role = get_crazy_functions() + crazy_classification = [i for i in crazy_fns_role] + crazy_fns = {} + for role in crazy_fns_role: + for k in crazy_fns_role[role]: + crazy_fns[k] = crazy_fns_role[role][k] # 处理markdown文本格式的转变 gr.Chatbot.postprocess = format_io @@ -86,15 +92,35 @@ def main(): with gr.Accordion("函数插件区", open=True, elem_id="plugin-panel") as area_crazy_fn: with gr.Row(): gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)") + plugin_dropdown = gr.Dropdown(choices=crazy_classification, label='选择插件分类', + value=default_plugin, + multiselect=True, interactive=True, + elem_classes='normal_mut_select' + ).style(container=False) with gr.Row(): - for k in crazy_fns: - if not crazy_fns[k].get("AsButton", True): continue - variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary" - crazy_fns[k]["Button"] = gr.Button(k, variant=variant) - crazy_fns[k]["Button"].style(size="sm") + for role in crazy_fns_role: + for k in crazy_fns_role[role]: + if not crazy_fns_role[role][k].get("AsButton", True): continue + if role not in default_plugin: + variant = crazy_fns_role[role][k]["Color"] if "Color" in crazy_fns_role[role][ + k] else "secondary" + crazy_fns_role[role][k]['Button'] = gr.Button(k, variant=variant, + visible=False).style(size="sm") + else: + variant = crazy_fns[k]["Color"] if "Color" in crazy_fns_role[role][ + k] else "secondary" + crazy_fns_role[role][k]['Button'] = gr.Button(k, variant=variant, + visible=True).style(size="sm") with gr.Row(): with gr.Accordion("更多函数插件", open=True): - dropdown_fn_list = [k for k in crazy_fns.keys() if not crazy_fns[k].get("AsButton", True)] + dropdown_fn_list = [] + for role in crazy_fns_role: + if role in default_plugin: + for k in crazy_fns_role[role]: + if not crazy_fns_role[role][k].get("AsButton", True): + dropdown_fn_list.append(k) + elif crazy_fns_role[role][k].get('AdvancedArgs', False): + dropdown_fn_list.append(k) with gr.Row(): dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="", show_label=False).style(container=False) with gr.Row(): @@ -190,6 +216,28 @@ def main(): # 终止按钮的回调函数注册 stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) + fn_btn_dict = {crazy_fns_role[role][k]['Button']: {role: k} for role in crazy_fns_role for k in crazy_fns_role[role] if crazy_fns_role[role][k].get('Button')} + def show_plugin_btn(plu_list): + new_btn_list = [] + fns_list = [] + if not plu_list: + return [*[fns.update(visible=False) for fns in fn_btn_dict], gr.Dropdown.update(choices=[])] + else: + for fns in fn_btn_dict: + if list(fn_btn_dict[fns].keys())[0] in plu_list: + new_btn_list.append(fns.update(visible=True)) + else: + new_btn_list.append(fns.update(visible=False)) + for role in crazy_fns_role: + if role in plu_list: + for k in crazy_fns_role[role]: + if not crazy_fns_role[role][k].get("AsButton", True): + fns_list.append(k) + elif crazy_fns_role[role][k].get('AdvancedArgs', False): + fns_list.append(k) + return [*new_btn_list, gr.Dropdown.update(choices=fns_list)] + plugin_dropdown.select(fn=show_plugin_btn, inputs=[plugin_dropdown], + outputs=[*fn_btn_dict.keys(), dropdown]) if ENABLE_AUDIO: from crazy_functions.live_audio.audio_io import RealtimeAudioDistribution rad = RealtimeAudioDistribution() diff --git a/themes/default.css b/themes/default.css index 07b5383..5fba4af 100644 --- a/themes/default.css +++ b/themes/default.css @@ -16,6 +16,11 @@ .markdown-body thead th { padding: .5em .2em; } +.normal_mut_select .svelte-1gfkn6j { + float: left; + width: auto; + line-height: 260% !important; +} .markdown-body ol, .markdown-body ul { padding-inline-start: 2em !important; diff --git a/themes/green.css b/themes/green.css index 950ac2e..dd109d5 100644 --- a/themes/green.css +++ b/themes/green.css @@ -24,7 +24,11 @@ mspace { border-color: yellow; } } - +.normal_mut_select .svelte-1gfkn6j { + float: left; + width: auto; + line-height: 260% !important; +} #highlight_update { animation-name: highlight; animation-duration: 0.75s; From 89de49f31ee5e3ff34d8f9a7f0daa91d2a13847f Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Wed, 30 Aug 2023 16:00:27 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=91=BD=E5=90=8D=EF=BC=8C=E6=95=B4=E7=90=86=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 20 +++++++++++++++++--- main.py | 8 ++++---- request_llm/bridge_chatglmft.py | 10 +++++----- toolbox.py | 4 ++-- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/config.py b/config.py index 3664c15..20e5d8d 100644 --- a/config.py +++ b/config.py @@ -67,8 +67,10 @@ WEB_PORT = -1 # 如果OpenAI不响应(网络卡顿、代理失败、KEY失效),重试的次数限制 MAX_RETRY = 2 + # 插件分类默认选项 -default_plugin = ['学术优化', '多功能插件', '代码解析'] +DEFAULT_FN_GROUPS = ['学术优化', '多功能插件', '代码解析'] + # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓ @@ -85,7 +87,7 @@ BAIDU_CLOUD_QIANFAN_MODEL = 'ERNIE-Bot' # 可选 "ERNIE-Bot"(文心一言), " # 如果使用ChatGLM2微调模型,请把 LLM_MODEL="chatglmft",并在此处指定模型路径 -ChatGLM_PTUNING_CHECKPOINT = "" # 例如"/home/hmp/ChatGLM2-6B/ptuning/output/6b-pt-128-1e-2/checkpoint-100" +CHATGLM_PTUNING_CHECKPOINT = "" # 例如"/home/hmp/ChatGLM2-6B/ptuning/output/6b-pt-128-1e-2/checkpoint-100" # 本地LLM模型如ChatGLM的执行方式 CPU/GPU @@ -101,7 +103,7 @@ CONCURRENT_COUNT = 100 AUTO_CLEAR_TXT = False -# 色彩主体,可选 ["Default", "Chuanhu-Small-and-Beautiful"] +# 色彩主题,可选 ["Default", "Chuanhu-Small-and-Beautiful"] THEME = "Chuanhu-Small-and-Beautiful" @@ -215,6 +217,18 @@ ALLOW_RESET_CONFIG = False ├── NEWBING_STYLE └── NEWBING_COOKIES + +用户图形界面布局依赖关系示意图 +│ +├── CHATBOT_HEIGHT 对话窗的高度 +├── CODE_HIGHLIGHT 代码高亮 +├── LAYOUT 窗口布局 +├── DARK_MODE 暗色模式 / 亮色模式 +├── DEFAULT_FN_GROUPS 插件分类默认选项 +├── THEME 色彩主题 +├── AUTO_CLEAR_TXT 是否在提交时自动清空输入框 +├── ADD_WAIFU 加一个live2d装饰 + 插件在线服务配置依赖关系示意图 diff --git a/main.py b/main.py index 4ecb2f7..ced4177 100644 --- a/main.py +++ b/main.py @@ -34,7 +34,7 @@ def main(): # 高级函数插件 from crazy_functional import get_crazy_functions - default_plugin, = get_conf('default_plugin') + DEFAULT_FN_GROUPS, = get_conf('DEFAULT_FN_GROUPS') crazy_fns_role = get_crazy_functions() crazy_classification = [i for i in crazy_fns_role] crazy_fns = {} @@ -93,7 +93,7 @@ def main(): with gr.Row(): gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)") plugin_dropdown = gr.Dropdown(choices=crazy_classification, label='选择插件分类', - value=default_plugin, + value=DEFAULT_FN_GROUPS, multiselect=True, interactive=True, elem_classes='normal_mut_select' ).style(container=False) @@ -101,7 +101,7 @@ def main(): for role in crazy_fns_role: for k in crazy_fns_role[role]: if not crazy_fns_role[role][k].get("AsButton", True): continue - if role not in default_plugin: + if role not in DEFAULT_FN_GROUPS: variant = crazy_fns_role[role][k]["Color"] if "Color" in crazy_fns_role[role][ k] else "secondary" crazy_fns_role[role][k]['Button'] = gr.Button(k, variant=variant, @@ -115,7 +115,7 @@ def main(): with gr.Accordion("更多函数插件", open=True): dropdown_fn_list = [] for role in crazy_fns_role: - if role in default_plugin: + if role in DEFAULT_FN_GROUPS: for k in crazy_fns_role[role]: if not crazy_fns_role[role][k].get("AsButton", True): dropdown_fn_list.append(k) diff --git a/request_llm/bridge_chatglmft.py b/request_llm/bridge_chatglmft.py index 4e21c98..71af942 100644 --- a/request_llm/bridge_chatglmft.py +++ b/request_llm/bridge_chatglmft.py @@ -63,9 +63,9 @@ class GetGLMFTHandle(Process): # if not os.path.exists(conf): raise RuntimeError('找不到微调模型信息') # with open(conf, 'r', encoding='utf8') as f: # model_args = json.loads(f.read()) - ChatGLM_PTUNING_CHECKPOINT, = get_conf('ChatGLM_PTUNING_CHECKPOINT') - assert os.path.exists(ChatGLM_PTUNING_CHECKPOINT), "找不到微调模型检查点" - conf = os.path.join(ChatGLM_PTUNING_CHECKPOINT, "config.json") + CHATGLM_PTUNING_CHECKPOINT, = get_conf('CHATGLM_PTUNING_CHECKPOINT') + assert os.path.exists(CHATGLM_PTUNING_CHECKPOINT), "找不到微调模型检查点" + conf = os.path.join(CHATGLM_PTUNING_CHECKPOINT, "config.json") with open(conf, 'r', encoding='utf8') as f: model_args = json.loads(f.read()) if 'model_name_or_path' not in model_args: @@ -78,9 +78,9 @@ class GetGLMFTHandle(Process): config.pre_seq_len = model_args['pre_seq_len'] config.prefix_projection = model_args['prefix_projection'] - print(f"Loading prefix_encoder weight from {ChatGLM_PTUNING_CHECKPOINT}") + print(f"Loading prefix_encoder weight from {CHATGLM_PTUNING_CHECKPOINT}") model = AutoModel.from_pretrained(model_args['model_name_or_path'], config=config, trust_remote_code=True) - prefix_state_dict = torch.load(os.path.join(ChatGLM_PTUNING_CHECKPOINT, "pytorch_model.bin")) + prefix_state_dict = torch.load(os.path.join(CHATGLM_PTUNING_CHECKPOINT, "pytorch_model.bin")) new_prefix_state_dict = {} for k, v in prefix_state_dict.items(): if k.startswith("transformer.prefix_encoder."): diff --git a/toolbox.py b/toolbox.py index 73e3e8d..6da2347 100644 --- a/toolbox.py +++ b/toolbox.py @@ -1001,7 +1001,7 @@ def get_plugin_default_kwargs(): chatbot = ChatBotWithCookies(llm_kwargs) # txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port - default_plugin_kwargs = { + DEFAULT_FN_GROUPS_kwargs = { "main_input": "./README.md", "llm_kwargs": llm_kwargs, "plugin_kwargs": {}, @@ -1010,7 +1010,7 @@ def get_plugin_default_kwargs(): "system_prompt": "You are a good AI.", "web_port": WEB_PORT } - return default_plugin_kwargs + return DEFAULT_FN_GROUPS_kwargs def get_chat_default_kwargs(): """ From 2d5a1fbc126397c18163911473f4416aa40a92ad Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 31 Aug 2023 00:21:24 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 12 +- crazy_functional.py | 669 ++++++++++++++++++++++++++------------------ main.py | 13 +- themes/common.css | 15 + themes/common.js | 5 +- themes/contrast.css | 482 +++++++++++++++++++++++++++++++ themes/contrast.py | 88 ++++++ themes/default.css | 44 +++ themes/default.py | 6 +- themes/green.py | 2 + themes/theme.py | 3 + 11 files changed, 1059 insertions(+), 280 deletions(-) create mode 100644 themes/common.css create mode 100644 themes/contrast.css create mode 100644 themes/contrast.py diff --git a/config.py b/config.py index 20e5d8d..6442ad8 100644 --- a/config.py +++ b/config.py @@ -43,7 +43,11 @@ API_URL_REDIRECT = {} DEFAULT_WORKER_NUM = 3 -# 对话窗的高度 +# 色彩主题,可选 ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast"] +THEME = "Default" + + +# 对话窗的高度 (仅在LAYOUT="TOP-DOWN"时生效) CHATBOT_HEIGHT = 1115 @@ -69,7 +73,7 @@ MAX_RETRY = 2 # 插件分类默认选项 -DEFAULT_FN_GROUPS = ['学术优化', '多功能插件', '代码解析'] +DEFAULT_FN_GROUPS = ['对话', '编程', '学术'] # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) @@ -103,10 +107,6 @@ CONCURRENT_COUNT = 100 AUTO_CLEAR_TXT = False -# 色彩主题,可选 ["Default", "Chuanhu-Small-and-Beautiful"] -THEME = "Chuanhu-Small-and-Beautiful" - - # 加一个live2d装饰 ADD_WAIFU = False diff --git a/crazy_functional.py b/crazy_functional.py index 99aad8a..ee3ed99 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -1,16 +1,8 @@ from toolbox import HotReload # HotReload 的意思是热更新,修改函数插件后,不需要重启程序,代码直接生效 -function_plugins = {} - def get_crazy_functions(): - get_functions_学术优化() - get_functions_文档读取() - get_functions_代码解析() - get_functions_多功能插件() - return function_plugins - -def get_functions_代码解析(): + from crazy_functions.读文章写摘要 import 读文章写摘要 from crazy_functions.生成函数注释 import 批量生成函数注释 from crazy_functions.解析项目源代码 import 解析项目本身 from crazy_functions.解析项目源代码 import 解析一个Python项目 @@ -22,345 +14,482 @@ def get_functions_代码解析(): from crazy_functions.解析项目源代码 import 解析一个前端项目 from crazy_functions.高级功能函数模板 import 高阶功能模板函数 from crazy_functions.代码重写为全英文_多线程 import 全项目切换英文 + from crazy_functions.Latex全文润色 import Latex英文润色 + from crazy_functions.询问多个大语言模型 import 同时问询 from crazy_functions.解析项目源代码 import 解析一个Lua项目 from crazy_functions.解析项目源代码 import 解析一个CSharp项目 + from crazy_functions.总结word文档 import 总结word文档 from crazy_functions.解析JupyterNotebook import 解析ipynb文件 - from crazy_functions.解析项目源代码 import 解析任意code项目 + from crazy_functions.对话历史存档 import 对话历史存档 + from crazy_functions.对话历史存档 import 载入对话历史存档 + from crazy_functions.对话历史存档 import 删除所有本地对话历史记录 + from crazy_functions.辅助功能 import 清除缓存 + from crazy_functions.批量Markdown翻译 import Markdown英译中 + from crazy_functions.批量总结PDF文档 import 批量总结PDF文档 + from crazy_functions.批量翻译PDF文档_多线程 import 批量翻译PDF文档 + from crazy_functions.谷歌检索小助手 import 谷歌检索小助手 + from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入 + from crazy_functions.Latex全文润色 import Latex中文润色 + from crazy_functions.Latex全文润色 import Latex英文纠错 + from crazy_functions.Latex全文翻译 import Latex中译英 + from crazy_functions.Latex全文翻译 import Latex英译中 from crazy_functions.批量Markdown翻译 import Markdown中译英 - function_plugins['代码解析'] = { + + + function_plugins = { "解析整个Python项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": True, "Info": "解析一个Python项目的所有源文件(.py) | 输入参数为路径", "Function": HotReload(解析一个Python项目) }, + "载入对话历史存档(先上传存档或输入路径)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "Info": "载入对话历史存档 | 输入参数为路径", + "Function": HotReload(载入对话历史存档) + }, + "删除所有本地对话历史记录(谨慎操作)": { + "Group": "对话", + "AsButton": False, + "Info": "删除所有本地对话历史记录,谨慎操作 | 不需要输入参数", + "Function": HotReload(删除所有本地对话历史记录) + }, + "清除所有缓存文件(谨慎操作)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Info": "清除所有缓存文件,谨慎操作 | 不需要输入参数", + "Function": HotReload(清除缓存) + }, + "批量总结Word文档": { + "Group": "学术", + "Color": "stop", + "AsButton": True, + "Info": "批量总结word文档 | 输入参数为路径", + "Function": HotReload(总结word文档) + }, "解析整个C++项目头文件": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个C++项目的所有头文件(.h/.hpp) | 输入参数为路径", "Function": HotReload(解析一个C项目的头文件) }, "解析整个C++项目(.cpp/.hpp/.c/.h)": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个C++项目的所有源文件(.cpp/.hpp/.c/.h)| 输入参数为路径", "Function": HotReload(解析一个C项目) }, "解析整个Go项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个Go项目的所有源文件 | 输入参数为路径", "Function": HotReload(解析一个Golang项目) }, "解析整个Rust项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个Rust项目的所有源文件 | 输入参数为路径", "Function": HotReload(解析一个Rust项目) }, "解析整个Java项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个Java项目的所有源文件 | 输入参数为路径", "Function": HotReload(解析一个Java项目) }, "解析整个前端项目(js,ts,css等)": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个前端项目的所有源文件(js,ts,css等) | 输入参数为路径", "Function": HotReload(解析一个前端项目) }, "解析整个Lua项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个Lua项目的所有源文件 | 输入参数为路径", "Function": HotReload(解析一个Lua项目) }, "解析整个CSharp项目": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 "Info": "解析一个CSharp项目的所有源文件 | 输入参数为路径", "Function": HotReload(解析一个CSharp项目) }, "解析Jupyter Notebook文件": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, "Info": "解析Jupyter Notebook文件 | 输入参数为路径", "Function": HotReload(解析ipynb文件), "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) "ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示 }, - "批量生成函数注释": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(批量生成函数注释) - }, - "[多线程Demo] 解析此项目本身(源码自译解)": { - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(解析项目本身) - }, - "[插件demo] 历史上的今天": { - "AsButton": True, - "Function": HotReload(高阶功能模板函数) - }, - "批量Markdown中译英(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Markdown中译英) - }, - "解析项目源代码(手动指定和筛选源代码文件类型)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "输入时用逗号隔开, *代表通配符, 加了^代表不匹配; 不输入代表全部匹配。例如: \"*.c, ^*.cpp, config.toml, ^*.toml\"", - # 高级参数输入区的显示提示 - "Function": HotReload(解析任意code项目) - }, - - } - - -def get_functions_文档读取(): - from crazy_functions.读文章写摘要 import 读文章写摘要 - from crazy_functions.总结word文档 import 总结word文档 - from crazy_functions.批量总结PDF文档 import 批量总结PDF文档 - from crazy_functions.批量翻译PDF文档_多线程 import 批量翻译PDF文档 - from crazy_functions.批量Markdown翻译 import Markdown英译中 - from crazy_functions.理解PDF文档内容 import 理解PDF文档内容标准文件输入 - from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言 - function_plugins['文档读取'] = { - "批量总结PDF文档": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(批量总结PDF文档) - }, - "理解PDF文档内容 (模仿ChatPDF)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(理解PDF文档内容标准文件输入) - }, - "精准翻译PDF论文": { - "Color": "primary", - "AsButton": True, # 加入下拉菜单中 - "Function": HotReload(批量翻译PDF文档) - }, - "批量总结Word文档": { - "Color": "primary", - "AsButton": True, - "Info": "批量总结word文档 | 输入参数为路径", - "Function": HotReload(总结word文档) - }, "读Tex论文写摘要": { - "Color": "primary", + "Group": "学术", + "Color": "stop", "AsButton": True, "Function": HotReload(读文章写摘要) }, - "翻译README或.MD": { - "Color": "primary", + "翻译README或MD": { + "Group": "编程", + "Color": "stop", "AsButton": True, "Info": "将Markdown翻译为中文 | 输入参数为路径或URL", "Function": HotReload(Markdown英译中) }, "翻译Markdown或README(支持Github链接)": { - "Color": "primary", + "Group": "编程", + "Color": "stop", "AsButton": False, "Function": HotReload(Markdown英译中) }, - "Markdown翻译(手动指定语言)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "请输入要翻译成哪种语言,默认为Chinese。", - "Function": HotReload(Markdown翻译指定语言) - }, - } - -def get_functions_学术优化(): - from crazy_functions.谷歌检索小助手 import 谷歌检索小助手 - from crazy_functions.Latex全文润色 import Latex中文润色 - from crazy_functions.Latex全文润色 import Latex英文纠错 - from crazy_functions.Latex全文翻译 import Latex中译英 - from crazy_functions.Latex全文翻译 import Latex英译中 - from crazy_functions.Latex全文润色 import Latex英文润色 - from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要 - from crazy_functions.Latex输出PDF结果 import Latex英文纠错加PDF对比 - from crazy_functions.Latex输出PDF结果 import Latex翻译中文并重新编译PDF - function_plugins['学术优化'] = { - "英文Latex项目全文纠错(输入路径或上传压缩包)": { - "Color": "primary", + "批量生成函数注释": { + "Group": "编程", + "Color": "stop", "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英文纠错) - }, - "中文Latex项目全文润色(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex中文润色) - }, - "Latex项目全文中译英(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex中译英) - }, - "Latex项目全文英译中(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英译中) - }, - "谷歌学术检索助手(输入谷歌学术搜索页url)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(谷歌检索小助手) - }, - "英文Latex项目全文润色(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(Latex英文润色) - }, - "Arixv论文精细翻译(输入arxivID)[需Latex]": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": - "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + - "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + - 'If the term "agent" is used in this section, it should be translated to "智能体". ', - "Function": HotReload(Latex翻译中文并重新编译PDF) - }, - "Latex英文纠错+高亮修正位置 [需Latex]": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "如果有必要, 请在此处追加更细致的矫错指令(使用英文)。", - "Function": HotReload(Latex英文纠错加PDF对比) - }, - - } - function_plugins['学术优化'].update({ - "一键下载arxiv论文并翻译摘要(先在input输入编号,如1812.10695)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(下载arxiv论文并翻译摘要) - } - }) - -def get_functions_多功能插件(): - from crazy_functions.询问多个大语言模型 import 同时问询 - from crazy_functions.对话历史存档 import 对话历史存档 - from crazy_functions.对话历史存档 import 载入对话历史存档 - from crazy_functions.对话历史存档 import 删除所有本地对话历史记录 - from crazy_functions.辅助功能 import 清除缓存 - from crazy_functions.联网的ChatGPT import 连接网络回答问题 - from crazy_functions.联网的ChatGPT_bing版 import 连接bing搜索回答问题 - from crazy_functions.询问多个大语言模型 import 同时问询_指定模型 - from crazy_functions.图片生成 import 图片生成 - from crazy_functions.总结音视频 import 总结音视频 - from crazy_functions.数学动画生成manim import 动画生成 - from crazy_functions.Langchain知识库 import 知识库问答 - from crazy_functions.Langchain知识库 import 读取知识库作答 - from crazy_functions.交互功能函数模板 import 交互功能模板函数 - from crazy_functions.语音助手 import 语音助手 - from crazy_functions.虚空终端 import 自动终端 - function_plugins['多功能插件'] = { - "询问多个GPT模型": { - "Color": "primary", - "AsButton": True, - "Function": HotReload(同时问询) + "Function": HotReload(批量生成函数注释) }, "保存当前的对话": { + "Group": "对话", "AsButton": True, "Info": "保存当前的对话 | 不需要输入参数", "Function": HotReload(对话历史存档) }, - "载入对话历史存档(先上传存档或输入路径)": { - "Color": "primary", - "AsButton": False, - "Info": "载入对话历史存档 | 输入参数为路径", - "Function": HotReload(载入对话历史存档) - }, - "删除所有本地对话历史记录(谨慎操作)": { - "AsButton": False, - "Info": "删除所有本地对话历史记录,谨慎操作 | 不需要输入参数", - "Function": HotReload(删除所有本地对话历史记录) - }, - "清除所有缓存文件(谨慎操作)": { - "Color": "primary", + "[多线程Demo]解析此项目本身(源码自译解)": { + "Group": "对话", "AsButton": False, # 加入下拉菜单中 - "Info": "清除所有缓存文件,谨慎操作 | 不需要输入参数", - "Function": HotReload(清除缓存) + "Function": HotReload(解析项目本身) }, - "连接网络回答问题(输入问题后点击该插件,需要访问谷歌)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(连接网络回答问题) - }, - "连接网络回答问题(中文Bing版,输入问题后点击该插件)": { - "Color": "primary", - "AsButton": False, # 加入下拉菜单中 - "Function": HotReload(连接bing搜索回答问题) - }, - "询问多个GPT模型(手动指定询问哪些模型)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "支持任意数量的llm接口,用&符号分隔。例如chatglm&gpt-3.5-turbo&api2d-gpt-4", # 高级参数输入区的显示提示 - "Function": HotReload(同时问询_指定模型) - }, - "图片生成(先切换模型到openai或api2d)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) - "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 - "Info": "图片生成 | 输入参数字符串,提供图像的内容", - "Function": HotReload(图片生成) - }, - "批量总结音视频(输入路径或上传压缩包)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "调用openai api 使用whisper-1模型, 目前支持的格式:mp4, m4a, wav, mpga, mpeg, mp3。此处可以输入解析提示,例如:解析为简体中文(默认)。", - "Info": "批量总结音频或视频 | 输入参数为路径", - "Function": HotReload(总结音视频) - }, - "数学动画生成(Manim)": { - "Color": "primary", - "AsButton": False, - "Function": HotReload(动画生成) - }, - "构建知识库(请先上传文件素材)": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "待注入的知识库名称id, 默认为default", - "Function": HotReload(知识库问答) - }, - "知识库问答": { - "Color": "primary", - "AsButton": False, - "AdvancedArgs": True, - "ArgsReminder": "待提取的知识库名称id, 默认为default, 您需要首先调用构建知识库", - "Function": HotReload(读取知识库作答) - }, - "交互功能模板函数": { - "Color": "primary", - "AsButton": False, - "Function": HotReload(交互功能模板函数) - }, - "实时音频采集": { - "Color": "primary", + "[插件demo]历史上的今天": { + "Group": "对话", "AsButton": True, - "Function": HotReload(语音助手) + "Function": HotReload(高阶功能模板函数) + }, + "精准翻译PDF论文": { + "Group": "学术", + "Color": "stop", + "AsButton": True, # 加入下拉菜单中 + "Function": HotReload(批量翻译PDF文档) + }, + "询问多个GPT模型": { + "Group": "对话", + "Color": "stop", + "AsButton": True, + "Function": HotReload(同时问询) + }, + "批量总结PDF文档": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(批量总结PDF文档) + }, + "谷歌学术检索助手(输入谷歌学术搜索页url)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(谷歌检索小助手) + }, + "理解PDF文档内容 (模仿ChatPDF)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(理解PDF文档内容标准文件输入) + }, + "英文Latex项目全文润色(输入路径或上传压缩包)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英文润色) + }, + "英文Latex项目全文纠错(输入路径或上传压缩包)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英文纠错) + }, + "中文Latex项目全文润色(输入路径或上传压缩包)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex中文润色) + }, + "Latex项目全文中译英(输入路径或上传压缩包)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex中译英) + }, + "Latex项目全文英译中(输入路径或上传压缩包)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Latex英译中) + }, + "批量Markdown中译英(输入路径或上传压缩包)": { + "Group": "编程", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(Markdown中译英) }, - "自动终端": { - "Color": "primary", - "AsButton": False, - "Function": HotReload(自动终端) - } } + + # -=--=- 尚未充分测试的实验性插件 & 需要额外依赖的插件 -=--=- + try: + from crazy_functions.下载arxiv论文翻译摘要 import 下载arxiv论文并翻译摘要 + function_plugins.update({ + "一键下载arxiv论文并翻译摘要(先在input输入编号,如1812.10695)": { + "Group": "学术", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(下载arxiv论文并翻译摘要) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.联网的ChatGPT import 连接网络回答问题 + function_plugins.update({ + "连接网络回答问题(输入问题后点击该插件,需要访问谷歌)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(连接网络回答问题) + } + }) + from crazy_functions.联网的ChatGPT_bing版 import 连接bing搜索回答问题 + function_plugins.update({ + "连接网络回答问题(中文Bing版,输入问题后点击该插件)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, # 加入下拉菜单中 + "Function": HotReload(连接bing搜索回答问题) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.解析项目源代码 import 解析任意code项目 + function_plugins.update({ + "解析项目源代码(手动指定和筛选源代码文件类型)": { + "Group": "编程", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "输入时用逗号隔开, *代表通配符, 加了^代表不匹配; 不输入代表全部匹配。例如: \"*.c, ^*.cpp, config.toml, ^*.toml\"", # 高级参数输入区的显示提示 + "Function": HotReload(解析任意code项目) + }, + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.询问多个大语言模型 import 同时问询_指定模型 + function_plugins.update({ + "询问多个GPT模型(手动指定询问哪些模型)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "支持任意数量的llm接口,用&符号分隔。例如chatglm&gpt-3.5-turbo&api2d-gpt-4", # 高级参数输入区的显示提示 + "Function": HotReload(同时问询_指定模型) + }, + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.图片生成 import 图片生成 + function_plugins.update({ + "图片生成(先切换模型到openai或api2d)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) + "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 + "Info": "图片生成 | 输入参数字符串,提供图像的内容", + "Function": HotReload(图片生成) + }, + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.总结音视频 import 总结音视频 + function_plugins.update({ + "批量总结音视频(输入路径或上传压缩包)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "调用openai api 使用whisper-1模型, 目前支持的格式:mp4, m4a, wav, mpga, mpeg, mp3。此处可以输入解析提示,例如:解析为简体中文(默认)。", + "Info": "批量总结音频或视频 | 输入参数为路径", + "Function": HotReload(总结音视频) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.数学动画生成manim import 动画生成 + function_plugins.update({ + "数学动画生成(Manim)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "Function": HotReload(动画生成) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言 + function_plugins.update({ + "Markdown翻译(手动指定语言)": { + "Group": "编程", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "请输入要翻译成哪种语言,默认为Chinese。", + "Function": HotReload(Markdown翻译指定语言) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.Langchain知识库 import 知识库问答 + function_plugins.update({ + "构建知识库(请先上传文件素材)": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "待注入的知识库名称id, 默认为default", + "Function": HotReload(知识库问答) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.Langchain知识库 import 读取知识库作答 + function_plugins.update({ + "知识库问答": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "待提取的知识库名称id, 默认为default, 您需要首先调用构建知识库", + "Function": HotReload(读取知识库作答) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.交互功能函数模板 import 交互功能模板函数 + function_plugins.update({ + "交互功能模板函数": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "Function": HotReload(交互功能模板函数) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.Latex输出PDF结果 import Latex英文纠错加PDF对比 + function_plugins.update({ + "Latex英文纠错+高亮修正位置 [需Latex]": { + "Group": "学术", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": "如果有必要, 请在此处追加更细致的矫错指令(使用英文)。", + "Function": HotReload(Latex英文纠错加PDF对比) + } + }) + from crazy_functions.Latex输出PDF结果 import Latex翻译中文并重新编译PDF + function_plugins.update({ + "Arixv论文精细翻译(输入arxivID)[需Latex]": { + "Group": "学术", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": + "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + + "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + + 'If the term "agent" is used in this section, it should be translated to "智能体". ', + "Function": HotReload(Latex翻译中文并重新编译PDF) + } + }) + function_plugins.update({ + "本地Latex论文精细翻译(上传Latex项目)[需Latex]": { + "Group": "学术", + "Color": "stop", + "AsButton": False, + "AdvancedArgs": True, + "ArgsReminder": + "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + + "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + + 'If the term "agent" is used in this section, it should be translated to "智能体". ', + "Function": HotReload(Latex翻译中文并重新编译PDF) + } + }) + except: + print('Load function plugin failed') + + try: + from toolbox import get_conf + ENABLE_AUDIO, = get_conf('ENABLE_AUDIO') + if ENABLE_AUDIO: + from crazy_functions.语音助手 import 语音助手 + function_plugins.update({ + "实时音频采集": { + "Group": "对话", + "Color": "stop", + "AsButton": True, + "Function": HotReload(语音助手) + } + }) + except: + print('Load function plugin failed') + + try: + from crazy_functions.虚空终端 import 自动终端 + function_plugins.update({ + "自动终端": { + "Group": "对话", + "Color": "stop", + "AsButton": False, + "Function": HotReload(自动终端) + } + }) + except: + print('Load function plugin failed') + # try: # from crazy_functions.chatglm微调工具 import 微调数据集生成 - # function_plugins['多功能'].update({ + # function_plugins.update({ # "黑盒模型学习: 微调数据集生成 (先上传数据集)": { - # "Color": "primary", + # "Color": "stop", # "AsButton": False, # "AdvancedArgs": True, # "ArgsReminder": "针对数据集输入(如 绿帽子*深蓝色衬衫*黑色运动裤)给出指令,例如您可以将以下命令复制到下方: --llm_to_learn=azure-gpt-3.5 --prompt_prefix='根据下面的服装类型提示,想象一个穿着者,对这个人外貌、身处的环境、内心世界、过去经历进行描写。要求:100字以内,用第二人称。' --system_prompt=''", @@ -370,3 +499,13 @@ def get_functions_多功能插件(): # except: # print('Load function plugin failed') + regroupped_functions = {} + for name, function_meta in function_plugins.items(): + if "Group" in function_meta: + groups = function_meta["Group"].split('|') + else: + groups = ['对话'] + for gruop in groups: + regroupped_functions[gruop] = regroupped_functions.get(gruop, {}) + regroupped_functions[gruop].update({name: function_meta}) + return regroupped_functions diff --git a/main.py b/main.py index ced4177..f21383b 100644 --- a/main.py +++ b/main.py @@ -89,14 +89,16 @@ def main(): if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue variant = functional[k]["Color"] if "Color" in functional[k] else "secondary" functional[k]["Button"] = gr.Button(k, variant=variant) + functional[k]["Button"].style(size="sm") with gr.Accordion("函数插件区", open=True, elem_id="plugin-panel") as area_crazy_fn: with gr.Row(): gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)") - plugin_dropdown = gr.Dropdown(choices=crazy_classification, label='选择插件分类', - value=DEFAULT_FN_GROUPS, - multiselect=True, interactive=True, - elem_classes='normal_mut_select' - ).style(container=False) + with gr.Row(elem_id="input-plugin-group"): + plugin_dropdown = gr.Dropdown(choices=crazy_classification, label='', + value=DEFAULT_FN_GROUPS, + multiselect=True, interactive=True, + elem_classes='normal_mut_select', + ).style(container=False) with gr.Row(): for role in crazy_fns_role: for k in crazy_fns_role[role]: @@ -138,7 +140,6 @@ def main(): max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",) checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区") md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False) - gr.Markdown(description) with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") as area_input_secondary: with gr.Row(): diff --git a/themes/common.css b/themes/common.css new file mode 100644 index 0000000..33bb4f0 --- /dev/null +++ b/themes/common.css @@ -0,0 +1,15 @@ +/* hide remove all button */ +.remove-all.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + visibility: hidden; +} + +/* hide selector border */ +#input-plugin-group .wrap.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + border: 0px; + box-shadow: none; +} + +/* hide selector label */ +#input-plugin-group .svelte-1gfkn6j { + visibility: hidden; +} diff --git a/themes/common.js b/themes/common.js index dcdeb50..a56672d 100644 --- a/themes/common.js +++ b/themes/common.js @@ -39,7 +39,10 @@ function get_elements() { const panel4 = document.querySelector('#interact-panel'); const panel5 = document.querySelector('#input-panel2'); const panel_active = document.querySelector('#state-panel'); - var panel_height_target = (20-panel_active.offsetHeight) + panel1.offsetHeight + panel2.offsetHeight + panel3.offsetHeight + panel4.offsetHeight + panel5.offsetHeight + 21; + // 25.3 是chatbot的label高度, 16 是右侧的gap + var panel_height_target = panel1.offsetHeight + panel2.offsetHeight + panel3.offsetHeight + panel4.offsetHeight + panel5.offsetHeight - 25.5 + 16*3; + // 禁止动态的state-panel高度影响 + panel_height_target = panel_height_target + (21-panel_active.offsetHeight) var panel_height_target = parseInt(panel_height_target); var chatbot_height = chatbot.style.height; var chatbot_height = parseInt(chatbot_height); diff --git a/themes/contrast.css b/themes/contrast.css new file mode 100644 index 0000000..54a1b2b --- /dev/null +++ b/themes/contrast.css @@ -0,0 +1,482 @@ +:root { + --body-text-color: #FFFFFF; + --link-text-color: #FFFFFF; + --link-text-color-active: #FFFFFF; + --link-text-color-hover: #FFFFFF; + --link-text-color-visited: #FFFFFF; + --body-text-color-subdued: #FFFFFF; + --block-info-text-color: #FFFFFF; + --block-label-text-color: #FFFFFF; + --block-title-text-color: #FFFFFF; + --checkbox-label-text-color: #FFFFFF; + --checkbox-label-text-color-selected: #FFFFFF; + --error-text-color: #FFFFFF; + --button-cancel-text-color: #FFFFFF; + --button-cancel-text-color-hover: #FFFFFF; + --button-primary-text-color: #FFFFFF; + --button-primary-text-color-hover: #FFFFFF; + --button-secondary-text-color: #FFFFFF; + --button-secondary-text-color-hover: #FFFFFF; + + + --border-bottom-right-radius: 0px; + --border-bottom-left-radius: 0px; + --border-top-right-radius: 0px; + --border-top-left-radius: 0px; + --block-radius: 0px; + --button-large-radius: 0px; + --button-small-radius: 0px; + --block-background-fill: #000000; + + --border-color-accent: #3cff00; + --border-color-primary: #3cff00; + --block-border-color: #3cff00; + --block-label-border-color: #3cff00; + --block-title-border-color: #3cff00; + --panel-border-color: #3cff00; + --checkbox-border-color: #3cff00; + --checkbox-border-color-focus: #3cff00; + --checkbox-border-color-hover: #3cff00; + --checkbox-border-color-selected: #3cff00; + --checkbox-label-border-color: #3cff00; + --checkbox-label-border-color-hover: #3cff00; + --error-border-color: #3cff00; + --input-border-color: #3cff00; + --input-border-color-focus: #3cff00; + --input-border-color-hover: #3cff00; + --table-border-color: #3cff00; + --button-cancel-border-color: #3cff00; + --button-cancel-border-color-hover: #3cff00; + --button-primary-border-color: #3cff00; + --button-primary-border-color-hover: #3cff00; + --button-secondary-border-color: #3cff00; + --button-secondary-border-color-hover: #3cff00; + + + --body-background-fill: #000000; + --background-fill-primary: #000000; + --background-fill-secondary: #000000; + --block-background-fill: #000000; + --block-label-background-fill: #000000; + --block-title-background-fill: #000000; + --panel-background-fill: #000000; + --chatbot-code-background-color: #000000; + --checkbox-background-color: #000000; + --checkbox-background-color-focus: #000000; + --checkbox-background-color-hover: #000000; + --checkbox-background-color-selected: #000000; + --checkbox-label-background-fill: #000000; + --checkbox-label-background-fill-hover: #000000; + --checkbox-label-background-fill-selected: #000000; + --error-background-fill: #000000; + --input-background-fill: #000000; + --input-background-fill-focus: #000000; + --input-background-fill-hover: #000000; + --stat-background-fill: #000000; + --table-even-background-fill: #000000; + --table-odd-background-fill: #000000; + --button-cancel-background-fill: #000000; + --button-cancel-background-fill-hover: #000000; + --button-primary-background-fill: #000000; + --button-primary-background-fill-hover: #000000; + --button-secondary-background-fill: #000000; + --button-secondary-background-fill-hover: #000000; + --color-accent-soft: #000000; +} + +.dark { + --body-text-color: #FFFFFF; + --link-text-color: #FFFFFF; + --link-text-color-active: #FFFFFF; + --link-text-color-hover: #FFFFFF; + --link-text-color-visited: #FFFFFF; + --body-text-color-subdued: #FFFFFF; + --block-info-text-color: #FFFFFF; + --block-label-text-color: #FFFFFF; + --block-title-text-color: #FFFFFF; + --checkbox-label-text-color: #FFFFFF; + --checkbox-label-text-color-selected: #FFFFFF; + --error-text-color: #FFFFFF; + --button-cancel-text-color: #FFFFFF; + --button-cancel-text-color-hover: #FFFFFF; + --button-primary-text-color: #FFFFFF; + --button-primary-text-color-hover: #FFFFFF; + --button-secondary-text-color: #FFFFFF; + --button-secondary-text-color-hover: #FFFFFF; + + + + --border-bottom-right-radius: 0px; + --border-bottom-left-radius: 0px; + --border-top-right-radius: 0px; + --border-top-left-radius: 0px; + --block-radius: 0px; + --button-large-radius: 0px; + --button-small-radius: 0px; + --block-background-fill: #000000; + + --border-color-accent: #3cff00; + --border-color-primary: #3cff00; + --block-border-color: #3cff00; + --block-label-border-color: #3cff00; + --block-title-border-color: #3cff00; + --panel-border-color: #3cff00; + --checkbox-border-color: #3cff00; + --checkbox-border-color-focus: #3cff00; + --checkbox-border-color-hover: #3cff00; + --checkbox-border-color-selected: #3cff00; + --checkbox-label-border-color: #3cff00; + --checkbox-label-border-color-hover: #3cff00; + --error-border-color: #3cff00; + --input-border-color: #3cff00; + --input-border-color-focus: #3cff00; + --input-border-color-hover: #3cff00; + --table-border-color: #3cff00; + --button-cancel-border-color: #3cff00; + --button-cancel-border-color-hover: #3cff00; + --button-primary-border-color: #3cff00; + --button-primary-border-color-hover: #3cff00; + --button-secondary-border-color: #3cff00; + --button-secondary-border-color-hover: #3cff00; + + + --body-background-fill: #000000; + --background-fill-primary: #000000; + --background-fill-secondary: #000000; + --block-background-fill: #000000; + --block-label-background-fill: #000000; + --block-title-background-fill: #000000; + --panel-background-fill: #000000; + --chatbot-code-background-color: #000000; + --checkbox-background-color: #000000; + --checkbox-background-color-focus: #000000; + --checkbox-background-color-hover: #000000; + --checkbox-background-color-selected: #000000; + --checkbox-label-background-fill: #000000; + --checkbox-label-background-fill-hover: #000000; + --checkbox-label-background-fill-selected: #000000; + --error-background-fill: #000000; + --input-background-fill: #000000; + --input-background-fill-focus: #000000; + --input-background-fill-hover: #000000; + --stat-background-fill: #000000; + --table-even-background-fill: #000000; + --table-odd-background-fill: #000000; + --button-cancel-background-fill: #000000; + --button-cancel-background-fill-hover: #000000; + --button-primary-background-fill: #000000; + --button-primary-background-fill-hover: #000000; + --button-secondary-background-fill: #000000; + --button-secondary-background-fill-hover: #000000; + --color-accent-soft: #000000; +} + + + +.block.svelte-mppz8v { + border-color: #3cff00; +} + +/* 插件下拉菜单 */ +#plugin-panel .wrap.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + box-shadow: var(--input-shadow); + border: var(--input-border-width) dashed var(--border-color-primary); + border-radius: 4px; +} + +#plugin-panel .dropdown-arrow.svelte-p5edak { + width: 50px; +} +#plugin-panel input.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + padding-left: 5px; +} +.root{ + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; + border-top-right-radius: 0px; + border-top-left-radius: 0px; +} + +/* 小按钮 */ +.sm.svelte-1ipelgc { + font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"; + --button-small-text-weight: 600; + --button-small-text-size: 16px; + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; + border-top-right-radius: 0px; + border-top-left-radius: 0px; +} + +#plugin-panel .sm.svelte-1ipelgc { + font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"; + --button-small-text-weight: 400; + --button-small-text-size: 14px; + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; + border-top-right-radius: 0px; + border-top-left-radius: 0px; +} + +.wrap-inner.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + padding: 0%; +} + +.markdown-body table { + margin: 1em 0; + border-collapse: collapse; + empty-cells: show; +} + +.markdown-body th, .markdown-body td { + border: 1.2px solid var(--border-color-primary); + padding: 5px; +} + +.markdown-body thead { + background-color: rgb(0, 0, 0); +} + +.markdown-body thead th { + padding: .5em .2em; +} + +.normal_mut_select .svelte-1gfkn6j { + float: left; + width: auto; + line-height: 260% !important; +} + +.markdown-body ol, .markdown-body ul { + padding-inline-start: 2em !important; +} + +/* chat box. */ +[class *= "message"] { + border-radius: var(--radius-xl) !important; + /* padding: var(--spacing-xl) !important; */ + /* font-size: var(--text-md) !important; */ + /* line-height: var(--line-md) !important; */ + /* min-height: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); */ + /* min-width: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); */ +} +[data-testid = "bot"] { + max-width: 95%; + /* width: auto !important; */ + border-bottom-left-radius: 0 !important; +} +[data-testid = "user"] { + max-width: 100%; + /* width: auto !important; */ + border-bottom-right-radius: 0 !important; +} + +/* linein code block. */ +.markdown-body code { + display: inline; + white-space: break-spaces; + border-radius: 6px; + margin: 0 2px 0 2px; + padding: .2em .4em .1em .4em; + background-color: rgba(0, 0, 0, 0.95); + color: #c9d1d9; +} + +.dark .markdown-body code { + display: inline; + white-space: break-spaces; + border-radius: 6px; + margin: 0 2px 0 2px; + padding: .2em .4em .1em .4em; + background-color: rgba(0,0,0,0.2); +} + +/* code block css */ +.markdown-body pre code { + display: block; + overflow: auto; + white-space: pre; + background-color: rgba(0, 0, 0, 0.95); + border-radius: 10px; + padding: 1em; + margin: 1em 2em 1em 0.5em; +} + +.dark .markdown-body pre code { + display: block; + overflow: auto; + white-space: pre; + background-color: rgba(0,0,0,0.2); + border-radius: 10px; + padding: 1em; + margin: 1em 2em 1em 0.5em; +} + +/* .mic-wrap.svelte-1thnwz { + +} */ +.block.svelte-mppz8v > .mic-wrap.svelte-1thnwz{ + justify-content: center; + display: flex; + padding: 0; + +} + +.codehilite .hll { background-color: #6e7681 } +.codehilite .c { color: #8b949e; font-style: italic } /* Comment */ +.codehilite .err { color: #f85149 } /* Error */ +.codehilite .esc { color: #c9d1d9 } /* Escape */ +.codehilite .g { color: #c9d1d9 } /* Generic */ +.codehilite .k { color: #ff7b72 } /* Keyword */ +.codehilite .l { color: #a5d6ff } /* Literal */ +.codehilite .n { color: #c9d1d9 } /* Name */ +.codehilite .o { color: #ff7b72; font-weight: bold } /* Operator */ +.codehilite .x { color: #c9d1d9 } /* Other */ +.codehilite .p { color: #c9d1d9 } /* Punctuation */ +.codehilite .ch { color: #8b949e; font-style: italic } /* Comment.Hashbang */ +.codehilite .cm { color: #8b949e; font-style: italic } /* Comment.Multiline */ +.codehilite .cp { color: #8b949e; font-weight: bold; font-style: italic } /* Comment.Preproc */ +.codehilite .cpf { color: #8b949e; font-style: italic } /* Comment.PreprocFile */ +.codehilite .c1 { color: #8b949e; font-style: italic } /* Comment.Single */ +.codehilite .cs { color: #8b949e; font-weight: bold; font-style: italic } /* Comment.Special */ +.codehilite .gd { color: #ffa198; background-color: #490202 } /* Generic.Deleted */ +.codehilite .ge { color: #c9d1d9; font-style: italic } /* Generic.Emph */ +.codehilite .gr { color: #ffa198 } /* Generic.Error */ +.codehilite .gh { color: #79c0ff; font-weight: bold } /* Generic.Heading */ +.codehilite .gi { color: #56d364; background-color: #0f5323 } /* Generic.Inserted */ +.codehilite .go { color: #8b949e } /* Generic.Output */ +.codehilite .gp { color: #8b949e } /* Generic.Prompt */ +.codehilite .gs { color: #c9d1d9; font-weight: bold } /* Generic.Strong */ +.codehilite .gu { color: #79c0ff } /* Generic.Subheading */ +.codehilite .gt { color: #ff7b72 } /* Generic.Traceback */ +.codehilite .g-Underline { color: #c9d1d9; text-decoration: underline } /* Generic.Underline */ +.codehilite .kc { color: #79c0ff } /* Keyword.Constant */ +.codehilite .kd { color: #ff7b72 } /* Keyword.Declaration */ +.codehilite .kn { color: #ff7b72 } /* Keyword.Namespace */ +.codehilite .kp { color: #79c0ff } /* Keyword.Pseudo */ +.codehilite .kr { color: #ff7b72 } /* Keyword.Reserved */ +.codehilite .kt { color: #ff7b72 } /* Keyword.Type */ +.codehilite .ld { color: #79c0ff } /* Literal.Date */ +.codehilite .m { color: #a5d6ff } /* Literal.Number */ +.codehilite .s { color: #a5d6ff } /* Literal.String */ +.codehilite .na { color: #c9d1d9 } /* Name.Attribute */ +.codehilite .nb { color: #c9d1d9 } /* Name.Builtin */ +.codehilite .nc { color: #f0883e; font-weight: bold } /* Name.Class */ +.codehilite .no { color: #79c0ff; font-weight: bold } /* Name.Constant */ +.codehilite .nd { color: #d2a8ff; font-weight: bold } /* Name.Decorator */ +.codehilite .ni { color: #ffa657 } /* Name.Entity */ +.codehilite .ne { color: #f0883e; font-weight: bold } /* Name.Exception */ +.codehilite .nf { color: #d2a8ff; font-weight: bold } /* Name.Function */ +.codehilite .nl { color: #79c0ff; font-weight: bold } /* Name.Label */ +.codehilite .nn { color: #ff7b72 } /* Name.Namespace */ +.codehilite .nx { color: #c9d1d9 } /* Name.Other */ +.codehilite .py { color: #79c0ff } /* Name.Property */ +.codehilite .nt { color: #7ee787 } /* Name.Tag */ +.codehilite .nv { color: #79c0ff } /* Name.Variable */ +.codehilite .ow { color: #ff7b72; font-weight: bold } /* Operator.Word */ +.codehilite .pm { color: #c9d1d9 } /* Punctuation.Marker */ +.codehilite .w { color: #6e7681 } /* Text.Whitespace */ +.codehilite .mb { color: #a5d6ff } /* Literal.Number.Bin */ +.codehilite .mf { color: #a5d6ff } /* Literal.Number.Float */ +.codehilite .mh { color: #a5d6ff } /* Literal.Number.Hex */ +.codehilite .mi { color: #a5d6ff } /* Literal.Number.Integer */ +.codehilite .mo { color: #a5d6ff } /* Literal.Number.Oct */ +.codehilite .sa { color: #79c0ff } /* Literal.String.Affix */ +.codehilite .sb { color: #a5d6ff } /* Literal.String.Backtick */ +.codehilite .sc { color: #a5d6ff } /* Literal.String.Char */ +.codehilite .dl { color: #79c0ff } /* Literal.String.Delimiter */ +.codehilite .sd { color: #a5d6ff } /* Literal.String.Doc */ +.codehilite .s2 { color: #a5d6ff } /* Literal.String.Double */ +.codehilite .se { color: #79c0ff } /* Literal.String.Escape */ +.codehilite .sh { color: #79c0ff } /* Literal.String.Heredoc */ +.codehilite .si { color: #a5d6ff } /* Literal.String.Interpol */ +.codehilite .sx { color: #a5d6ff } /* Literal.String.Other */ +.codehilite .sr { color: #79c0ff } /* Literal.String.Regex */ +.codehilite .s1 { color: #a5d6ff } /* Literal.String.Single */ +.codehilite .ss { color: #a5d6ff } /* Literal.String.Symbol */ +.codehilite .bp { color: #c9d1d9 } /* Name.Builtin.Pseudo */ +.codehilite .fm { color: #d2a8ff; font-weight: bold } /* Name.Function.Magic */ +.codehilite .vc { color: #79c0ff } /* Name.Variable.Class */ +.codehilite .vg { color: #79c0ff } /* Name.Variable.Global */ +.codehilite .vi { color: #79c0ff } /* Name.Variable.Instance */ +.codehilite .vm { color: #79c0ff } /* Name.Variable.Magic */ +.codehilite .il { color: #a5d6ff } /* Literal.Number.Integer.Long */ + +.dark .codehilite .hll { background-color: #2C3B41 } +.dark .codehilite .c { color: #79d618; font-style: italic } /* Comment */ +.dark .codehilite .err { color: #FF5370 } /* Error */ +.dark .codehilite .esc { color: #89DDFF } /* Escape */ +.dark .codehilite .g { color: #EEFFFF } /* Generic */ +.dark .codehilite .k { color: #BB80B3 } /* Keyword */ +.dark .codehilite .l { color: #C3E88D } /* Literal */ +.dark .codehilite .n { color: #EEFFFF } /* Name */ +.dark .codehilite .o { color: #89DDFF } /* Operator */ +.dark .codehilite .p { color: #89DDFF } /* Punctuation */ +.dark .codehilite .ch { color: #79d618; font-style: italic } /* Comment.Hashbang */ +.dark .codehilite .cm { color: #79d618; font-style: italic } /* Comment.Multiline */ +.dark .codehilite .cp { color: #79d618; font-style: italic } /* Comment.Preproc */ +.dark .codehilite .cpf { color: #79d618; font-style: italic } /* Comment.PreprocFile */ +.dark .codehilite .c1 { color: #79d618; font-style: italic } /* Comment.Single */ +.dark .codehilite .cs { color: #79d618; font-style: italic } /* Comment.Special */ +.dark .codehilite .gd { color: #FF5370 } /* Generic.Deleted */ +.dark .codehilite .ge { color: #89DDFF } /* Generic.Emph */ +.dark .codehilite .gr { color: #FF5370 } /* Generic.Error */ +.dark .codehilite .gh { color: #C3E88D } /* Generic.Heading */ +.dark .codehilite .gi { color: #C3E88D } /* Generic.Inserted */ +.dark .codehilite .go { color: #79d618 } /* Generic.Output */ +.dark .codehilite .gp { color: #FFCB6B } /* Generic.Prompt */ +.dark .codehilite .gs { color: #FF5370 } /* Generic.Strong */ +.dark .codehilite .gu { color: #89DDFF } /* Generic.Subheading */ +.dark .codehilite .gt { color: #FF5370 } /* Generic.Traceback */ +.dark .codehilite .kc { color: #89DDFF } /* Keyword.Constant */ +.dark .codehilite .kd { color: #BB80B3 } /* Keyword.Declaration */ +.dark .codehilite .kn { color: #89DDFF; font-style: italic } /* Keyword.Namespace */ +.dark .codehilite .kp { color: #89DDFF } /* Keyword.Pseudo */ +.dark .codehilite .kr { color: #BB80B3 } /* Keyword.Reserved */ +.dark .codehilite .kt { color: #BB80B3 } /* Keyword.Type */ +.dark .codehilite .ld { color: #C3E88D } /* Literal.Date */ +.dark .codehilite .m { color: #F78C6C } /* Literal.Number */ +.dark .codehilite .s { color: #C3E88D } /* Literal.String */ +.dark .codehilite .na { color: #BB80B3 } /* Name.Attribute */ +.dark .codehilite .nb { color: #82AAFF } /* Name.Builtin */ +.dark .codehilite .nc { color: #FFCB6B } /* Name.Class */ +.dark .codehilite .no { color: #EEFFFF } /* Name.Constant */ +.dark .codehilite .nd { color: #82AAFF } /* Name.Decorator */ +.dark .codehilite .ni { color: #89DDFF } /* Name.Entity */ +.dark .codehilite .ne { color: #FFCB6B } /* Name.Exception */ +.dark .codehilite .nf { color: #82AAFF } /* Name.Function */ +.dark .codehilite .nl { color: #82AAFF } /* Name.Label */ +.dark .codehilite .nn { color: #FFCB6B } /* Name.Namespace */ +.dark .codehilite .nx { color: #EEFFFF } /* Name.Other */ +.dark .codehilite .py { color: #FFCB6B } /* Name.Property */ +.dark .codehilite .nt { color: #FF5370 } /* Name.Tag */ +.dark .codehilite .nv { color: #89DDFF } /* Name.Variable */ +.dark .codehilite .ow { color: #89DDFF; font-style: italic } /* Operator.Word */ +.dark .codehilite .pm { color: #89DDFF } /* Punctuation.Marker */ +.dark .codehilite .w { color: #EEFFFF } /* Text.Whitespace */ +.dark .codehilite .mb { color: #F78C6C } /* Literal.Number.Bin */ +.dark .codehilite .mf { color: #F78C6C } /* Literal.Number.Float */ +.dark .codehilite .mh { color: #F78C6C } /* Literal.Number.Hex */ +.dark .codehilite .mi { color: #F78C6C } /* Literal.Number.Integer */ +.dark .codehilite .mo { color: #F78C6C } /* Literal.Number.Oct */ +.dark .codehilite .sa { color: #BB80B3 } /* Literal.String.Affix */ +.dark .codehilite .sb { color: #C3E88D } /* Literal.String.Backtick */ +.dark .codehilite .sc { color: #C3E88D } /* Literal.String.Char */ +.dark .codehilite .dl { color: #EEFFFF } /* Literal.String.Delimiter */ +.dark .codehilite .sd { color: #79d618; font-style: italic } /* Literal.String.Doc */ +.dark .codehilite .s2 { color: #C3E88D } /* Literal.String.Double */ +.dark .codehilite .se { color: #EEFFFF } /* Literal.String.Escape */ +.dark .codehilite .sh { color: #C3E88D } /* Literal.String.Heredoc */ +.dark .codehilite .si { color: #89DDFF } /* Literal.String.Interpol */ +.dark .codehilite .sx { color: #C3E88D } /* Literal.String.Other */ +.dark .codehilite .sr { color: #89DDFF } /* Literal.String.Regex */ +.dark .codehilite .s1 { color: #C3E88D } /* Literal.String.Single */ +.dark .codehilite .ss { color: #89DDFF } /* Literal.String.Symbol */ +.dark .codehilite .bp { color: #89DDFF } /* Name.Builtin.Pseudo */ +.dark .codehilite .fm { color: #82AAFF } /* Name.Function.Magic */ +.dark .codehilite .vc { color: #89DDFF } /* Name.Variable.Class */ +.dark .codehilite .vg { color: #89DDFF } /* Name.Variable.Global */ +.dark .codehilite .vi { color: #89DDFF } /* Name.Variable.Instance */ +.dark .codehilite .vm { color: #82AAFF } /* Name.Variable.Magic */ +.dark .codehilite .il { color: #F78C6C } /* Literal.Number.Integer.Long */ + diff --git a/themes/contrast.py b/themes/contrast.py new file mode 100644 index 0000000..fd4ef04 --- /dev/null +++ b/themes/contrast.py @@ -0,0 +1,88 @@ +import gradio as gr +from toolbox import get_conf +CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT') + +def adjust_theme(): + + try: + color_er = gr.themes.utils.colors.fuchsia + set_theme = gr.themes.Default( + primary_hue=gr.themes.utils.colors.orange, + neutral_hue=gr.themes.utils.colors.gray, + font=["Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"], + font_mono=["ui-monospace", "Consolas", "monospace"]) + set_theme.set( + # Colors + input_background_fill_dark="*neutral_800", + # Transition + button_transition="none", + # Shadows + button_shadow="*shadow_drop", + button_shadow_hover="*shadow_drop_lg", + button_shadow_active="*shadow_inset", + input_shadow="0 0 0 *shadow_spread transparent, *shadow_inset", + input_shadow_focus="0 0 0 *shadow_spread *secondary_50, *shadow_inset", + input_shadow_focus_dark="0 0 0 *shadow_spread *neutral_700, *shadow_inset", + checkbox_label_shadow="*shadow_drop", + block_shadow="*shadow_drop", + form_gap_width="1px", + # Button borders + input_border_width="1px", + input_background_fill="white", + # Gradients + stat_background_fill="linear-gradient(to right, *primary_400, *primary_200)", + stat_background_fill_dark="linear-gradient(to right, *primary_400, *primary_600)", + error_background_fill=f"linear-gradient(to right, {color_er.c100}, *background_fill_secondary)", + error_background_fill_dark="*background_fill_primary", + checkbox_label_background_fill="linear-gradient(to top, *neutral_50, white)", + checkbox_label_background_fill_dark="linear-gradient(to top, *neutral_900, *neutral_800)", + checkbox_label_background_fill_hover="linear-gradient(to top, *neutral_100, white)", + checkbox_label_background_fill_hover_dark="linear-gradient(to top, *neutral_900, *neutral_800)", + button_primary_background_fill="linear-gradient(to bottom right, *primary_100, *primary_300)", + button_primary_background_fill_dark="linear-gradient(to bottom right, *primary_500, *primary_600)", + button_primary_background_fill_hover="linear-gradient(to bottom right, *primary_100, *primary_200)", + button_primary_background_fill_hover_dark="linear-gradient(to bottom right, *primary_500, *primary_500)", + button_primary_border_color_dark="*primary_500", + button_secondary_background_fill="linear-gradient(to bottom right, *neutral_100, *neutral_200)", + button_secondary_background_fill_dark="linear-gradient(to bottom right, *neutral_600, *neutral_700)", + button_secondary_background_fill_hover="linear-gradient(to bottom right, *neutral_100, *neutral_100)", + button_secondary_background_fill_hover_dark="linear-gradient(to bottom right, *neutral_600, *neutral_600)", + button_cancel_background_fill=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c200})", + button_cancel_background_fill_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c700})", + button_cancel_background_fill_hover=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c100})", + button_cancel_background_fill_hover_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c600})", + button_cancel_border_color=color_er.c200, + button_cancel_border_color_dark=color_er.c600, + button_cancel_text_color=color_er.c600, + button_cancel_text_color_dark="white", + ) + + if LAYOUT=="TOP-DOWN": + js = "" + else: + with open('themes/common.js', 'r', encoding='utf8') as f: + js = f"" + + # 添加一个萌萌的看板娘 + if ADD_WAIFU: + js += """ + + + + """ + gradio_original_template_fn = gr.routes.templates.TemplateResponse + def gradio_new_template_fn(*args, **kwargs): + res = gradio_original_template_fn(*args, **kwargs) + res.body = res.body.replace(b'', f'{js}'.encode("utf8")) + res.init_headers() + return res + gr.routes.templates.TemplateResponse = gradio_new_template_fn # override gradio template + except: + set_theme = None + print('gradio版本较旧, 不能自定义字体和颜色') + return set_theme + +with open("themes/contrast.css", "r", encoding="utf-8") as f: + advanced_css = f.read() +with open("themes/common.css", "r", encoding="utf-8") as f: + advanced_css += f.read() diff --git a/themes/default.css b/themes/default.css index 5fba4af..a35cd1d 100644 --- a/themes/default.css +++ b/themes/default.css @@ -1,3 +1,46 @@ +.dark { + --background-fill-primary: #050810; + --body-background-fill: var(--background-fill-primary); +} +/* 插件下拉菜单 */ +#plugin-panel .wrap.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + box-shadow: var(--input-shadow); + border: var(--input-border-width) dashed var(--border-color-primary); + border-radius: 4px; +} + +#plugin-panel .dropdown-arrow.svelte-p5edak { + width: 50px; +} +#plugin-panel input.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + padding-left: 5px; +} + +/* 小按钮 */ +.sm.svelte-1ipelgc { + font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"; + --button-small-text-weight: 600; + --button-small-text-size: 16px; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + border-top-right-radius: 6px; + border-top-left-radius: 6px; +} + +#plugin-panel .sm.svelte-1ipelgc { + font-family: "Microsoft YaHei UI", "Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"; + --button-small-text-weight: 400; + --button-small-text-size: 14px; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + border-top-right-radius: 6px; + border-top-left-radius: 6px; +} + +.wrap-inner.svelte-aqlk7e.svelte-aqlk7e.svelte-aqlk7e { + padding: 0%; +} + .markdown-body table { margin: 1em 0; border-collapse: collapse; @@ -16,6 +59,7 @@ .markdown-body thead th { padding: .5em .2em; } + .normal_mut_select .svelte-1gfkn6j { float: left; width: auto; diff --git a/themes/default.py b/themes/default.py index 4efde5b..2611e7a 100644 --- a/themes/default.py +++ b/themes/default.py @@ -9,7 +9,7 @@ def adjust_theme(): set_theme = gr.themes.Default( primary_hue=gr.themes.utils.colors.orange, neutral_hue=gr.themes.utils.colors.gray, - font=["sans-serif", "Microsoft YaHei", "ui-sans-serif", "system-ui"], + font=["Helvetica", "Microsoft YaHei", "ui-sans-serif", "sans-serif", "system-ui"], font_mono=["ui-monospace", "Consolas", "monospace"]) set_theme.set( # Colors @@ -83,4 +83,6 @@ def adjust_theme(): return set_theme with open("themes/default.css", "r", encoding="utf-8") as f: - advanced_css = f.read() \ No newline at end of file + advanced_css = f.read() +with open("themes/common.css", "r", encoding="utf-8") as f: + advanced_css += f.read() diff --git a/themes/green.py b/themes/green.py index e14f4b6..5aa9e8b 100644 --- a/themes/green.py +++ b/themes/green.py @@ -106,3 +106,5 @@ def adjust_theme(): with open("themes/green.css", "r", encoding="utf-8") as f: advanced_css = f.read() +with open("themes/common.css", "r", encoding="utf-8") as f: + advanced_css += f.read() diff --git a/themes/theme.py b/themes/theme.py index c08d9bb..5cba541 100644 --- a/themes/theme.py +++ b/themes/theme.py @@ -5,6 +5,9 @@ THEME, = get_conf('THEME') if THEME == 'Chuanhu-Small-and-Beautiful': from .green import adjust_theme, advanced_css theme_declaration = "

[Chuanhu-Small-and-Beautiful主题]

" +elif THEME == 'High-Contrast': + from .contrast import adjust_theme, advanced_css + theme_declaration = "" else: from .default import adjust_theme, advanced_css theme_declaration = "" From b31abbcad352cf773a7b512d129f3be9f97ba2ad Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 31 Aug 2023 15:59:19 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=BD=92=E5=B1=9E=E5=A4=9A=E4=B8=AAGroup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functional.py | 30 ++++++++---- main.py | 110 ++++++++++++++++++-------------------------- 2 files changed, 64 insertions(+), 76 deletions(-) diff --git a/crazy_functional.py b/crazy_functional.py index ee3ed99..e51dec0 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -168,7 +168,7 @@ def get_crazy_functions(): "Function": HotReload(对话历史存档) }, "[多线程Demo]解析此项目本身(源码自译解)": { - "Group": "对话", + "Group": "对话|编程", "AsButton": False, # 加入下拉菜单中 "Function": HotReload(解析项目本身) }, @@ -499,13 +499,23 @@ def get_crazy_functions(): # except: # print('Load function plugin failed') - regroupped_functions = {} + + + """ + 设置默认值: + - 默认 Group = 对话 + - 默认 AsButton = True + - 默认 AdvancedArgs = False + - 默认 Color = secondary + """ for name, function_meta in function_plugins.items(): - if "Group" in function_meta: - groups = function_meta["Group"].split('|') - else: - groups = ['对话'] - for gruop in groups: - regroupped_functions[gruop] = regroupped_functions.get(gruop, {}) - regroupped_functions[gruop].update({name: function_meta}) - return regroupped_functions + if "Group" not in function_meta: + function_plugins[name]["Group"] = '对话' + if "AsButton" not in function_meta: + function_plugins[name]["AsButton"] = True + if "AdvancedArgs" not in function_meta: + function_plugins[name]["AdvancedArgs"] = False + if "Color" not in function_meta: + function_plugins[name]["Color"] = 'secondary' + + return function_plugins diff --git a/main.py b/main.py index f21383b..50028c2 100644 --- a/main.py +++ b/main.py @@ -5,19 +5,20 @@ def main(): # if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt" from request_llm.bridge_all import predict from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith + # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 - proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = \ - get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT') + proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION') + CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = get_conf('CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT') ENABLE_AUDIO, AUTO_CLEAR_TXT = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT') + # 如果WEB_PORT是-1, 则随机选取WEB端口 PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT - if not AUTHENTICATION: AUTHENTICATION = None - from check_proxy import get_current_version from themes.theme import adjust_theme, advanced_css, theme_declaration initial_prompt = "Serve me as a writing and programming assistant." title_html = f"

GPT 学术优化 {get_current_version()}

{theme_declaration}" - description = """代码开源和更新[地址🚀](https://github.com/binary-husky/chatgpt_academic),感谢热情的[开发者们❤️](https://github.com/binary-husky/chatgpt_academic/graphs/contributors)""" + description = "代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic)," + description += "感谢热情的[开发者们❤️](https://github.com/binary-husky/gpt_academic/graphs/contributors)" # 问询记录, python 版本建议3.9+(越新越好) import logging, uuid @@ -35,12 +36,9 @@ def main(): # 高级函数插件 from crazy_functional import get_crazy_functions DEFAULT_FN_GROUPS, = get_conf('DEFAULT_FN_GROUPS') - crazy_fns_role = get_crazy_functions() - crazy_classification = [i for i in crazy_fns_role] - crazy_fns = {} - for role in crazy_fns_role: - for k in crazy_fns_role[role]: - crazy_fns[k] = crazy_fns_role[role][k] + plugins = get_crazy_functions() + all_plugin_groups = list(set([g for _, plugin in plugins.items() for g in plugin['Group'].split('|')])) + match_group = lambda tags, groups: any([g in groups for g in tags.split('|')]) # 处理markdown文本格式的转变 gr.Chatbot.postprocess = format_io @@ -94,35 +92,21 @@ def main(): with gr.Row(): gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)") with gr.Row(elem_id="input-plugin-group"): - plugin_dropdown = gr.Dropdown(choices=crazy_classification, label='', - value=DEFAULT_FN_GROUPS, - multiselect=True, interactive=True, - elem_classes='normal_mut_select', - ).style(container=False) + plugin_group_sel = gr.Dropdown(choices=all_plugin_groups, label='', show_label=False, value=DEFAULT_FN_GROUPS, + multiselect=True, interactive=True, elem_classes='normal_mut_select').style(container=False) with gr.Row(): - for role in crazy_fns_role: - for k in crazy_fns_role[role]: - if not crazy_fns_role[role][k].get("AsButton", True): continue - if role not in DEFAULT_FN_GROUPS: - variant = crazy_fns_role[role][k]["Color"] if "Color" in crazy_fns_role[role][ - k] else "secondary" - crazy_fns_role[role][k]['Button'] = gr.Button(k, variant=variant, - visible=False).style(size="sm") - else: - variant = crazy_fns[k]["Color"] if "Color" in crazy_fns_role[role][ - k] else "secondary" - crazy_fns_role[role][k]['Button'] = gr.Button(k, variant=variant, - visible=True).style(size="sm") + for k, plugin in plugins.items(): + if not plugin.get("AsButton", True): continue + visible = True if match_group(plugin['Group'], DEFAULT_FN_GROUPS) else False + variant = plugins[k]["Color"] if "Color" in plugin else "secondary" + plugin['Button'] = plugins[k]['Button'] = gr.Button(k, variant=variant, visible=visible).style(size="sm") with gr.Row(): with gr.Accordion("更多函数插件", open=True): dropdown_fn_list = [] - for role in crazy_fns_role: - if role in DEFAULT_FN_GROUPS: - for k in crazy_fns_role[role]: - if not crazy_fns_role[role][k].get("AsButton", True): - dropdown_fn_list.append(k) - elif crazy_fns_role[role][k].get('AdvancedArgs', False): - dropdown_fn_list.append(k) + for k, plugin in plugins.items(): + if not match_group(plugin['Group'], DEFAULT_FN_GROUPS): continue + if not plugin.get("AsButton", True): dropdown_fn_list.append(k) # 排除已经是按钮的插件 + elif plugin.get('AdvancedArgs', False): dropdown_fn_list.append(k) # 对于需要高级参数的插件,亦在下拉菜单中显示 with gr.Row(): dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="", show_label=False).style(container=False) with gr.Row(): @@ -150,6 +134,7 @@ def main(): resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn2.style(size="sm") stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn2.style(size="sm") clearBtn2 = gr.Button("清除", variant="secondary", visible=False); clearBtn2.style(size="sm") + # 功能区显示开关与功能区的互动 def fn_area_visibility(a): ret = {} @@ -189,17 +174,17 @@ def main(): # 文件上传区,接收文件后与chatbot的互动 file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes], [chatbot, txt, txt2]) # 函数插件-固定按钮区 - for k in crazy_fns: - if not crazy_fns[k].get("AsButton", True): continue - click_handle = crazy_fns[k]["Button"].click(ArgsGeneralWrapper(crazy_fns[k]["Function"]), [*input_combo, gr.State(PORT)], output_combo) + for k in plugins: + if not plugins[k].get("AsButton", True): continue + click_handle = plugins[k]["Button"].click(ArgsGeneralWrapper(plugins[k]["Function"]), [*input_combo, gr.State(PORT)], output_combo) click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot]) cancel_handles.append(click_handle) # 函数插件-下拉菜单与随变按钮的互动 def on_dropdown_changed(k): - variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary" + variant = plugins[k]["Color"] if "Color" in plugins[k] else "secondary" ret = {switchy_bt: gr.update(value=k, variant=variant)} - if crazy_fns[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区 - ret.update({plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + crazy_fns[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))}) + if plugins[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区 + ret.update({plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + plugins[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))}) else: ret.update({plugin_advanced_arg: gr.update(visible=False, label=f"插件[{k}]不需要高级参数。")}) return ret @@ -210,35 +195,26 @@ def main(): # 随变按钮的回调函数注册 def route(request: gr.Request, k, *args, **kwargs): if k in [r"打开插件列表", r"请先从插件列表中选择"]: return - yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(request, *args, **kwargs) + yield from ArgsGeneralWrapper(plugins[k]["Function"])(request, *args, **kwargs) click_handle = switchy_bt.click(route,[switchy_bt, *input_combo, gr.State(PORT)], output_combo) click_handle.then(on_report_generated, [cookies, file_upload, chatbot], [cookies, file_upload, chatbot]) cancel_handles.append(click_handle) # 终止按钮的回调函数注册 stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) - fn_btn_dict = {crazy_fns_role[role][k]['Button']: {role: k} for role in crazy_fns_role for k in crazy_fns_role[role] if crazy_fns_role[role][k].get('Button')} - def show_plugin_btn(plu_list): - new_btn_list = [] + plugins_as_btn = {name:plugin for name, plugin in plugins.items() if plugin.get('Button', None)} + def on_group_change(group_list): + btn_list = [] fns_list = [] - if not plu_list: - return [*[fns.update(visible=False) for fns in fn_btn_dict], gr.Dropdown.update(choices=[])] - else: - for fns in fn_btn_dict: - if list(fn_btn_dict[fns].keys())[0] in plu_list: - new_btn_list.append(fns.update(visible=True)) - else: - new_btn_list.append(fns.update(visible=False)) - for role in crazy_fns_role: - if role in plu_list: - for k in crazy_fns_role[role]: - if not crazy_fns_role[role][k].get("AsButton", True): - fns_list.append(k) - elif crazy_fns_role[role][k].get('AdvancedArgs', False): - fns_list.append(k) - return [*new_btn_list, gr.Dropdown.update(choices=fns_list)] - plugin_dropdown.select(fn=show_plugin_btn, inputs=[plugin_dropdown], - outputs=[*fn_btn_dict.keys(), dropdown]) + if not group_list: # 处理特殊情况:没有选择任何插件组 + return [*[plugin['Button'].update(visible=False) for _, plugin in plugins_as_btn.items()], gr.Dropdown.update(choices=[])] + for k, plugin in plugins.items(): + if plugin.get("AsButton", True): + btn_list.append(plugin['Button'].update(visible=match_group(plugin['Group'], group_list))) # 刷新按钮 + if plugin.get('AdvancedArgs', False): dropdown_fn_list.append(k) # 对于需要高级参数的插件,亦在下拉菜单中显示 + elif match_group(plugin['Group'], group_list): fns_list.append(k) # 刷新下拉列表 + return [*btn_list, gr.Dropdown.update(choices=fns_list)] + plugin_group_sel.select(fn=on_group_change, inputs=[plugin_group_sel], outputs=[*[plugin['Button'] for name, plugin in plugins_as_btn.items()], dropdown]) if ENABLE_AUDIO: from crazy_functions.live_audio.audio_io import RealtimeAudioDistribution rad = RealtimeAudioDistribution() @@ -270,8 +246,10 @@ def main(): auto_opentab_delay() demo.queue(concurrency_count=CONCURRENT_COUNT).launch( - server_name="0.0.0.0", server_port=PORT, - favicon_path="docs/logo.png", auth=AUTHENTICATION, + server_name="0.0.0.0", + server_port=PORT, + favicon_path="docs/logo.png", + auth=AUTHENTICATION if len(AUTHENTICATION) != 0 else None, blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile"]) # 如果需要在二级路径下运行 From b69140307bccaa486e8d6449528b99e55ad5aef8 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 31 Aug 2023 16:24:00 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=A1=86=E5=AF=B9=E9=BD=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/common.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/themes/common.js b/themes/common.js index a56672d..7733c7b 100644 --- a/themes/common.js +++ b/themes/common.js @@ -1,6 +1,6 @@ function ChatBotHeight() { function update_height(){ - var { panel_height_target, chatbot_height, chatbot } = get_elements(); + var { panel_height_target, chatbot_height, chatbot } = get_elements(true); if (panel_height_target!=chatbot_height) { var pixelString = panel_height_target.toString() + 'px'; @@ -28,21 +28,24 @@ function ChatBotHeight() { }, 50); // 每100毫秒执行一次 } -function get_elements() { +function get_elements(consider_state_panel=false) { var chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq'); if (!chatbot) { chatbot = document.querySelector('#gpt-chatbot'); } - const panel1 = document.querySelector('#input-panel'); - const panel2 = document.querySelector('#basic-panel'); - const panel3 = document.querySelector('#plugin-panel'); - const panel4 = document.querySelector('#interact-panel'); - const panel5 = document.querySelector('#input-panel2'); - const panel_active = document.querySelector('#state-panel'); - // 25.3 是chatbot的label高度, 16 是右侧的gap - var panel_height_target = panel1.offsetHeight + panel2.offsetHeight + panel3.offsetHeight + panel4.offsetHeight + panel5.offsetHeight - 25.5 + 16*3; + const panel1 = document.querySelector('#input-panel').getBoundingClientRect(); + const panel2 = document.querySelector('#basic-panel').getBoundingClientRect() + const panel3 = document.querySelector('#plugin-panel').getBoundingClientRect(); + const panel4 = document.querySelector('#interact-panel').getBoundingClientRect(); + const panel5 = document.querySelector('#input-panel2').getBoundingClientRect(); + const panel_active = document.querySelector('#state-panel').getBoundingClientRect(); + if (consider_state_panel || panel_active.height < 25){ + document.state_panel_height = panel_active.height; + } + // 25 是chatbot的label高度, 16 是右侧的gap + var panel_height_target = panel1.height + panel2.height + panel3.height + panel4.height + panel5.height - 25 + 16*3; // 禁止动态的state-panel高度影响 - panel_height_target = panel_height_target + (21-panel_active.offsetHeight) + panel_height_target = panel_height_target + (document.state_panel_height-panel_active.height) var panel_height_target = parseInt(panel_height_target); var chatbot_height = chatbot.style.height; var chatbot_height = parseInt(chatbot_height); From 8b0905c076d23336ef2839c54626756b44911bd9 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 31 Aug 2023 18:04:31 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=8F=90=E9=AB=98=E8=99=9A=E7=A9=BA?= =?UTF-8?q?=E7=BB=88=E7=AB=AF=E7=9A=84=E6=88=90=E5=8A=9F=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functional.py | 30 ++++++++++++++++--- crazy_functions/json_fns/pydantic_io.py | 18 +++++++++--- crazy_functions/vt_fns/vt_call_plugin.py | 37 +++++++++++++++++------- crazy_functions/虚空终端.py | 37 +++++++++--------------- tests/test_plugins.py | 4 +-- version | 4 +-- 6 files changed, 83 insertions(+), 47 deletions(-) diff --git a/crazy_functional.py b/crazy_functional.py index e51dec0..1388e34 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -140,6 +140,7 @@ def get_crazy_functions(): "Group": "学术", "Color": "stop", "AsButton": True, + "Info": "读取Tex论文并写摘要 | 输入参数为路径", "Function": HotReload(读文章写摘要) }, "翻译README或MD": { @@ -153,12 +154,14 @@ def get_crazy_functions(): "Group": "编程", "Color": "stop", "AsButton": False, + "Info": "将Markdown或README翻译为中文 | 输入参数为路径或URL", "Function": HotReload(Markdown英译中) }, "批量生成函数注释": { "Group": "编程", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "批量生成函数的注释 | 输入参数为路径", "Function": HotReload(批量生成函数注释) }, "保存当前的对话": { @@ -170,17 +173,20 @@ def get_crazy_functions(): "[多线程Demo]解析此项目本身(源码自译解)": { "Group": "对话|编程", "AsButton": False, # 加入下拉菜单中 + "Info": "多线程解析并翻译此项目的源码 | 不需要输入参数", "Function": HotReload(解析项目本身) }, "[插件demo]历史上的今天": { "Group": "对话", "AsButton": True, + "Info": "查看历史上的今天事件 | 不需要输入参数", "Function": HotReload(高阶功能模板函数) }, "精准翻译PDF论文": { "Group": "学术", "Color": "stop", - "AsButton": True, # 加入下拉菜单中 + "AsButton": True, + "Info": "精准翻译PDF论文为中文 | 输入参数为路径", "Function": HotReload(批量翻译PDF文档) }, "询问多个GPT模型": { @@ -193,54 +199,63 @@ def get_crazy_functions(): "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "批量总结PDF文档的内容 | 输入参数为路径", "Function": HotReload(批量总结PDF文档) }, "谷歌学术检索助手(输入谷歌学术搜索页url)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "使用谷歌学术检索助手搜索指定URL的结果 | 输入参数为谷歌学术搜索页的URL", "Function": HotReload(谷歌检索小助手) }, "理解PDF文档内容 (模仿ChatPDF)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "理解PDF文档的内容并进行回答 | 输入参数为路径", "Function": HotReload(理解PDF文档内容标准文件输入) }, "英文Latex项目全文润色(输入路径或上传压缩包)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "对英文Latex项目全文进行润色处理 | 输入参数为路径或上传压缩包", "Function": HotReload(Latex英文润色) }, "英文Latex项目全文纠错(输入路径或上传压缩包)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "对英文Latex项目全文进行纠错处理 | 输入参数为路径或上传压缩包", "Function": HotReload(Latex英文纠错) }, "中文Latex项目全文润色(输入路径或上传压缩包)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "对中文Latex项目全文进行润色处理 | 输入参数为路径或上传压缩包", "Function": HotReload(Latex中文润色) }, "Latex项目全文中译英(输入路径或上传压缩包)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "对Latex项目全文进行中译英处理 | 输入参数为路径或上传压缩包", "Function": HotReload(Latex中译英) }, "Latex项目全文英译中(输入路径或上传压缩包)": { "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "对Latex项目全文进行英译中处理 | 输入参数为路径或上传压缩包", "Function": HotReload(Latex英译中) }, "批量Markdown中译英(输入路径或上传压缩包)": { "Group": "编程", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "批量将Markdown文件中文翻译为英文 | 输入参数为路径或上传压缩包", "Function": HotReload(Markdown中译英) }, } @@ -253,6 +268,7 @@ def get_crazy_functions(): "Group": "学术", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "下载arxiv论文并翻译摘要 | 输入参数为arxiv编号如1812.10695", "Function": HotReload(下载arxiv论文并翻译摘要) } }) @@ -266,6 +282,7 @@ def get_crazy_functions(): "Group": "对话", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + # "Info": "连接网络回答问题(需要访问谷歌)| 输入参数是一个问题", "Function": HotReload(连接网络回答问题) } }) @@ -275,6 +292,7 @@ def get_crazy_functions(): "Group": "对话", "Color": "stop", "AsButton": False, # 加入下拉菜单中 + "Info": "连接网络回答问题(需要访问中文Bing)| 输入参数是一个问题", "Function": HotReload(连接bing搜索回答问题) } }) @@ -350,6 +368,7 @@ def get_crazy_functions(): "Group": "对话", "Color": "stop", "AsButton": False, + "Info": "按照自然语言描述生成一个动画 | 输入参数是一段话", "Function": HotReload(动画生成) } }) @@ -437,6 +456,7 @@ def get_crazy_functions(): "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + 'If the term "agent" is used in this section, it should be translated to "智能体". ', + "Info": "Arixv论文精细翻译 | 输入参数arxiv论文的ID,比如1812.10695", "Function": HotReload(Latex翻译中文并重新编译PDF) } }) @@ -450,6 +470,7 @@ def get_crazy_functions(): "如果有必要, 请在此处给出自定义翻译命令, 解决部分词汇翻译不准确的问题。 " + "例如当单词'agent'翻译不准确时, 请尝试把以下指令复制到高级参数区: " + 'If the term "agent" is used in this section, it should be translated to "智能体". ', + "Info": "本地Latex论文精细翻译 | 输入参数是路径", "Function": HotReload(Latex翻译中文并重新编译PDF) } }) @@ -466,6 +487,7 @@ def get_crazy_functions(): "Group": "对话", "Color": "stop", "AsButton": True, + "Info": "开始语言对话 | 没有输入参数", "Function": HotReload(语音助手) } }) @@ -473,13 +495,13 @@ def get_crazy_functions(): print('Load function plugin failed') try: - from crazy_functions.虚空终端 import 自动终端 + from crazy_functions.虚空终端 import 虚空终端 function_plugins.update({ - "自动终端": { + "虚空终端": { "Group": "对话", "Color": "stop", "AsButton": False, - "Function": HotReload(自动终端) + "Function": HotReload(虚空终端) } }) except: diff --git a/crazy_functions/json_fns/pydantic_io.py b/crazy_functions/json_fns/pydantic_io.py index db92412..9bd39c3 100644 --- a/crazy_functions/json_fns/pydantic_io.py +++ b/crazy_functions/json_fns/pydantic_io.py @@ -37,10 +37,18 @@ Here is the output schema: {schema} ```""" + +PYDANTIC_FORMAT_INSTRUCTIONS_SIMPLE = """The output should be formatted as a JSON instance that conforms to the JSON schema below. +``` +{schema} +```""" + + class GptJsonIO(): - def __init__(self, schema): + def __init__(self, schema, example_instruction=True): self.pydantic_object = schema + self.example_instruction = example_instruction self.format_instructions = self.generate_format_instructions() def generate_format_instructions(self): @@ -53,9 +61,11 @@ class GptJsonIO(): if "type" in reduced_schema: del reduced_schema["type"] # Ensure json in context is well-formed with double quotes. - schema_str = json.dumps(reduced_schema) - - return PYDANTIC_FORMAT_INSTRUCTIONS.format(schema=schema_str) + if self.example_instruction: + schema_str = json.dumps(reduced_schema) + return PYDANTIC_FORMAT_INSTRUCTIONS.format(schema=schema_str) + else: + return PYDANTIC_FORMAT_INSTRUCTIONS_SIMPLE.format(schema=schema_str) def generate_output(self, text): # Greedy search for 1st json candidate. diff --git a/crazy_functions/vt_fns/vt_call_plugin.py b/crazy_functions/vt_fns/vt_call_plugin.py index c1c1976..8ee88b1 100644 --- a/crazy_functions/vt_fns/vt_call_plugin.py +++ b/crazy_functions/vt_fns/vt_call_plugin.py @@ -11,32 +11,47 @@ def read_avail_plugin_enum(): plugin_arr = get_crazy_functions() # remove plugins with out explaination plugin_arr = {k:v for k, v in plugin_arr.items() if 'Info' in v} - plugin_arr_info = {"F{:04d}".format(i):v["Info"] for i, v in enumerate(plugin_arr.values(), start=1)} - plugin_arr_dict = {"F{:04d}".format(i):v for i, v in enumerate(plugin_arr.values(), start=1)} + plugin_arr_info = {"F_{:04d}".format(i):v["Info"] for i, v in enumerate(plugin_arr.values(), start=1)} + plugin_arr_dict = {"F_{:04d}".format(i):v for i, v in enumerate(plugin_arr.values(), start=1)} prompt = json.dumps(plugin_arr_info, ensure_ascii=False, indent=2) prompt = "\n\nThe defination of PluginEnum:\nPluginEnum=" + prompt return prompt, plugin_arr_dict +def wrap_code(txt): + return f"\n```\n{txt}\n```\n" 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): - plugin_selection: str = Field(description="The most related plugin from one of the PluginEnum.", default="F0000000000000") - plugin_arg: str = Field(description="The argument of the plugin. A path or url or empty.", default="") - + plugin_selection: str = Field(description="The most related plugin from one of the PluginEnum.", default="F_0000") + reason_of_selection: str = Field(description="The reason why you should select this plugin.", default="This plugin satisfy user requirement most") # ⭐ ⭐ ⭐ 选择插件 yield from update_ui_lastest_msg(lastmsg=f"正在执行任务: {txt}\n\n查找可用插件中...", chatbot=chatbot, history=history, delay=0) gpt_json_io = GptJsonIO(Plugin) + gpt_json_io.format_instructions = "The format of your output should be a json that can be parsed by json.loads.\n" + gpt_json_io.format_instructions += """Output example: {"plugin_selection":"F_1234", "reason_of_selection":"F_1234 plugin satisfy user requirement most"}\n""" + gpt_json_io.format_instructions += "The plugins you are authorized to use are listed below:\n" gpt_json_io.format_instructions += plugin_arr_enum_prompt - inputs = "Choose the correct plugin and extract plugin_arg, the user requirement is: \n\n" + \ - ">> " + txt.rstrip('\n').replace('\n','\n>> ') + '\n\n' + \ - gpt_json_io.format_instructions + inputs = "Choose the correct plugin according to user requirements, the user requirement is: \n\n" + \ + ">> " + txt.rstrip('\n').replace('\n','\n>> ') + '\n\n' + gpt_json_io.format_instructions + 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=[]) - plugin_sel = gpt_json_io.generate_output_auto_repair(run_gpt_fn(inputs, ""), run_gpt_fn) - + try: + gpt_reply = run_gpt_fn(inputs, "") + plugin_sel = gpt_json_io.generate_output_auto_repair(gpt_reply, run_gpt_fn) + except: + msg = "抱歉,当前的大语言模型无法理解您的需求。" + msg += "请求的Prompt为:\n" + wrap_code(inputs) + 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 = f'找不到合适插件执行该任务' + msg = "抱歉, 找不到合适插件执行该任务, 当前的大语言模型可能无法理解您的需求。" + msg += "请求的Prompt为:\n" + wrap_code(inputs) + msg += "语言模型回复为:\n" + wrap_code(gpt_reply) + msg += "但您可以尝试再试一次\n" yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) return diff --git a/crazy_functions/虚空终端.py b/crazy_functions/虚空终端.py index da16527..ef8efd5 100644 --- a/crazy_functions/虚空终端.py +++ b/crazy_functions/虚空终端.py @@ -46,7 +46,7 @@ def analyze_with_rule(txt): return is_certain, user_intention @CatchException -def 自动终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): +def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): """ txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径 llm_kwargs gpt模型参数, 如温度和top_p等, 一般原样传递下去就行 @@ -57,7 +57,7 @@ def 自动终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt web_port 当前软件运行的端口号 """ history = [] # 清空历史,以免输入溢出 - chatbot.append(("自动终端状态: ", f"正在执行任务: {txt}")) + chatbot.append(("虚空终端状态: ", f"正在执行任务: {txt}")) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 初始化插件状态 @@ -67,21 +67,29 @@ def 自动终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt def update_vt_state(): # 赋予插件锁定 锁定插件回调路径,当下一次用户提交时,会直接转到该函数 - chatbot._cookies['lock_plugin'] = 'crazy_functions.虚空终端->自动终端' + chatbot._cookies['lock_plugin'] = 'crazy_functions.虚空终端->虚空终端' chatbot._cookies['vt_state'] = pickle.dumps(state) # ⭐ ⭐ ⭐ 分析用户意图 is_certain, user_intention = analyze_with_rule(txt) if not is_certain: - yield from update_ui_lastest_msg(lastmsg=f"正在执行任务: {txt}\n\n分析用户意图中", chatbot=chatbot, history=history, delay=0) + yield from update_ui_lastest_msg( + lastmsg=f"正在执行任务: {txt}\n\n分析用户意图中", chatbot=chatbot, history=history, delay=0) gpt_json_io = GptJsonIO(UserIntention) inputs = "Analyze the intention of the user according to following user input: \n\n" + txt + '\n\n' + gpt_json_io.format_instructions 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=[]) - user_intention = gpt_json_io.generate_output_auto_repair(run_gpt_fn(inputs, ""), run_gpt_fn) + try: + user_intention = gpt_json_io.generate_output_auto_repair(run_gpt_fn(inputs, ""), run_gpt_fn) + except: + yield from update_ui_lastest_msg( + lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 失败 当前语言模型不能理解您的意图", chatbot=chatbot, history=history, delay=0) + return else: pass + yield from update_ui_lastest_msg( + lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: intention_type={user_intention.intention_type}", chatbot=chatbot, history=history, delay=0) # 用户意图: 修改本项目的配置 if user_intention.intention_type == 'ModifyConfiguration': yield from modify_configuration_reboot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention) @@ -97,22 +105,3 @@ def 自动终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt return - - - - # # if state == 'wait_user_keyword': - # # chatbot._cookies['lock_plugin'] = None # 解除插件锁定,避免遗忘导致死锁 - # # chatbot._cookies['plugin_state_0001'] = None # 解除插件状态,避免遗忘导致死锁 - - # # # 解除插件锁定 - # # chatbot.append((f"获取关键词:{txt}", "")) - # # yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - # # inputs=inputs_show_user=f"Extract all image urls in this html page, pick the first 5 images and show them with markdown format: \n\n {page_return}" - # # gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive( - # # inputs=inputs, inputs_show_user=inputs_show_user, - # # llm_kwargs=llm_kwargs, chatbot=chatbot, history=[], - # # sys_prompt="When you want to show an image, use markdown format. e.g. ![image_description](image_url). If there are no image url provided, answer 'no image url provided'" - # # ) - # # chatbot[-1] = [chatbot[-1][0], gpt_say] - # yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - # return diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 2207f71..2780ed2 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -9,9 +9,9 @@ validate_path() # 返回项目根路径 from tests.test_utils import plugin_test if __name__ == "__main__": - # plugin_test(plugin='crazy_functions.虚空终端->自动终端', main_input='修改api-key为sk-jhoejriotherjep') + # plugin_test(plugin='crazy_functions.虚空终端->虚空终端', main_input='修改api-key为sk-jhoejriotherjep') - plugin_test(plugin='crazy_functions.虚空终端->自动终端', main_input='调用插件,对C:/Users/fuqingxu/Desktop/旧文件/gpt/chatgpt_academic/crazy_functions/latex_fns中的python文件进行解析') + plugin_test(plugin='crazy_functions.虚空终端->虚空终端', main_input='调用插件,对C:/Users/fuqingxu/Desktop/旧文件/gpt/chatgpt_academic/crazy_functions/latex_fns中的python文件进行解析') # plugin_test(plugin='crazy_functions.命令行助手->命令行助手', main_input='查看当前的docker容器列表') diff --git a/version b/version index 303a44b..2034d6d 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { - "version": 3.49, + "version": 3.50, "show_feature": true, - "new_feature": "支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率 <-> 支持自定义APIKEY格式 <-> 临时修复theme的文件丢失问题 <-> 新增实时语音对话插件(自动断句,脱手对话) <-> 支持加载自定义的ChatGLM2微调模型 <-> 动态ChatBot窗口高度 <-> 修复Azure接口的BUG <-> 完善多语言模块" + "new_feature": "支持自然语言插件调度(虚空终端) <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率 <-> 支持自定义APIKEY格式 <-> 临时修复theme的文件丢失问题 <-> 新增实时语音对话插件(自动断句,脱手对话) <-> 支持加载自定义的ChatGLM2微调模型 <-> 动态ChatBot窗口高度 <-> 修复Azure接口的BUG <-> 完善多语言模块" } From d0af07422583710b86351302f0202bcc76e31526 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sat, 2 Sep 2023 18:19:19 +0800 Subject: [PATCH 07/14] change layout --- core_functional.py | 2 ++ crazy_functional.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core_functional.py b/core_functional.py index b04e1e0..c4519ef 100644 --- a/core_functional.py +++ b/core_functional.py @@ -63,6 +63,7 @@ def get_core_functions(): "英译中": { "Prefix": r"翻译成地道的中文:" + "\n\n", "Suffix": r"", + "Visible": False, }, "找图片": { "Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," + @@ -78,6 +79,7 @@ def get_core_functions(): "Prefix": r"Here are some bibliography items, please transform them into bibtex style." + r"Note that, reference styles maybe more than one kind, you should transform each item correctly." + r"Items need to be transformed:", + "Visible": False, "Suffix": r"", } } diff --git a/crazy_functional.py b/crazy_functional.py index 1388e34..8fed5f8 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -500,7 +500,7 @@ def get_crazy_functions(): "虚空终端": { "Group": "对话", "Color": "stop", - "AsButton": False, + "AsButton": True, "Function": HotReload(虚空终端) } }) From 1639796041b4354ce3927776650f44a9c7453671 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sat, 2 Sep 2023 22:22:41 +0800 Subject: [PATCH 08/14] support file implementation --- crazy_functions/Latex输出PDF结果.py | 4 +-- crazy_functions/vt_fns/vt_call_plugin.py | 26 ++++++++++++++++-- main.py | 4 +-- themes/common.css | 6 ++++ toolbox.py | 35 ++++++++++++++++++------ 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/crazy_functions/Latex输出PDF结果.py b/crazy_functions/Latex输出PDF结果.py index e79cf82..0ba9f19 100644 --- a/crazy_functions/Latex输出PDF结果.py +++ b/crazy_functions/Latex输出PDF结果.py @@ -6,7 +6,7 @@ pj = os.path.join ARXIV_CACHE_DIR = os.path.expanduser(f"~/arxiv_cache/") # =================================== 工具函数 =============================================== -专业词汇声明 = 'If the term "agent" is used in this section, it should be translated to "智能体". ' +# 专业词汇声明 = 'If the term "agent" is used in this section, it should be translated to "智能体". ' def switch_prompt(pfg, mode, more_requirement): """ Generate prompts and system prompts based on the mode for proofreading or translating. @@ -291,7 +291,7 @@ def Latex翻译中文并重新编译PDF(txt, llm_kwargs, plugin_kwargs, chatbot, yield from update_ui(chatbot=chatbot, history=history); time.sleep(1) # 刷新界面 promote_file_to_downloadzone(file=zip_res, chatbot=chatbot) else: - chatbot.append((f"失败了", '虽然PDF生成失败了, 但请查收结果(压缩包), 内含已经翻译的Tex文档, 也是可读的, 您可以到Github Issue区, 用该压缩包+对话历史存档进行反馈 ...')) + chatbot.append((f"失败了", '虽然PDF生成失败了, 但请查收结果(压缩包), 内含已经翻译的Tex文档, 您可以到Github Issue区, 用该压缩包进行反馈。如系统是Linux,请检查系统字体(见Github wiki) ...')) yield from update_ui(chatbot=chatbot, history=history); time.sleep(1) # 刷新界面 promote_file_to_downloadzone(file=zip_res, chatbot=chatbot) diff --git a/crazy_functions/vt_fns/vt_call_plugin.py b/crazy_functions/vt_fns/vt_call_plugin.py index 8ee88b1..09b136f 100644 --- a/crazy_functions/vt_fns/vt_call_plugin.py +++ b/crazy_functions/vt_fns/vt_call_plugin.py @@ -3,7 +3,7 @@ from typing import List from toolbox import update_ui_lastest_msg, get_conf from request_llm.bridge_all import predict_no_ui_long_connection from crazy_functions.json_fns.pydantic_io import GptJsonIO -import copy, json, pickle, os, sys +import copy, json, pickle, os, sys, time def read_avail_plugin_enum(): @@ -20,6 +20,23 @@ def read_avail_plugin_enum(): def wrap_code(txt): return f"\n```\n{txt}\n```\n" +def have_any_recent_upload_files(chatbot): + _5min = 5 * 60 + if not chatbot: return False # chatbot is None + most_recent_uploaded = chatbot._cookies.get("most_recent_uploaded", None) + if not most_recent_uploaded: return False # most_recent_uploaded is None + if time.time() - most_recent_uploaded["time"] < _5min: return True # most_recent_uploaded is new + else: return False # most_recent_uploaded is too old + +def get_recent_file_prompt_support(chatbot): + most_recent_uploaded = chatbot._cookies.get("most_recent_uploaded", None) + path = most_recent_uploaded['path'] + prompt = "\nAdditional Information:\n" + prompt = "In case that this plugin requires a path or a file as argument," + prompt += f"it is important for you to know that the user has recently uploaded a file, located at: `{path}`" + prompt += f"Only use it when necessary, otherwise, you can ignore this file." + return prompt + 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): @@ -56,6 +73,11 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom return # ⭐ ⭐ ⭐ 确认插件参数 + if not have_any_recent_upload_files(chatbot): + appendix_info = "" + else: + appendix_info = get_recent_file_prompt_support(chatbot) + plugin = plugin_arr_dict[plugin_sel.plugin_selection] yield from update_ui_lastest_msg(lastmsg=f"正在执行任务: {txt}\n\n提取插件参数...", chatbot=chatbot, history=history, delay=0) class PluginExplicit(BaseModel): @@ -65,7 +87,7 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom gpt_json_io.format_instructions += "The information about this plugin is:" + plugin["Info"] inputs = f"A plugin named {plugin_sel.plugin_selection} is selected, " + \ "you should extract plugin_arg from the user requirement, the user requirement is: \n\n" + \ - ">> " + txt.rstrip('\n').replace('\n','\n>> ') + '\n\n' + \ + ">> " + (txt + appendix_info).rstrip('\n').replace('\n','\n>> ') + '\n\n' + \ gpt_json_io.format_instructions 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=[]) diff --git a/main.py b/main.py index 50028c2..feebfb6 100644 --- a/main.py +++ b/main.py @@ -113,7 +113,7 @@ def main(): plugin_advanced_arg = gr.Textbox(show_label=True, label="高级参数输入区", visible=False, placeholder="这里是特殊函数插件的高级参数输入区").style(container=False) with gr.Row(): - switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary") + switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary").style(size="sm") with gr.Row(): with gr.Accordion("点击展开“文件上传区”。上传本地文件/压缩包供函数插件调用。", open=False) as area_file_up: file_upload = gr.Files(label="任何文件, 但推荐上传压缩文件(zip, tar)", file_count="multiple") @@ -172,7 +172,7 @@ def main(): click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(k)], outputs=output_combo) cancel_handles.append(click_handle) # 文件上传区,接收文件后与chatbot的互动 - file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes], [chatbot, txt, txt2]) + file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies]) # 函数插件-固定按钮区 for k in plugins: if not plugins[k].get("AsButton", True): continue diff --git a/themes/common.css b/themes/common.css index 33bb4f0..c43e54d 100644 --- a/themes/common.css +++ b/themes/common.css @@ -13,3 +13,9 @@ #input-plugin-group .svelte-1gfkn6j { visibility: hidden; } + + +/* height of the upload box */ +.wrap.svelte-xwlu1w { + min-height: var(--size-32); +} \ No newline at end of file diff --git a/toolbox.py b/toolbox.py index 6da2347..9a06895 100644 --- a/toolbox.py +++ b/toolbox.py @@ -24,6 +24,19 @@ pj = os.path.join class ChatBotWithCookies(list): def __init__(self, cookie): + """ + cookies = { + 'top_p': top_p, + 'temperature': temperature, + 'lock_plugin': bool, + "files_to_promote": ["file1", "file2"], + "most_recent_uploaded": { + "path": "uploaded_path", + "time": time.time(), + "time_str": "timestr", + } + } + """ self._cookies = cookie def write_list(self, list): @@ -503,15 +516,15 @@ def promote_file_to_downloadzone(file, rename_file=None, chatbot=None): if not os.path.exists(new_path): shutil.copyfile(file, new_path) # 将文件添加到chatbot cookie中,避免多用户干扰 if chatbot: - if 'file_to_promote' in chatbot._cookies: current = chatbot._cookies['file_to_promote'] + if 'files_to_promote' in chatbot._cookies: current = chatbot._cookies['files_to_promote'] else: current = [] - chatbot._cookies.update({'file_to_promote': [new_path] + current}) + chatbot._cookies.update({'files_to_promote': [new_path] + current}) def disable_auto_promotion(chatbot): - chatbot._cookies.update({'file_to_promote': []}) + chatbot._cookies.update({'files_to_promote': []}) return -def on_file_uploaded(files, chatbot, txt, txt2, checkboxes): +def on_file_uploaded(files, chatbot, txt, txt2, checkboxes, cookies): """ 当文件被上传时的回调函数 """ @@ -546,14 +559,20 @@ def on_file_uploaded(files, chatbot, txt, txt2, checkboxes): f'[Local Message] 收到以下文件: \n\n{moved_files_str}' + f'\n\n调用路径参数已自动修正到: \n\n{txt}' + f'\n\n现在您点击任意“红颜色”标识的函数插件时,以上文件将被作为输入参数'+err_msg]) - return chatbot, txt, txt2 + cookies.update({ + 'most_recent_uploaded': { + 'path': f'private_upload/{time_tag}', + 'time': time.time(), + 'time_str': time_tag + }}) + return chatbot, txt, txt2, cookies def on_report_generated(cookies, files, chatbot): from toolbox import find_recent_files - if 'file_to_promote' in cookies: - report_files = cookies['file_to_promote'] - cookies.pop('file_to_promote') + if 'files_to_promote' in cookies: + report_files = cookies['files_to_promote'] + cookies.pop('files_to_promote') else: report_files = find_recent_files('gpt_log') if len(report_files) == 0: From 0b70e9df7b5635f598ad32af917a2cabccb9c27f Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sat, 2 Sep 2023 23:49:56 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=99=9A=E7=A9=BA?= =?UTF-8?q?=E7=BB=88=E7=AB=AF=E8=B0=83=E7=94=A8=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/vt_fns/vt_state.py | 28 +++++++++ crazy_functions/虚空终端.py | 95 ++++++++++++++++++++++-------- toolbox.py | 2 +- 3 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 crazy_functions/vt_fns/vt_state.py diff --git a/crazy_functions/vt_fns/vt_state.py b/crazy_functions/vt_fns/vt_state.py new file mode 100644 index 0000000..1818728 --- /dev/null +++ b/crazy_functions/vt_fns/vt_state.py @@ -0,0 +1,28 @@ +import pickle + +class VoidTerminalState(): + def __init__(self): + self.reset_state() + + def reset_state(self): + self.has_provided_explaination = False + + def lock_plugin(self, chatbot): + chatbot._cookies['lock_plugin'] = 'crazy_functions.虚空终端->虚空终端' + chatbot._cookies['plugin_state'] = pickle.dumps(self) + + def unlock_plugin(self, chatbot): + self.reset_state() + chatbot._cookies['lock_plugin'] = None + chatbot._cookies['plugin_state'] = pickle.dumps(self) + + def set_state(self, chatbot, key, value): + setattr(self, key, value) + chatbot._cookies['plugin_state'] = pickle.dumps(self) + + def get_state(chatbot): + state = chatbot._cookies.get('plugin_state', None) + if state is not None: state = pickle.loads(state) + else: state = VoidTerminalState() + state.chatbot = chatbot + return state \ No newline at end of file diff --git a/crazy_functions/虚空终端.py b/crazy_functions/虚空终端.py index ef8efd5..6304bd7 100644 --- a/crazy_functions/虚空终端.py +++ b/crazy_functions/虚空终端.py @@ -6,6 +6,7 @@ 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 input_clipping from crazy_functions.json_fns.pydantic_io import GptJsonIO +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_reboot from crazy_functions.vt_fns.vt_call_plugin import execute_plugin @@ -13,12 +14,14 @@ from enum import Enum import copy, json, pickle, os, sys + class UserIntention(BaseModel): user_prompt: str = Field(description="the content of user input", default="") - intention_type: str = Field(description="the type of user intention, choose from ['ModifyConfiguration', 'ExecutePlugin', 'Chat']", default="Chat") + intention_type: str = Field(description="the type of user intention, choose from ['ModifyConfiguration', 'ExecutePlugin', 'Chat']", default="ExecutePlugin") user_provide_file: bool = Field(description="whether the user provides a path to a file", default=False) user_provide_url: bool = Field(description="whether the user provides a url", default=False) + def chat(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention): gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive( inputs=txt, inputs_show_user=txt, @@ -30,11 +33,23 @@ def chat(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_i yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 pass -def analyze_with_rule(txt): + +explain_intention_to_user = { + 'Chat': "聊天对话", + 'ExecutePlugin': "调用插件", + 'ModifyConfiguration': "修改配置", +} + + +def analyze_intention_with_simple_rules(txt): user_intention = UserIntention() user_intention.user_prompt = txt is_certain = False + if '请问' in txt: + is_certain = True + user_intention.intention_type = 'Chat' + if '调用插件' in txt: is_certain = True user_intention.intention_type = 'ExecutePlugin' @@ -45,33 +60,63 @@ def analyze_with_rule(txt): return is_certain, user_intention + + + + + + +explain_msg = """ +## 虚空终端插件说明: + +请用**自然语言**描述您需要做什么。 + +1. 如果涉及文件处理, 请务必描述文件所在路径(把文件拖拽到文件上传区亦可)。 + +2. 您可以打开插件下拉菜单以了解本项目的各种能力。 + +3. 如果您使用“调用插件xxx”、“修改配置xxx”、“请问”等关键词,您的意图可以被识别的更准确。 + +4. 使用GPT4等强模型时,您的意图可以被识别的更准确。 + +5. 现在,请您给出指令(或先上传文件,再给指令)。 +""" + + + + @CatchException def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): - """ - txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径 - llm_kwargs gpt模型参数, 如温度和top_p等, 一般原样传递下去就行 - plugin_kwargs 插件模型的参数, 如温度和top_p等, 一般原样传递下去就行 - chatbot 聊天显示框的句柄,用于显示给用户 - history 聊天历史,前情提要 - system_prompt 给gpt的静默提醒 - web_port 当前软件运行的端口号 - """ - history = [] # 清空历史,以免输入溢出 + # 获取当前虚空终端状态 + state = VoidTerminalState.get_state(chatbot) + + # 用简单的关键词检测用户意图 + is_certain, _ = analyze_intention_with_simple_rules(txt) + + if is_certain or (state.has_provided_explaination): + # 如果意图明确,跳过提示环节 + state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True) + state.unlock_plugin(chatbot=chatbot) + yield from update_ui(chatbot=chatbot, history=history) + yield from 虚空终端主路由(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port) + return + else: + # 如果意图模糊,提示 + state.set_state(chatbot=chatbot, key='has_provided_explaination', value=True) + state.lock_plugin(chatbot=chatbot) + chatbot.append(("虚空终端状态:", explain_msg)) + yield from update_ui(chatbot=chatbot, history=history) + return + + + +def 虚空终端主路由(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): + history = [] chatbot.append(("虚空终端状态: ", f"正在执行任务: {txt}")) yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 - # 初始化插件状态 - state = chatbot._cookies.get('plugin_state', None) - if state is not None: state = pickle.loads(state) - else: state = {} - - def update_vt_state(): - # 赋予插件锁定 锁定插件回调路径,当下一次用户提交时,会直接转到该函数 - chatbot._cookies['lock_plugin'] = 'crazy_functions.虚空终端->虚空终端' - chatbot._cookies['vt_state'] = pickle.dumps(state) - # ⭐ ⭐ ⭐ 分析用户意图 - is_certain, user_intention = analyze_with_rule(txt) + is_certain, user_intention = analyze_intention_with_simple_rules(txt) if not is_certain: yield from update_ui_lastest_msg( lastmsg=f"正在执行任务: {txt}\n\n分析用户意图中", chatbot=chatbot, history=history, delay=0) @@ -89,7 +134,9 @@ def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt pass yield from update_ui_lastest_msg( - lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: intention_type={user_intention.intention_type}", chatbot=chatbot, history=history, delay=0) + lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 意图={explain_intention_to_user[user_intention.intention_type]}", + chatbot=chatbot, history=history, delay=0) + # 用户意图: 修改本项目的配置 if user_intention.intention_type == 'ModifyConfiguration': yield from modify_configuration_reboot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention) diff --git a/toolbox.py b/toolbox.py index 9a06895..0d598d8 100644 --- a/toolbox.py +++ b/toolbox.py @@ -82,7 +82,7 @@ def ArgsGeneralWrapper(f): # 处理个别特殊插件的锁定状态 module, fn_name = cookies['lock_plugin'].split('->') f_hot_reload = getattr(importlib.import_module(module, fn_name), fn_name) - yield from f_hot_reload(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args) + yield from f_hot_reload(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, request) return decorated 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 10/14] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=99=9A=E7=A9=BA?= =?UTF-8?q?=E7=BB=88=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 From 1dd165a3cd1f74b2f643f2b94948b790c6806d55 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sun, 3 Sep 2023 14:47:22 +0800 Subject: [PATCH 11/14] ui layout improve --- crazy_functional.py | 21 ++++------ crazy_functions/虚空终端.py | 81 ++++++++++++++++++++----------------- toolbox.py | 3 +- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/crazy_functional.py b/crazy_functional.py index 05e4466..f06cd40 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -34,9 +34,16 @@ def get_crazy_functions(): from crazy_functions.Latex全文翻译 import Latex中译英 from crazy_functions.Latex全文翻译 import Latex英译中 from crazy_functions.批量Markdown翻译 import Markdown中译英 + from crazy_functions.虚空终端 import 虚空终端 function_plugins = { + "虚空终端": { + "Group": "对话|编程|学术", + "Color": "stop", + "AsButton": True, + "Function": HotReload(虚空终端) + }, "解析整个Python项目": { "Group": "编程", "Color": "stop", @@ -139,7 +146,7 @@ def get_crazy_functions(): "读Tex论文写摘要": { "Group": "学术", "Color": "stop", - "AsButton": True, + "AsButton": False, "Info": "读取Tex论文并写摘要 | 输入参数为路径", "Function": HotReload(读文章写摘要) }, @@ -494,18 +501,6 @@ def get_crazy_functions(): except: print('Load function plugin failed') - try: - from crazy_functions.虚空终端 import 虚空终端 - function_plugins.update({ - "虚空终端": { - "Group": "对话", - "Color": "stop", - "AsButton": True, - "Function": HotReload(虚空终端) - } - }) - except: - print('Load function plugin failed') # try: # from crazy_functions.chatglm微调工具 import 微调数据集生成 diff --git a/crazy_functions/虚空终端.py b/crazy_functions/虚空终端.py index c4f2b2f..cdf0605 100644 --- a/crazy_functions/虚空终端.py +++ b/crazy_functions/虚空终端.py @@ -1,3 +1,48 @@ +""" +Explanation of the Void Terminal Plugin: + +Please describe in natural language what you want to do. + +1. You can open the plugin's dropdown menu to explore various capabilities of this project, and then describe your needs in natural language, for example: +- "Please call the plugin to translate a PDF paper for me. I just uploaded the paper to the upload area." +- "Please use the plugin to translate a PDF paper, with the address being https://www.nature.com/articles/s41586-019-1724-z.pdf." +- "Generate an image with blooming flowers and lush green grass using the plugin." +- "Translate the README using the plugin. The GitHub URL is https://github.com/facebookresearch/co-tracker." +- "Translate an Arxiv paper for me. The Arxiv ID is 1812.10695. Remember to use the plugin and don't do it manually!" +- "I don't like the current interface color. Modify the configuration and change the theme to THEME="High-Contrast"." +- "Could you please explain the structure of the Transformer network?" + +2. If you use keywords like "call the plugin xxx", "modify the configuration xxx", "please", etc., your intention can be recognized more accurately. + +3. Your intention can be recognized more accurately when using powerful models like GPT4. This plugin is relatively new, so please feel free to provide feedback on GitHub. + +4. Now, if you need to process a file, please upload the file (drag the file to the file upload area) or describe the path to the file. + +5. If you don't need to upload a file, you can simply repeat your command again. +""" +explain_msg = """ +## 虚空终端插件说明: + +请用**自然语言**描述您需要做什么。 + +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. 如果您使用「调用插件xxx」、「修改配置xxx」、「请问」等关键词,您的意图可以被识别的更准确。 + +3. 使用GPT4等强力模型时,您的意图可以被识别的更准确。该插件诞生时间不长,欢迎您前往Github反馈问题。 + +4. 现在,如果需要处理文件,请您上传文件(将文件拖动到文件上传区),或者描述文件所在的路径。 + +5. 如果不需要上传文件,现在您只需要再次重复一次您的指令即可。 +""" + from pydantic import BaseModel, Field from typing import List from toolbox import CatchException, update_ui, gen_time_str @@ -10,10 +55,6 @@ 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_reboot from crazy_functions.vt_fns.vt_call_plugin import execute_plugin -from enum import Enum -import copy, json, pickle, os, sys - - class UserIntention(BaseModel): user_prompt: str = Field(description="the content of user input", default="") @@ -61,37 +102,6 @@ def analyze_intention_with_simple_rules(txt): return is_certain, user_intention - - - - - -explain_msg = """ -## 虚空终端插件说明: - -请用**自然语言**描述您需要做什么。 - -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. 如果您使用「调用插件xxx」、「修改配置xxx」、「请问」等关键词,您的意图可以被识别的更准确。 - -3. 使用GPT4等强模型时,您的意图可以被识别的更准确。 - -4. 现在,如果需要处理文件,请您上传文件(将文件拖动到文件上传区),或者描述文件所在的路径。 - -5. 如果不需要上传文件,现在您只需要再次重复一次您的指令即可。 -""" - - - - @CatchException def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): # 获取当前虚空终端状态 @@ -162,4 +172,3 @@ def 虚空终端主路由(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst return - diff --git a/toolbox.py b/toolbox.py index 0d598d8..1242fab 100644 --- a/toolbox.py +++ b/toolbox.py @@ -492,7 +492,8 @@ def find_recent_files(directory): current_time = time.time() one_minute_ago = current_time - 60 recent_files = [] - + if not os.path.exists(directory): + os.makedirs(directory, exist_ok=True) for filename in os.listdir(directory): file_path = os.path.join(directory, filename) if file_path.endswith('.log'): From a3e6fc0141ba5afaffd1d9da0a0f9bf317a53b09 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sun, 3 Sep 2023 15:32:39 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E5=BF=83?= =?UTF-8?q?=E4=B8=80=E8=A8=80=E7=9A=84=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/vt_fns/vt_call_plugin.py | 26 +++++++++++++----------- crazy_functions/虚空终端.py | 12 +++++++---- request_llm/bridge_qianfan.py | 5 +++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/crazy_functions/vt_fns/vt_call_plugin.py b/crazy_functions/vt_fns/vt_call_plugin.py index 1f84d23..614e9fe 100644 --- a/crazy_functions/vt_fns/vt_call_plugin.py +++ b/crazy_functions/vt_fns/vt_call_plugin.py @@ -1,6 +1,6 @@ from pydantic import BaseModel, Field from typing import List -from toolbox import update_ui_lastest_msg, get_conf +from toolbox import update_ui_lastest_msg, disable_auto_promotion from request_llm.bridge_all import predict_no_ui_long_connection from crazy_functions.json_fns.pydantic_io import GptJsonIO import copy, json, pickle, os, sys, time @@ -13,11 +13,14 @@ def read_avail_plugin_enum(): plugin_arr = {k:v for k, v in plugin_arr.items() if 'Info' in v} plugin_arr_info = {"F_{:04d}".format(i):v["Info"] for i, v in enumerate(plugin_arr.values(), start=1)} plugin_arr_dict = {"F_{:04d}".format(i):v for i, v in enumerate(plugin_arr.values(), start=1)} + plugin_arr_dict_parse = {"F_{:04d}".format(i):v for i, v in enumerate(plugin_arr.values(), start=1)} + plugin_arr_dict_parse.update({f"F_{i}":v for i, v in enumerate(plugin_arr.values(), start=1)}) prompt = json.dumps(plugin_arr_info, ensure_ascii=False, indent=2) prompt = "\n\nThe defination of PluginEnum:\nPluginEnum=" + prompt - return prompt, plugin_arr_dict + return prompt, plugin_arr_dict, plugin_arr_dict_parse def wrap_code(txt): + txt = txt.replace('```','') return f"\n```\n{txt}\n```\n" def have_any_recent_upload_files(chatbot): @@ -47,7 +50,7 @@ def get_inputs_show_user(inputs, plugin_arr_enum_prompt): 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() + plugin_arr_enum_prompt, plugin_arr_dict, plugin_arr_dict_parse = read_avail_plugin_enum() class Plugin(BaseModel): plugin_selection: str = Field(description="The most related plugin from one of the PluginEnum.", default="F_0000") reason_of_selection: str = Field(description="The reason why you should select this plugin.", default="This plugin satisfy user requirement most") @@ -67,17 +70,16 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom gpt_reply = run_gpt_fn(inputs, "") plugin_sel = gpt_json_io.generate_output_auto_repair(gpt_reply, run_gpt_fn) except: - msg = "抱歉,当前的大语言模型无法理解您的需求。" + msg = f"抱歉, {llm_kwargs['llm_model']}无法理解您的需求。" msg += "请求的Prompt为:\n" + wrap_code(get_inputs_show_user(inputs, plugin_arr_enum_prompt)) msg += "语言模型回复为:\n" + wrap_code(gpt_reply) - msg += "但您可以尝试再试一次\n" + msg += "\n但您可以尝试再试一次\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(get_inputs_show_user(inputs, plugin_arr_enum_prompt)) - msg += "语言模型回复为:\n" + wrap_code(gpt_reply) - msg += "但您可以尝试再试一次\n" + if plugin_sel.plugin_selection not in plugin_arr_dict_parse: + msg = f"抱歉, 找不到合适插件执行该任务, 或者{llm_kwargs['llm_model']}无法理解您的需求。" + msg += f"语言模型{llm_kwargs['llm_model']}选择了不存在的插件:\n" + wrap_code(gpt_reply) + msg += "\n但您可以尝试再试一次\n" yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) return @@ -87,7 +89,7 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom else: appendix_info = get_recent_file_prompt_support(chatbot) - plugin = plugin_arr_dict[plugin_sel.plugin_selection] + plugin = plugin_arr_dict_parse[plugin_sel.plugin_selection] yield from update_ui_lastest_msg(lastmsg=f"正在执行任务: {txt}\n\n提取插件参数...", chatbot=chatbot, history=history, delay=0) class PluginExplicit(BaseModel): plugin_selection: str = plugin_sel.plugin_selection @@ -106,7 +108,7 @@ def execute_plugin(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom # ⭐ ⭐ ⭐ 执行插件 fn = plugin['Function'] fn_name = fn.__name__ - msg = f'正在调用插件: {fn_name}\n\n插件说明:{plugin["Info"]}\n\n插件参数:{plugin_sel.plugin_arg}' + msg = f'{llm_kwargs["llm_model"]}为您选择了插件: `{fn_name}`\n\n插件说明:{plugin["Info"]}\n\n插件参数:{plugin_sel.plugin_arg}\n\n假如偏离了您的要求,按停止键终止。' yield from update_ui_lastest_msg(lastmsg=msg, chatbot=chatbot, history=history, delay=2) yield from fn(plugin_sel.plugin_arg, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, -1) return \ No newline at end of file diff --git a/crazy_functions/虚空终端.py b/crazy_functions/虚空终端.py index cdf0605..caf241c 100644 --- a/crazy_functions/虚空终端.py +++ b/crazy_functions/虚空终端.py @@ -36,7 +36,7 @@ explain_msg = """ 2. 如果您使用「调用插件xxx」、「修改配置xxx」、「请问」等关键词,您的意图可以被识别的更准确。 -3. 使用GPT4等强力模型时,您的意图可以被识别的更准确。该插件诞生时间不长,欢迎您前往Github反馈问题。 +3. 建议使用 GPT3.5 或更强的模型,弱模型可能无法理解您的想法。该插件诞生时间不长,欢迎您前往Github反馈问题。 4. 现在,如果需要处理文件,请您上传文件(将文件拖动到文件上传区),或者描述文件所在的路径。 @@ -46,7 +46,7 @@ explain_msg = """ from pydantic import BaseModel, Field from typing import List from toolbox import CatchException, update_ui, gen_time_str -from toolbox import update_ui_lastest_msg +from toolbox import update_ui_lastest_msg, disable_auto_promotion 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 input_clipping @@ -104,6 +104,7 @@ def analyze_intention_with_simple_rules(txt): @CatchException def 虚空终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): + disable_auto_promotion(chatbot=chatbot) # 获取当前虚空终端状态 state = VoidTerminalState.get_state(chatbot) appendix_msg = "" @@ -142,14 +143,17 @@ def 虚空终端主路由(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst yield from update_ui_lastest_msg( lastmsg=f"正在执行任务: {txt}\n\n分析用户意图中", chatbot=chatbot, history=history, delay=0) gpt_json_io = GptJsonIO(UserIntention) - inputs = "Analyze the intention of the user according to following user input: \n\n" + txt + '\n\n' + gpt_json_io.format_instructions + rf_req = "\nchoose from ['ModifyConfiguration', 'ExecutePlugin', 'Chat']" + inputs = "Analyze the intention of the user according to following user input: \n\n" + \ + ">> " + (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( inputs=inputs, llm_kwargs=llm_kwargs, history=[], sys_prompt=sys_prompt, observe_window=[]) try: user_intention = gpt_json_io.generate_output_auto_repair(run_gpt_fn(inputs, ""), run_gpt_fn) + lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 意图={explain_intention_to_user[user_intention.intention_type]}", except: yield from update_ui_lastest_msg( - lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 失败 当前语言模型不能理解您的意图", chatbot=chatbot, history=history, delay=0) + lastmsg=f"正在执行任务: {txt}\n\n用户意图理解: 失败 当前语言模型({llm_kwargs['llm_model']})不能理解您的意图", chatbot=chatbot, history=history, delay=0) return else: pass diff --git a/request_llm/bridge_qianfan.py b/request_llm/bridge_qianfan.py index e2cdb0e..be73976 100644 --- a/request_llm/bridge_qianfan.py +++ b/request_llm/bridge_qianfan.py @@ -49,16 +49,17 @@ def get_access_token(): def generate_message_payload(inputs, llm_kwargs, history, system_prompt): conversation_cnt = len(history) // 2 + if system_prompt == "": system_prompt = "Hello" messages = [{"role": "user", "content": system_prompt}] messages.append({"role": "assistant", "content": 'Certainly!'}) if conversation_cnt: for index in range(0, 2*conversation_cnt, 2): what_i_have_asked = {} what_i_have_asked["role"] = "user" - what_i_have_asked["content"] = history[index] + what_i_have_asked["content"] = history[index] if history[index]!="" else "Hello" what_gpt_answer = {} what_gpt_answer["role"] = "assistant" - what_gpt_answer["content"] = history[index+1] + what_gpt_answer["content"] = history[index+1] if history[index]!="" else "Hello" if what_i_have_asked["content"] != "": if what_gpt_answer["content"] == "": continue if what_gpt_answer["content"] == timeout_bot_msg: continue From 0d6e32d31a812744d837fcbba1f5fbe16d955c18 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sun, 3 Sep 2023 15:38:10 +0800 Subject: [PATCH 13/14] version 3.5 release --- README.md | 3 ++- version | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 761e303..43b38dd 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,8 @@ Tip:不指定文件直接点击 `载入对话历史存档` 可以查看历史h ### II:版本: -- version 3.5(Todo): 使用自然语言调用本项目的所有函数插件(高优先级) +- version 3.60(todo): 优化虚空终端,引入code interpreter和更多插件 +- version 3.50: 使用自然语言调用本项目的所有函数插件(虚空终端),支持插件分类,改进UI,设计新主题 - version 3.49: 支持百度千帆平台和文心一言 - version 3.48: 支持阿里达摩院通义千问,上海AI-Lab书生,讯飞星火 - version 3.46: 支持完全脱手操作的实时语音对话 diff --git a/version b/version index 2034d6d..369a800 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { "version": 3.50, "show_feature": true, - "new_feature": "支持自然语言插件调度(虚空终端) <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率 <-> 支持自定义APIKEY格式 <-> 临时修复theme的文件丢失问题 <-> 新增实时语音对话插件(自动断句,脱手对话) <-> 支持加载自定义的ChatGLM2微调模型 <-> 动态ChatBot窗口高度 <-> 修复Azure接口的BUG <-> 完善多语言模块" + "new_feature": "支持插件分类! <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" } From 9bd2023a8e820cd068ffce124f2bc17442ae3c1d Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Sun, 3 Sep 2023 15:40:41 +0800 Subject: [PATCH 14/14] revise version check --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index feebfb6..d475253 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,9 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 def main(): import gradio as gr - # if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt" + if gr.__version__ not in ['3.28.3','3.32.2']: assert False, "需要特殊依赖,请务必用 pip install -r requirements.txt 指令安装依赖,详情信息见requirements.txt" from request_llm.bridge_all import predict from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, load_chat_cookies, DummyWith - # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION') CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = get_conf('CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT')