Compare commits

...

146 Commits

Author SHA1 Message Date
qingxu fu
1335da4f45 Merge branch 'frontier' into master_autogen 2023-11-11 23:24:21 +08:00
qingxu fu
2d91e438d6 修正internlm输入设备bug 2023-11-11 23:22:50 +08:00
qingxu fu
a55bc0c07c AutoGen自动忽略重复的输入 2023-11-11 23:22:09 +08:00
qingxu fu
f7f6db831b 处理模型兼容的一些细节 2023-11-11 22:35:06 +08:00
qingxu fu
a655ce1f00 Merge branch 'frontier' into master_autogen 2023-11-11 22:03:20 +08:00
qingxu fu
28119e343c 将autogen大模型调用底层hook掉 2023-11-11 22:01:19 +08:00
qingxu fu
f75e39dc27 修复本地模型在Windows下的加载BUG 2023-11-11 21:11:55 +08:00
qingxu fu
e4409b94d1 修正拼写 report_execption -> report_exception #1220 2023-11-11 18:30:57 +08:00
qingxu fu
2570e4b997 remove revision 2023-11-11 18:17:58 +08:00
qingxu fu
2b917edf26 修复本地模型在windows上的兼容性 2023-11-11 17:58:17 +08:00
binary-husky
fcf04554c6 Merge pull request #1255 from xiangsam/master
[Feature] 更新精准翻译PDF文档(NOUGAT)插件
2023-11-11 14:07:22 +08:00
qingxu fu
107ea868e1 API2D自动对齐 2023-11-10 23:08:56 +08:00
qingxu fu
da7c03e868 图像修改 2023-11-10 22:54:55 +08:00
qingxu fu
42339a3e6b Merge branch 'master' into frontier 2023-11-10 22:54:24 +08:00
xiangsam
362b545a45 更改import nougat时机 2023-11-10 14:32:07 +00:00
Samrito
84b45dc4fb Merge branch 'binary-husky:master' into master 2023-11-10 22:07:41 +08:00
qingxu fu
f9fc02948a 更新分辨率提示 2023-11-10 21:04:21 +08:00
qingxu fu
0299b0f95f 支持DALLE3 2023-11-10 20:59:08 +08:00
xiangsam
33bf795c66 更新精准翻译PDF文档(NOUGAT)插件 2023-11-10 12:06:39 +00:00
binary-husky
caf45ef740 Merge pull request #1244 from awwaawwa/fix_gpt_35_16k_maxtoken
修改 gpt-3.5-turbo-16k 系列模型 max_token 为 16385
2023-11-10 12:55:02 +08:00
binary-husky
b49b272587 Merge pull request #1241 from Skyzayre/master
新加入1106两个模型的适配
2023-11-10 12:53:42 +08:00
qingxu fu
a1a91c25a5 移除重复项 2023-11-10 12:53:03 +08:00
qingxu fu
2912eaf082 Merge branch 'master' of https://github.com/Skyzayre/gpt_academic into Skyzayre-master2 2023-11-10 12:51:50 +08:00
binary-husky
795de492fe Merge pull request #1238 from samxiaowastaken/master
Add new API support
2023-11-10 12:41:14 +08:00
qingxu fu
0ff750b60a 修改缩进 2023-11-10 12:40:25 +08:00
qingxu fu
8ad2a2bb86 Merge branch 'master' of https://github.com/samxiaowastaken/gpt_academic into samxiaowastaken-master 2023-11-10 12:37:30 +08:00
binary-husky
12df41563a hide audio btn border 2023-11-08 18:40:36 +08:00
awwaawwa
8d94564e67 修改 gpt-3.5-turbo-16k 系列模型 max_token 为 16385
根据 https://platform.openai.com/docs/models/gpt-3-5 ,这个16k的3.5上下文窗口其实是16385
2023-11-07 15:59:07 +08:00
Skyzayre
736f1214ee Update bridge_all.py 2023-11-07 15:55:23 +08:00
binary-husky
e9cf3d3d12 version 3.57 2023-11-07 15:52:08 +08:00
binary-husky
996057e588 support chatglm3 2023-11-07 15:41:04 +08:00
binary-husky
804599bbc3 autogen 2023-11-07 15:36:05 +08:00
Skyzayre
ffe6c1403e Update bridge_chatgpt.py 2023-11-07 14:25:36 +08:00
Skyzayre
3a2466fe4e Update README_RS.md 2023-11-07 14:23:16 +08:00
Skyzayre
6c795809f7 Update README_JP.md 2023-11-07 14:23:01 +08:00
Skyzayre
3141cd392a Update README_FR.md 2023-11-07 14:22:46 +08:00
Skyzayre
77220002e0 Update README_EN.md 2023-11-07 14:22:29 +08:00
Skyzayre
cd40bf9ae2 Update README.md.Portuguese.md 2023-11-07 14:22:12 +08:00
Skyzayre
6c3405ba55 Update README.md.Korean.md 2023-11-07 14:21:52 +08:00
Skyzayre
bba3419ace Update README.md.Italian.md 2023-11-07 14:21:32 +08:00
Skyzayre
61cf2b32eb Update README.md.German.md 2023-11-07 14:21:08 +08:00
Skyzayre
3ed0e8012d Update bridge_all.py 2023-11-07 14:17:01 +08:00
Skyzayre
4d9256296d Update 多智能体.py 2023-11-07 14:13:37 +08:00
Skyzayre
0897057be1 Update README.md 2023-11-07 14:11:52 +08:00
Skyzayre
136e6aaa21 Update config.py 2023-11-07 14:08:24 +08:00
binary-husky
8e375b0ed2 support chatglm3 2023-11-07 14:07:30 +08:00
binary-husky
5192d316f0 Merge branch 'frontier' 2023-11-07 11:40:27 +08:00
binary-husky
245585be81 Update README.md 2023-11-07 10:39:35 +08:00
Yao Xiao
4824905592 Add new API support 2023-11-07 09:48:01 +08:00
binary-husky
5566ba8257 Merge pull request #1215 from ZornWang/ERNIE_Bot_4
[Feature] 添加百度千帆文心4.0大模型支持
2023-11-01 22:29:33 +08:00
binary-husky
8c4a753b65 Merge pull request #1222 from ji-jinlong/master
Update 理解PDF文档内容.py
2023-11-01 22:26:55 +08:00
binary-husky
f016323b8a Update 理解PDF文档内容.py 2023-11-01 22:26:46 +08:00
binary-husky
cd9f2ec402 Update README.md 2023-11-01 22:25:27 +08:00
ji-jinlong
ca7ff47fcb Update 理解PDF文档内容.py 2023-11-01 16:05:57 +08:00
binary-husky
09857ea455 解除本地模型的若干并发问题 2023-10-31 20:37:07 +08:00
binary-husky
17cf47dcd6 防止多线程数据交叉 2023-10-31 18:02:14 +08:00
binary-husky
136162ec0d better local model interaction 2023-10-31 16:18:27 +08:00
binary-husky
08f036aafd 支持chatglm3 2023-10-31 03:08:50 +08:00
Zorn Wang
9fb29f249b Feature: 添加百度千帆文心4.0大模型支持 2023-10-30 19:20:05 +08:00
binary-husky
9a1aff5bb6 修复get_conf接口 2023-10-30 11:10:05 +08:00
binary-husky
f3f90f7b90 Update README.md 2023-10-30 01:10:45 +08:00
binary-husky
527f9d28ad change get_conf 2023-10-29 00:34:40 +08:00
binary-husky
12b2a229b6 移除调试打印 2023-10-28 20:15:59 +08:00
binary-husky
40a065ce04 Merge branch 'master' into frontier 2023-10-28 20:09:49 +08:00
binary-husky
b14d4de0b1 将默认系统提示词转移到Config中 2023-10-28 20:08:50 +08:00
binary-husky
e64c26e617 紧急修复报错异常 2023-10-28 19:53:05 +08:00
binary-husky
0b1e599b01 紧急修复报错异常 2023-10-28 19:43:48 +08:00
binary-husky
127385b846 接入新模型 2023-10-28 19:23:43 +08:00
binary-husky
cf085565a7 rename folder 2023-10-28 17:44:17 +08:00
binary-husky
5a530df4f2 修复autogen接口的问题 2023-10-28 17:41:22 +08:00
binary-husky
b4c7b26f63 Merge branch 'master' into frontier 2023-10-28 14:32:12 +08:00
binary-husky
8bdcc4ff28 修复对一些第三方接口的兼容性 2023-10-28 14:32:03 +08:00
binary-husky
e596bb6fff 修复AZURE_CFG_ARRAY使用时不给定apikey报错的问题 2023-10-28 00:29:49 +08:00
binary-husky
50ecb45d63 Merge pull request #1173 from Kilig947/azure_multiple_models
Azure 支持部署多个模型
2023-10-27 23:36:05 +08:00
binary-husky
349c399967 Merge branch 'frontier' into azure_multiple_models 2023-10-27 23:35:50 +08:00
binary-husky
103d05d242 增加一个Azure配置的Array 2023-10-27 23:29:18 +08:00
binary-husky
d0589209cc Merge branch 'azure_multiple_models' of https://github.com/Kilig947/gpt_academic into Kilig947-azure_multiple_models 2023-10-27 22:41:51 +08:00
binary-husky
8faf69c41e Merge branch 'master' into frontier 2023-10-27 10:25:11 +08:00
binary-husky
f7a332eee7 Merge pull request #1201 from shao0099876/master
修复了一个导致无法加载未量化的ChatGLM2 fine-tuning模型的问题
2023-10-27 10:00:48 +08:00
shao0099876
f6e34d9621 修复了一个导致无法加载未量化的ChatGLM2 fine-tuning模型的问题(quantization_bit=0) 2023-10-26 14:38:58 +00:00
qingxu fu
706a239232 Newbing组件已不再维护 2023-10-25 11:56:20 +08:00
qingxu fu
00076cc6f4 支持讯飞星火v3 (sparkv3) 2023-10-25 11:48:28 +08:00
binary-husky
5dd3f4ad6d rename 2023-10-23 21:50:47 +08:00
binary-husky
65e202881a add option to skip new translation 2023-10-23 21:12:36 +08:00
binary-husky
27c4e3ef4f 优化autogen的使用 2023-10-23 01:56:18 +08:00
binary-husky
e2b3c47186 Version 3.56 - Merge branch 'frontier' 2023-10-22 23:24:41 +08:00
binary-husky
a14ef78d52 容忍tex文件的缺失 2023-10-22 00:05:48 +08:00
binary-husky
b88e577eb5 update translation 2023-10-21 19:15:23 +08:00
binary-husky
991e41b313 change default path to relative 2023-10-21 00:27:55 +08:00
binary-husky
ff2bc64d57 图片交互显示 2023-10-20 23:56:24 +08:00
binary-husky
218f0c445e 微调Autogen代码结构 2023-10-20 23:18:32 +08:00
binary-husky
7ee0c94924 接入autogen 2023-10-20 21:31:50 +08:00
binary-husky
3531e7f23f 修正提示 2023-10-20 15:40:36 +08:00
binary-husky
d99f4681f0 修正提示 2023-10-20 15:39:50 +08:00
binary-husky
f2b2ccd577 Merge branch 'master' into frontier 2023-10-20 10:47:40 +08:00
binary-husky
c18a235d33 微调HTML 2023-10-20 10:43:05 +08:00
binary-husky
6c87c55a8a 微调HTML样式 2023-10-20 10:43:04 +08:00
binary-husky
f925fe7692 添加对NOUGAT的代理设置 2023-10-20 10:43:04 +08:00
qingxu fu
af83c43fb0 补充缺失摘要的措施 2023-10-20 10:43:04 +08:00
qingxu fu
4305ee0313 微调HTML汇报样式 2023-10-20 10:43:04 +08:00
binary-husky
a6e7bbbd22 修改缩进 2023-10-20 10:43:04 +08:00
binary-husky
62c02dfa86 修复warmup模块的延迟问题 2023-10-20 10:43:04 +08:00
binary-husky
a2ebbafb77 微调提示 2023-10-20 10:43:04 +08:00
binary-husky
a915a2ddd1 Grobid负载均衡 2023-10-20 10:43:04 +08:00
Menghuan1918
537c15b354 在proxies返回空时会首先尝试直接连接 2023-10-20 10:43:04 +08:00
binary-husky
73ed92af59 Update GithubAction+NoLocal+Latex 2023-10-20 10:43:04 +08:00
Skyzayre
88303b6f78 Update Dockerfile
gradio已经更新到3.32.6,但是Dockerfile中仍然是3.32.2
2023-10-20 10:42:31 +08:00
binary-husky
120d4ad556 Update README.md 2023-10-20 10:42:31 +08:00
binary-husky
3410bd9b1d Update README.md 2023-10-19 16:05:12 +08:00
binary-husky
20e3eee6e7 Update GithubAction+NoLocal+Latex 2023-10-18 16:23:28 +08:00
binary-husky
775b07dbcc 为Dockerfile添加更多注释 2023-10-18 11:15:35 +08:00
binary-husky
560d4e2cb1 修正Dockerfile中的错误 2023-10-18 11:10:38 +08:00
qingxu fu
4ad432e1da 新版HTML报告页面 2023-10-16 22:13:59 +08:00
binary-husky
32ddcd067a Merge branch 'master' of github.com:binary-husky/chatgpt_academic 2023-10-16 00:05:53 +08:00
binary-husky
98ef658307 修复warmup模块的延迟问题 2023-10-16 00:05:31 +08:00
w_xiaolizu
1e2bcb8189 Azure 支持部署多个模型 2023-10-15 23:19:07 +08:00
binary-husky
a4de91d000 修改缩进 2023-10-15 22:53:57 +08:00
binary-husky
1bb437a5d0 微调提示 2023-10-15 21:17:00 +08:00
binary-husky
4421219c2b Merge branch 'frontier' 2023-10-15 20:56:49 +08:00
binary-husky
ea28db855d 完善自定义菜单 2023-10-15 20:54:16 +08:00
binary-husky
5aea7b3d09 多线程运行微调 2023-10-15 19:13:25 +08:00
binary-husky
5274117cf1 缺失摘要时,插入伪摘要 2023-10-14 23:48:37 +08:00
binary-husky
673faf8cef Grobid负载均衡 2023-10-14 19:59:35 +08:00
binary-husky
130ae31d55 Merge pull request #1168 from Menghuan1918/master
fix bug  #1167 学术小助手在proxies返回空时会首先尝试直接连接
2023-10-13 17:02:01 +08:00
Menghuan1918
c3abc46d4d 在proxies返回空时会首先尝试直接连接 2023-10-13 15:23:06 +08:00
binary-husky
4df75d49ad 兼容一些第三方代理 2023-10-12 23:42:45 +08:00
binary-husky
9ea0fe4de2 Update GithubAction+NoLocal+Latex 2023-10-12 21:23:15 +08:00
binary-husky
8698c5a80f Merge pull request #1159 from Skyzayre/patch-1
Update Dockerfile
2023-10-11 17:18:28 +08:00
binary-husky
383f7f4f77 add webrtcvad dependency 2023-10-11 15:51:34 +08:00
binary-husky
34d784df79 12 2023-10-11 15:48:25 +08:00
binary-husky
662bebfc02 SSL 2023-10-11 15:34:06 +08:00
binary-husky
0c3b00fc6b cookie space 2023-10-11 12:33:50 +08:00
binary-husky
b6e370e8c9 ymp 2023-10-11 11:30:34 +08:00
binary-husky
71ea8e584a 自定义基础功能区按钮 2023-10-11 11:21:41 +08:00
Skyzayre
a5491b9199 Update Dockerfile
gradio已经更新到3.32.6,但是Dockerfile中仍然是3.32.2
2023-10-11 00:26:16 +08:00
binary-husky
6f383c1dc8 支持自定义基础功能区 2023-10-11 00:14:56 +08:00
binary-husky
500a0cbd16 大幅优化语音助手 2023-10-09 01:18:05 +08:00
binary-husky
1ef6730369 Update README.md 2023-10-08 23:14:07 +08:00
binary-husky
491174095a 更新docker-compose说明 2023-10-07 11:59:06 +08:00
binary-husky
02c270410c 减小Latex容器体积 2023-10-06 11:44:10 +08:00
binary-husky
89eec21f27 随机选择, 绕过openai访问频率限制 2023-10-06 10:50:41 +08:00
binary-husky
49cea97822 启动主题自动转换 2023-10-06 10:36:30 +08:00
binary-husky
6310b65d70 重新编译Gradio优化使用体验 2023-10-06 10:32:03 +08:00
binary-husky
93c76e1809 更新内置gradio版本 2023-10-06 09:54:07 +08:00
binary-husky
f64cf7a3d1 update translation matrix 2023-10-02 14:24:01 +08:00
binary-husky
fdffbee1b0 Update toolbox.py 2023-09-30 09:56:30 +08:00
124 changed files with 3315 additions and 1128 deletions

6
.gitignore vendored
View File

@@ -146,9 +146,9 @@ debug*
private* private*
crazy_functions/test_project/pdf_and_word crazy_functions/test_project/pdf_and_word
crazy_functions/test_samples crazy_functions/test_samples
request_llm/jittorllms request_llms/jittorllms
multi-language multi-language
request_llm/moss request_llms/moss
media media
flagged flagged
request_llm/ChatGLM-6b-onnx-u8s8 request_llms/ChatGLM-6b-onnx-u8s8

View File

@@ -1,34 +1,35 @@
# 此Dockerfile适用于“无本地模型”的环境构建如果需要使用chatglm等本地模型或者latex运行依赖请参考 docker-compose.yml # 此Dockerfile适用于“无本地模型”的迷你运行环境构建
# 如何构建: 先修改 `config.py` 然后 `docker build -t gpt-academic . ` # 如果需要使用chatglm等本地模型或者latex运行依赖请参考 docker-compose.yml
# 如何运行(Linux下): `docker run --rm -it --net=host gpt-academic ` # - 如何构建: 先修改 `config.py` 然后 `docker build -t gpt-academic . `
# 如何运行(其他操作系统选择任意一个固定端口50923): `docker run --rm -it -e WEB_PORT=50923 -p 50923:50923 gpt-academic ` # - 如何运行(Linux下): `docker run --rm -it --net=host gpt-academic `
# - 如何运行(其他操作系统选择任意一个固定端口50923): `docker run --rm -it -e WEB_PORT=50923 -p 50923:50923 gpt-academic `
FROM python:3.11 FROM python:3.11
# 非必要步骤更换pip源 # 非必要步骤更换pip源 (以下三行,可以删除)
RUN echo '[global]' > /etc/pip.conf && \ RUN echo '[global]' > /etc/pip.conf && \
echo 'index-url = https://mirrors.aliyun.com/pypi/simple/' >> /etc/pip.conf && \ echo 'index-url = https://mirrors.aliyun.com/pypi/simple/' >> /etc/pip.conf && \
echo 'trusted-host = mirrors.aliyun.com' >> /etc/pip.conf echo 'trusted-host = mirrors.aliyun.com' >> /etc/pip.conf
# 进入工作路径 # 进入工作路径(必要)
WORKDIR /gpt WORKDIR /gpt
# 安装大部分依赖利用Docker缓存加速以后的构建 # 安装大部分依赖利用Docker缓存加速以后的构建 (以下三行,可以删除)
COPY requirements.txt ./ COPY requirements.txt ./
COPY ./docs/gradio-3.32.2-py3-none-any.whl ./docs/gradio-3.32.2-py3-none-any.whl COPY ./docs/gradio-3.32.6-py3-none-any.whl ./docs/gradio-3.32.6-py3-none-any.whl
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
# 装载项目文件,安装剩余依赖 # 装载项目文件,安装剩余依赖(必要)
COPY . . COPY . .
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
# 非必要步骤,用于预热模块 # 非必要步骤,用于预热模块(可以删除)
RUN python3 -c 'from check_proxy import warm_up_modules; warm_up_modules()' RUN python3 -c 'from check_proxy import warm_up_modules; warm_up_modules()'
# 启动 # 启动(必要)
CMD ["python3", "-u", "main.py"] CMD ["python3", "-u", "main.py"]

111
README.md
View File

@@ -1,24 +1,27 @@
> **Note** > **Note**
> >
> 2023.7.8: Gradio, Pydantic依赖调整已修改 `requirements.txt`。请及时**更新代码**,安装依赖时,请严格选择`requirements.txt`中**指定的版本** > 2023.10.28: 紧急修复了若干问题,安装依赖时,请选择`requirements.txt`中**指定的版本**
> >
> `pip install -r requirements.txt` > `pip install -r requirements.txt`
>
> 2023.11.7: 本项目开源免费,近期发现有人蔑视开源协议并利用本项目违规圈钱,请提高警惕,谨防上当受骗。
# <div align=center><img src="docs/logo.png" width="40"> GPT 学术优化 (GPT Academic)</div> # <div align=center><img src="docs/logo.png" width="40"> GPT 学术优化 (GPT Academic)</div>
**如果喜欢这个项目请给它一个Star如果您发明了好用的快捷键或函数插件欢迎发pull requests** **如果喜欢这个项目请给它一个Star如果您发明了好用的快捷键或插件欢迎发pull requests**
If you like this project, please give it a Star. If you've come up with more useful academic shortcuts or functional plugins, feel free to open an issue or pull request. We also have a README in [English|](docs/README_EN.md)[日本語|](docs/README_JP.md)[한국어|](https://github.com/mldljyh/ko_gpt_academic)[Русский|](docs/README_RS.md)[Français](docs/README_FR.md) translated by this project itself. If you like this project, please give it a Star. We also have a README in [English|](docs/README_EN.md)[日本語|](docs/README_JP.md)[한국어|](https://github.com/mldljyh/ko_gpt_academic)[Русский|](docs/README_RS.md)[Français](docs/README_FR.md) translated by this project itself.
To translate this project to arbitrary language with GPT, read and run [`multi_language.py`](multi_language.py) (experimental). To translate this project to arbitrary language with GPT, read and run [`multi_language.py`](multi_language.py) (experimental).
> **Note** > **Note**
> >
> 1.请注意只有 **高亮** 标识的函数插件(按钮)才支持读取文件,部分插件位于插件区的**下拉菜单**中。另外我们以**最高优先级**欢迎和处理任何新插件的PR。 > 1.请注意只有 **高亮** 标识的插件(按钮)才支持读取文件,部分插件位于插件区的**下拉菜单**中。另外我们以**最高优先级**欢迎和处理任何新插件的PR。
> >
> 2.本项目中每个文件的功能都在[自译解报告`self_analysis.md`](https://github.com/binary-husky/gpt_academic/wiki/GPTAcademic项目自译解报告)详细说明。随着版本的迭代您也可以随时自行点击相关函数插件调用GPT重新生成项目的自我解析报告。常见问题[`wiki`](https://github.com/binary-husky/gpt_academic/wiki)。[安装方法](#installation) | [配置说明](https://github.com/binary-husky/gpt_academic/wiki/%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E)。 > 2.本项目中每个文件的功能都在[自译解报告`self_analysis.md`](https://github.com/binary-husky/gpt_academic/wiki/GPTAcademic项目自译解报告)详细说明。随着版本的迭代您也可以随时自行点击相关函数插件调用GPT重新生成项目的自我解析报告。常见问题[`wiki`](https://github.com/binary-husky/gpt_academic/wiki)。[常规安装方法](#installation) | [一键安装脚本](https://github.com/binary-husky/gpt_academic/releases) | [配置说明](https://github.com/binary-husky/gpt_academic/wiki/项目配置说明)。
> >
> 3.本项目兼容并鼓励尝试国产大语言模型ChatGLM和Moss等等。支持多个api-key共存可在配置文件中填写如`API_KEY="openai-key1,openai-key2,azure-key3,api2d-key4"`。需要临时更换`API_KEY`时,在输入区输入临时的`API_KEY`然后回车键提交后即可生效。 > 3.本项目兼容并鼓励尝试国产大语言模型ChatGLM等。支持多个api-key共存可在配置文件中填写如`API_KEY="openai-key1,openai-key2,azure-key3,api2d-key4"`。需要临时更换`API_KEY`时,在输入区输入临时的`API_KEY`然后回车键提交后即可生效。
@@ -61,7 +64,7 @@ Latex论文一键校对 | [函数插件] 仿Grammarly对Latex文章进行语法
- 新界面(修改`config.py`中的LAYOUT选项即可实现“左右布局”和“上下布局”的切换 - 新界面(修改`config.py`中的LAYOUT选项即可实现“左右布局”和“上下布局”的切换
<div align="center"> <div align="center">
<img src="https://user-images.githubusercontent.com/96192199/230361456-61078362-a966-4eb5-b49e-3c62ef18b860.gif" width="700" > <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/d81137c3-affd-4cd1-bb5e-b15610389762" width="700" >
</div> </div>
@@ -101,16 +104,16 @@ cd gpt_academic
2. 配置API_KEY 2. 配置API_KEY
在`config.py`中配置API KEY等设置[点击查看特殊网络环境设置方法](https://github.com/binary-husky/gpt_academic/issues/1) 。[Wiki页面](https://github.com/binary-husky/gpt_academic/wiki/%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E)。 在`config.py`中配置API KEY等设置[点击查看特殊网络环境设置方法](https://github.com/binary-husky/gpt_academic/issues/1) 。[Wiki页面](https://github.com/binary-husky/gpt_academic/wiki/项目配置说明)。
「 程序会优先检查是否存在名为`config_private.py`的私密配置文件,并用其中的配置覆盖`config.py`的同名配置。如您能理解该读取逻辑,我们强烈建议您在`config.py`旁边创建一个名为`config_private.py`的新配置文件,并把`config.py`中的配置转移(复制)到`config_private.py`中(仅复制您修改过的配置条目即可)。 」 「 程序会优先检查是否存在名为`config_private.py`的私密配置文件,并用其中的配置覆盖`config.py`的同名配置。如您能理解该读取逻辑,我们强烈建议您在`config.py`旁边创建一个名为`config_private.py`的新配置文件,并把`config.py`中的配置转移(复制)到`config_private.py`中(仅复制您修改过的配置条目即可)。 」
「 支持通过`环境变量`配置项目,环境变量的书写格式参考`docker-compose.yml`文件或者我们的[Wiki页面](https://github.com/binary-husky/gpt_academic/wiki/%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E8%AF%B4%E6%98%8E)。配置读取优先级: `环境变量` > `config_private.py` > `config.py`。 」 「 支持通过`环境变量`配置项目,环境变量的书写格式参考`docker-compose.yml`文件或者我们的[Wiki页面](https://github.com/binary-husky/gpt_academic/wiki/项目配置说明)。配置读取优先级: `环境变量` > `config_private.py` > `config.py`。 」
3. 安装依赖 3. 安装依赖
```sh ```sh
# 选择I: 如熟悉pythonpython版本3.9以上,越新越好),备注使用官方pip源或者阿里pip源,临时换源方法python -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ # 选择I: 如熟悉python, python>=3.9备注使用官方pip源或者阿里pip源, 临时换源方法python -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
python -m pip install -r requirements.txt python -m pip install -r requirements.txt
# 选择II: 使用Anaconda步骤也是类似的 (https://www.bilibili.com/video/BV1rc411W7Dr) # 选择II: 使用Anaconda步骤也是类似的 (https://www.bilibili.com/video/BV1rc411W7Dr)
@@ -126,17 +129,17 @@ python -m pip install -r requirements.txt # 这个步骤和pip安装一样的步
【可选步骤】如果需要支持清华ChatGLM2/复旦MOSS作为后端需要额外安装更多依赖前提条件熟悉Python + 用过Pytorch + 电脑配置够强): 【可选步骤】如果需要支持清华ChatGLM2/复旦MOSS作为后端需要额外安装更多依赖前提条件熟悉Python + 用过Pytorch + 电脑配置够强):
```sh ```sh
# 【可选步骤I】支持清华ChatGLM2。清华ChatGLM备注如果遇到"Call ChatGLM fail 不能正常加载ChatGLM的参数" 错误,参考如下: 1以上默认安装的为torch+cpu版使用cuda需要卸载torch重新安装torch+cuda 2如因本机配置不够无法加载模型可以修改request_llm/bridge_chatglm.py中的模型精度, 将 AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) 都修改为 AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # 【可选步骤I】支持清华ChatGLM2。清华ChatGLM备注如果遇到"Call ChatGLM fail 不能正常加载ChatGLM的参数" 错误,参考如下: 1以上默认安装的为torch+cpu版使用cuda需要卸载torch重新安装torch+cuda 2如因本机配置不够无法加载模型可以修改request_llm/bridge_chatglm.py中的模型精度, 将 AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) 都修改为 AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# 【可选步骤II】支持复旦MOSS # 【可选步骤II】支持复旦MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llm/moss # 注意执行此行代码时,必须处于项目根路径 git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llms/moss # 注意执行此行代码时,必须处于项目根路径
# 【可选步骤III】支持RWKV Runner # 【可选步骤III】支持RWKV Runner
参考wikihttps://github.com/binary-husky/gpt_academic/wiki/%E9%80%82%E9%85%8DRWKV-Runner 参考wikihttps://github.com/binary-husky/gpt_academic/wiki/%E9%80%82%E9%85%8DRWKV-Runner
# 【可选步骤IV】确保config.py配置文件的AVAIL_LLM_MODELS包含了期望的模型目前支持的全部模型如下(jittorllms系列目前仅支持docker方案) # 【可选步骤IV】确保config.py配置文件的AVAIL_LLM_MODELS包含了期望的模型目前支持的全部模型如下(jittorllms系列目前仅支持docker方案)
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]
``` ```
</p> </p>
@@ -151,11 +154,11 @@ python main.py
### 安装方法II使用Docker ### 安装方法II使用Docker
0. 部署项目的全部能力这个是包含cuda和latex的大型镜像。如果您网速慢、硬盘小或没有显卡,则不推荐使用这个建议使用方案1需要熟悉[Nvidia Docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-on-ubuntu-and-debian)运行时 0. 部署项目的全部能力这个是包含cuda和latex的大型镜像。如果您网速慢、硬盘小,则不推荐使用这个)
[![fullcapacity](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-all-capacity.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml) [![fullcapacity](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-all-capacity.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-all-capacity.yml)
``` sh ``` sh
# 修改docker-compose.yml保留方案0并删除其他方案。修改docker-compose.yml中方案0的配置参考其中注释即可 # 修改docker-compose.yml保留方案0并删除其他方案。然后运行:
docker-compose up docker-compose up
``` ```
@@ -165,7 +168,7 @@ docker-compose up
[![basicaudio](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml) [![basicaudio](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-audio-assistant.yml)
``` sh ``` sh
# 修改docker-compose.yml保留方案1并删除其他方案。修改docker-compose.yml中方案1的配置参考其中注释即可 # 修改docker-compose.yml保留方案1并删除其他方案。然后运行:
docker-compose up docker-compose up
``` ```
@@ -175,48 +178,30 @@ P.S. 如果需要依赖Latex的插件功能请见Wiki。另外您也可以
[![chatglm](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-chatglm.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-chatglm.yml) [![chatglm](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-chatglm.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-chatglm.yml)
``` sh ``` sh
# 修改docker-compose.yml保留方案2并删除其他方案。修改docker-compose.yml中方案2的配置参考其中注释即可 # 修改docker-compose.yml保留方案2并删除其他方案。然后运行:
docker-compose up
```
3. ChatGPT + LLAMA + 盘古 + RWKV需要熟悉[Nvidia Docker](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#installing-on-ubuntu-and-debian)运行时)
[![jittorllms](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-jittorllms.yml/badge.svg?branch=master)](https://github.com/binary-husky/gpt_academic/actions/workflows/build-with-jittorllms.yml)
``` sh
# 修改docker-compose.yml保留方案3并删除其他方案。修改docker-compose.yml中方案3的配置参考其中注释即可
docker-compose up docker-compose up
``` ```
### 安装方法III其他部署姿势 ### 安装方法III其他部署姿势
1. 一键运行脚本。 1. **Windows一键运行脚本**
完全不熟悉python环境的Windows用户可以下载[Release](https://github.com/binary-husky/gpt_academic/releases)中发布的一键运行脚本安装无本地模型的版本。 完全不熟悉python环境的Windows用户可以下载[Release](https://github.com/binary-husky/gpt_academic/releases)中发布的一键运行脚本安装无本地模型的版本。
脚本的贡献来源是[oobabooga](https://github.com/oobabooga/one-click-installers)。 脚本的贡献来源是[oobabooga](https://github.com/oobabooga/one-click-installers)。
2. 使用docker-compose运行。 2. 使用第三方API、Azure等、文心一言、星火等见[Wiki页面](https://github.com/binary-husky/gpt_academic/wiki/项目配置说明)
请阅读docker-compose.yml后按照其中的提示操作即可
3. 如何使用反代URL 3. 云服务器远程部署避坑指南。
按照`config.py`中的说明配置API_URL_REDIRECT即可。 请访问[云服务器远程部署wiki](https://github.com/binary-husky/gpt_academic/wiki/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%9C%E7%A8%8B%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)
4. 微软云AzureAPI 4. 一些新型的部署平台或方法
按照`config.py`中的说明配置即可AZURE_ENDPOINT等四个配置 - 使用Sealos[一键部署](https://github.com/binary-husky/gpt_academic/issues/993)。
- 使用WSL2Windows Subsystem for Linux 子系统)。请访问[部署wiki-2](https://github.com/binary-husky/gpt_academic/wiki/%E4%BD%BF%E7%94%A8WSL2%EF%BC%88Windows-Subsystem-for-Linux-%E5%AD%90%E7%B3%BB%E7%BB%9F%EF%BC%89%E9%83%A8%E7%BD%B2)
5. 远程云服务器部署(需要云服务器知识与经验)。 - 如何在二级网址(如`http://localhost/subpath`)下运行。请访问[FastAPI运行说明](docs/WithFastapi.md)
请访问[部署wiki-1](https://github.com/binary-husky/gpt_academic/wiki/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%9C%E7%A8%8B%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)
6. 使用Sealos[一键部署](https://github.com/binary-husky/gpt_academic/issues/993)。
7. 使用WSL2Windows Subsystem for Linux 子系统)。
请访问[部署wiki-2](https://github.com/binary-husky/gpt_academic/wiki/%E4%BD%BF%E7%94%A8WSL2%EF%BC%88Windows-Subsystem-for-Linux-%E5%AD%90%E7%B3%BB%E7%BB%9F%EF%BC%89%E9%83%A8%E7%BD%B2)
8. 如何在二级网址(如`http://localhost/subpath`)下运行。
请访问[FastAPI运行说明](docs/WithFastapi.md)
# Advanced Usage # Advanced Usage
### I自定义新的便捷按钮学术快捷键 ### I自定义新的便捷按钮学术快捷键
任意文本编辑器打开`core_functional.py`,添加条目如下,然后重启程序即可。(如按钮已经添加成功并可见,那么前缀、后缀都支持热修改,无需重启程序即可生效。) 任意文本编辑器打开`core_functional.py`,添加条目如下,然后重启程序。(如按钮已存在,那么前缀、后缀都支持热修改,无需重启程序即可生效。)
例如 例如
``` ```
"超级英译中": { "超级英译中": {
@@ -232,14 +217,13 @@ docker-compose up
</div> </div>
### II自定义函数插件 ### II自定义函数插件
编写强大的函数插件来执行任何你想得到的和想不到的任务。 编写强大的函数插件来执行任何你想得到的和想不到的任务。
本项目的插件编写、调试难度很低只要您具备一定的python基础知识就可以仿照我们提供的模板实现自己的插件功能。 本项目的插件编写、调试难度很低只要您具备一定的python基础知识就可以仿照我们提供的模板实现自己的插件功能。
详情请参考[函数插件指南](https://github.com/binary-husky/gpt_academic/wiki/%E5%87%BD%E6%95%B0%E6%8F%92%E4%BB%B6%E6%8C%87%E5%8D%97)。 详情请参考[函数插件指南](https://github.com/binary-husky/gpt_academic/wiki/%E5%87%BD%E6%95%B0%E6%8F%92%E4%BB%B6%E6%8C%87%E5%8D%97)。
# Latest Update # Updates
### I新功能动态 ### I动态
1. 对话保存功能。在函数插件区调用 `保存当前的对话` 即可将当前对话保存为可读+可复原的html文件 1. 对话保存功能。在函数插件区调用 `保存当前的对话` 即可将当前对话保存为可读+可复原的html文件
另外在函数插件区(下拉菜单)调用 `载入对话历史存档` ,即可还原之前的会话。 另外在函数插件区(下拉菜单)调用 `载入对话历史存档` ,即可还原之前的会话。
@@ -280,28 +264,23 @@ Tip不指定文件直接点击 `载入对话历史存档` 可以查看历史h
<img src="https://user-images.githubusercontent.com/96192199/236432361-67739153-73e8-43fe-8111-b61296edabd9.png" width="500" > <img src="https://user-images.githubusercontent.com/96192199/236432361-67739153-73e8-43fe-8111-b61296edabd9.png" width="500" >
</div> </div>
7. 新增MOSS大语言模型支持 7. OpenAI图像生成
<div align="center">
<img src="https://user-images.githubusercontent.com/96192199/236639178-92836f37-13af-4fdd-984d-b4450fe30336.png" width="500" >
</div>
8. OpenAI图像生成
<div align="center"> <div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/bc7ab234-ad90-48a0-8d62-f703d9e74665" width="500" > <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/bc7ab234-ad90-48a0-8d62-f703d9e74665" width="500" >
</div> </div>
9. OpenAI音频解析与总结 8. OpenAI音频解析与总结
<div align="center"> <div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/709ccf95-3aee-498a-934a-e1c22d3d5d5b" width="500" > <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/709ccf95-3aee-498a-934a-e1c22d3d5d5b" width="500" >
</div> </div>
10. Latex全文校对纠错 9. Latex全文校对纠错
<div align="center"> <div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/651ccd98-02c9-4464-91e1-77a6b7d1b033" height="200" > ===> <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/651ccd98-02c9-4464-91e1-77a6b7d1b033" height="200" > ===>
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/476f66d9-7716-4537-b5c1-735372c25adb" height="200"> <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/476f66d9-7716-4537-b5c1-735372c25adb" height="200">
</div> </div>
11. 语言、主题切换 10. 语言、主题切换
<div align="center"> <div align="center">
<img src="https://github.com/binary-husky/gpt_academic/assets/96192199/b6799499-b6fb-4f0c-9c8e-1b441872f4e8" width="500" > <img src="https://github.com/binary-husky/gpt_academic/assets/96192199/b6799499-b6fb-4f0c-9c8e-1b441872f4e8" width="500" >
</div> </div>
@@ -309,7 +288,11 @@ Tip不指定文件直接点击 `载入对话历史存档` 可以查看历史h
### II版本: ### II版本:
- version 3.60todo: 优化虚空终端,引入code interpreter和更多插件 - version 3.60todo: 优化虚空终端,引入AutoGen作为新一代插件的基石
- version 3.57: 支持GLM3星火v3文心一言v4修复本地模型的并发BUG
- version 3.56: 支持动态追加基础功能按钮新汇报PDF汇总页面
- version 3.55: 重构前端界面,引入悬浮窗口与菜单栏
- version 3.54: 新增动态代码解释器Code Interpreter待完善
- version 3.53: 支持动态选择不同界面主题,提高稳定性&解决多用户冲突问题 - version 3.53: 支持动态选择不同界面主题,提高稳定性&解决多用户冲突问题
- version 3.50: 使用自然语言调用本项目的所有函数插件虚空终端支持插件分类改进UI设计新主题 - version 3.50: 使用自然语言调用本项目的所有函数插件虚空终端支持插件分类改进UI设计新主题
- version 3.49: 支持百度千帆平台和文心一言 - version 3.49: 支持百度千帆平台和文心一言
@@ -331,7 +314,7 @@ Tip不指定文件直接点击 `载入对话历史存档` 可以查看历史h
- version 2.0: 引入模块化函数插件 - version 2.0: 引入模块化函数插件
- version 1.0: 基础功能 - version 1.0: 基础功能
gpt_academic开发者QQ群-2610599535 GPT Academic开发者QQ群`610599535`
- 已知问题 - 已知问题
- 某些浏览器翻译插件干扰此软件前端的运行 - 某些浏览器翻译插件干扰此软件前端的运行
@@ -342,7 +325,13 @@ gpt_academic开发者QQ群-2610599535
1. `Chuanhu-Small-and-Beautiful` [网址](https://github.com/GaiZhenbiao/ChuanhuChatGPT/) 1. `Chuanhu-Small-and-Beautiful` [网址](https://github.com/GaiZhenbiao/ChuanhuChatGPT/)
### IV参考与学习 ### IV本项目的开发分支
1. `master` 分支: 主分支,稳定版
2. `frontier` 分支: 开发分支,测试版
### V参考与学习
``` ```
代码中参考了很多其他优秀项目中的设计,顺序不分先后: 代码中参考了很多其他优秀项目中的设计,顺序不分先后:

View File

@@ -46,7 +46,7 @@ def backup_and_download(current_version, remote_version):
return new_version_dir return new_version_dir
os.makedirs(new_version_dir) os.makedirs(new_version_dir)
shutil.copytree('./', backup_dir, ignore=lambda x, y: ['history']) shutil.copytree('./', backup_dir, ignore=lambda x, y: ['history'])
proxies, = get_conf('proxies') proxies = get_conf('proxies')
r = requests.get( r = requests.get(
'https://github.com/binary-husky/chatgpt_academic/archive/refs/heads/master.zip', proxies=proxies, stream=True) 'https://github.com/binary-husky/chatgpt_academic/archive/refs/heads/master.zip', proxies=proxies, stream=True)
zip_file_path = backup_dir+'/master.zip' zip_file_path = backup_dir+'/master.zip'
@@ -113,7 +113,7 @@ def auto_update(raise_error=False):
import requests import requests
import time import time
import json import json
proxies, = get_conf('proxies') proxies = get_conf('proxies')
response = requests.get( response = requests.get(
"https://raw.githubusercontent.com/binary-husky/chatgpt_academic/master/version", proxies=proxies, timeout=5) "https://raw.githubusercontent.com/binary-husky/chatgpt_academic/master/version", proxies=proxies, timeout=5)
remote_json_data = json.loads(response.text) remote_json_data = json.loads(response.text)
@@ -156,7 +156,7 @@ def auto_update(raise_error=False):
def warm_up_modules(): def warm_up_modules():
print('正在执行一些模块的预热...') print('正在执行一些模块的预热...')
from toolbox import ProxyNetworkActivate from toolbox import ProxyNetworkActivate
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
with ProxyNetworkActivate("Warmup_Modules"): with ProxyNetworkActivate("Warmup_Modules"):
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
enc.encode("模块预热", disallowed_special=()) enc.encode("模块预热", disallowed_special=())
@@ -167,5 +167,5 @@ if __name__ == '__main__':
import os import os
os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
from toolbox import get_conf from toolbox import get_conf
proxies, = get_conf('proxies') proxies = get_conf('proxies')
check_proxy(proxies) check_proxy(proxies)

View File

@@ -48,6 +48,11 @@ DEFAULT_WORKER_NUM = 3
THEME = "Default" THEME = "Default"
AVAIL_THEMES = ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast", "Gstaff/Xkcd", "NoCrypt/Miku"] AVAIL_THEMES = ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast", "Gstaff/Xkcd", "NoCrypt/Miku"]
# 默认的系统提示词system prompt
INIT_SYS_PROMPT = "Serve me as a writing and programming assistant."
# 对话窗的高度 仅在LAYOUT="TOP-DOWN"时生效) # 对话窗的高度 仅在LAYOUT="TOP-DOWN"时生效)
CHATBOT_HEIGHT = 1115 CHATBOT_HEIGHT = 1115
@@ -58,7 +63,10 @@ CODE_HIGHLIGHT = True
# 窗口布局 # 窗口布局
LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布局) LAYOUT = "LEFT-RIGHT" # "LEFT-RIGHT"(左右布局) # "TOP-DOWN"(上下布局)
DARK_MODE = True # 暗色模式 / 亮色模式
# 暗色模式 / 亮色模式
DARK_MODE = True
# 发送请求到OpenAI后等待多久判定为超时 # 发送请求到OpenAI后等待多久判定为超时
@@ -79,16 +87,23 @@ DEFAULT_FN_GROUPS = ['对话', '编程', '学术', '智能体']
# 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 ) # 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 )
LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓ LLM_MODEL = "gpt-3.5-turbo" # 可选 ↓↓↓
AVAIL_LLM_MODELS = ["gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5", "api2d-gpt-3.5-turbo", AVAIL_LLM_MODELS = ["gpt-3.5-turbo-1106","gpt-4-1106-preview",
"gpt-4", "gpt-4-32k", "azure-gpt-4", "api2d-gpt-4", "chatglm", "moss", "newbing", "stack-claude"] "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5",
# P.S. 其他可用的模型还包括 ["qianfan", "llama2", "qwen", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", "api2d-gpt-3.5-turbo", 'api2d-gpt-3.5-turbo-16k',
# "spark", "sparkv2", "chatglm_onnx", "claude-1-100k", "claude-2", "internlm", "jittorllms_pangualpha", "jittorllms_llama"] "gpt-4", "gpt-4-32k", "azure-gpt-4", "api2d-gpt-4",
"chatglm3", "moss", "newbing", "claude-2"]
# P.S. 其他可用的模型还包括 ["zhipuai", "qianfan", "llama2", "qwen", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613", "gpt-3.5-random"
# "spark", "sparkv2", "sparkv3", "chatglm_onnx", "claude-1-100k", "claude-2", "internlm", "jittorllms_pangualpha", "jittorllms_llama"]
# 定义界面上“询问多个GPT模型”插件应该使用哪些模型请从AVAIL_LLM_MODELS中选择并在不同模型之间用`&`间隔,例如"gpt-3.5-turbo&chatglm3&azure-gpt-4"
MULTI_QUERY_LLM_MODELS = "gpt-3.5-turbo&chatglm3"
# 百度千帆LLM_MODEL="qianfan" # 百度千帆LLM_MODEL="qianfan"
BAIDU_CLOUD_API_KEY = '' BAIDU_CLOUD_API_KEY = ''
BAIDU_CLOUD_SECRET_KEY = '' BAIDU_CLOUD_SECRET_KEY = ''
BAIDU_CLOUD_QIANFAN_MODEL = 'ERNIE-Bot' # 可选 "ERNIE-Bot"(文心一言), "ERNIE-Bot-turbo", "BLOOMZ-7B", "Llama-2-70B-Chat", "Llama-2-13B-Chat", "Llama-2-7B-Chat" BAIDU_CLOUD_QIANFAN_MODEL = 'ERNIE-Bot' # 可选 "ERNIE-Bot-4"(文心大模型4.0), "ERNIE-Bot"(文心一言), "ERNIE-Bot-turbo", "BLOOMZ-7B", "Llama-2-70B-Chat", "Llama-2-13B-Chat", "Llama-2-7B-Chat"
# 如果使用ChatGLM2微调模型请把 LLM_MODEL="chatglmft",并在此处指定模型路径 # 如果使用ChatGLM2微调模型请把 LLM_MODEL="chatglmft",并在此处指定模型路径
@@ -121,22 +136,31 @@ AUTHENTICATION = []
CUSTOM_PATH = "/" CUSTOM_PATH = "/"
# HTTPS 秘钥和证书(不需要修改)
SSL_KEYFILE = ""
SSL_CERTFILE = ""
# 极少数情况下openai的官方KEY需要伴随组织编码格式如org-xxxxxxxxxxxxxxxxxxxxxxxx使用 # 极少数情况下openai的官方KEY需要伴随组织编码格式如org-xxxxxxxxxxxxxxxxxxxxxxxx使用
API_ORG = "" API_ORG = ""
# 如果需要使用Slack Claude使用教程详情见 request_llm/README.md # 如果需要使用Slack Claude使用教程详情见 request_llms/README.md
SLACK_CLAUDE_BOT_ID = '' SLACK_CLAUDE_BOT_ID = ''
SLACK_CLAUDE_USER_TOKEN = '' SLACK_CLAUDE_USER_TOKEN = ''
# 如果需要使用AZURE 详情请见额外文档 docs\use_azure.md # 如果需要使用AZURE方法一单个azure模型部署详情请见额外文档 docs\use_azure.md
AZURE_ENDPOINT = "https://你亲手写的api名称.openai.azure.com/" AZURE_ENDPOINT = "https://你亲手写的api名称.openai.azure.com/"
AZURE_API_KEY = "填入azure openai api的密钥" # 建议直接在API_KEY处填写该选项即将被弃用 AZURE_API_KEY = "填入azure openai api的密钥" # 建议直接在API_KEY处填写该选项即将被弃用
AZURE_ENGINE = "填入你亲手写的部署名" # 读 docs\use_azure.md AZURE_ENGINE = "填入你亲手写的部署名" # 读 docs\use_azure.md
# 使用Newbing # 如果需要使用AZURE方法二多个azure模型部署+动态切换)详情请见额外文档 docs\use_azure.md
AZURE_CFG_ARRAY = {}
# 使用Newbing (不推荐使用,未来将删除)
NEWBING_STYLE = "creative" # ["creative", "balanced", "precise"] NEWBING_STYLE = "creative" # ["creative", "balanced", "precise"]
NEWBING_COOKIES = """ NEWBING_COOKIES = """
put your new bing cookies here put your new bing cookies here
@@ -157,6 +181,11 @@ XFYUN_API_SECRET = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
XFYUN_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" XFYUN_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
# 接入智谱大模型
ZHIPUAI_API_KEY = ""
ZHIPUAI_MODEL = "chatglm_turbo"
# Claude API KEY # Claude API KEY
ANTHROPIC_API_KEY = "" ANTHROPIC_API_KEY = ""
@@ -173,20 +202,39 @@ HUGGINGFACE_ACCESS_TOKEN = "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"
# 获取方法复制以下空间https://huggingface.co/spaces/qingxu98/grobid设为public然后GROBID_URL = "https://(你的hf用户名如qingxu98)-(你的填写的空间名如grobid).hf.space" # 获取方法复制以下空间https://huggingface.co/spaces/qingxu98/grobid设为public然后GROBID_URL = "https://(你的hf用户名如qingxu98)-(你的填写的空间名如grobid).hf.space"
GROBID_URLS = [ GROBID_URLS = [
"https://qingxu98-grobid.hf.space","https://qingxu98-grobid2.hf.space","https://qingxu98-grobid3.hf.space", "https://qingxu98-grobid.hf.space","https://qingxu98-grobid2.hf.space","https://qingxu98-grobid3.hf.space",
"https://shaocongma-grobid.hf.space","https://FBR123-grobid.hf.space", "https://yeku-grobid.hf.space", "https://qingxu98-grobid4.hf.space","https://qingxu98-grobid5.hf.space", "https://qingxu98-grobid6.hf.space",
"https://qingxu98-grobid7.hf.space", "https://qingxu98-grobid8.hf.space",
] ]
# 是否允许通过自然语言描述修改本页的配置,该功能具有一定的危险性,默认关闭 # 是否允许通过自然语言描述修改本页的配置,该功能具有一定的危险性,默认关闭
ALLOW_RESET_CONFIG = False ALLOW_RESET_CONFIG = False
# 在使用AutoGen插件时是否使用Docker容器运行代码
AUTOGEN_USE_DOCKER = False
# 临时的上传文件夹位置,请勿修改 # 临时的上传文件夹位置,请勿修改
PATH_PRIVATE_UPLOAD = "private_upload" PATH_PRIVATE_UPLOAD = "private_upload"
# 日志文件夹的位置,请勿修改 # 日志文件夹的位置,请勿修改
PATH_LOGGING = "gpt_log" PATH_LOGGING = "gpt_log"
# 除了连接OpenAI之外还有哪些场合允许使用代理请勿修改
WHEN_TO_USE_PROXY = ["Download_LLM", "Download_Gradio_Theme", "Connect_Grobid", "Warmup_Modules"]
# 除了连接OpenAI之外还有哪些场合允许使用代理请勿修改
WHEN_TO_USE_PROXY = ["Download_LLM", "Download_Gradio_Theme", "Connect_Grobid",
"Warmup_Modules", "Nougat_Download", "AutoGen"]
# *实验性功能*: 自动检测并屏蔽失效的KEY请勿使用
BLOCK_INVALID_APIKEY = False
# 自定义按钮的最大数量限制
NUM_CUSTOM_BASIC_BTN = 4
""" """
在线大模型配置关联关系示意图 在线大模型配置关联关系示意图
@@ -196,13 +244,16 @@ WHEN_TO_USE_PROXY = ["Download_LLM", "Download_Gradio_Theme", "Connect_Grobid",
│ ├── API_ORG不常用 │ ├── API_ORG不常用
│ └── API_URL_REDIRECT不常用 │ └── API_URL_REDIRECT不常用
├── "azure-gpt-3.5" 等azure模型 ├── "azure-gpt-3.5" 等azure模型单个azure模型不需要动态切换
│ ├── API_KEY │ ├── API_KEY
│ ├── AZURE_ENDPOINT │ ├── AZURE_ENDPOINT
│ ├── AZURE_API_KEY │ ├── AZURE_API_KEY
│ ├── AZURE_ENGINE │ ├── AZURE_ENGINE
│ └── API_URL_REDIRECT │ └── API_URL_REDIRECT
├── "azure-gpt-3.5" 等azure模型多个azure模型需要动态切换高优先级
│ └── AZURE_CFG_ARRAY
├── "spark" 星火认知大模型 spark & sparkv2 ├── "spark" 星火认知大模型 spark & sparkv2
│ ├── XFYUN_APPID │ ├── XFYUN_APPID
│ ├── XFYUN_API_SECRET │ ├── XFYUN_API_SECRET

View File

@@ -91,6 +91,13 @@ def handle_core_functionality(additional_fn, inputs, history, chatbot):
import core_functional import core_functional
importlib.reload(core_functional) # 热更新prompt importlib.reload(core_functional) # 热更新prompt
core_functional = core_functional.get_core_functions() core_functional = core_functional.get_core_functions()
addition = chatbot._cookies['customize_fn_overwrite']
if additional_fn in addition:
# 自定义功能
inputs = addition[additional_fn]["Prefix"] + inputs + addition[additional_fn]["Suffix"]
return inputs, history
else:
# 预制功能
if "PreProcess" in core_functional[additional_fn]: inputs = core_functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话) if "PreProcess" in core_functional[additional_fn]: inputs = core_functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话)
inputs = core_functional[additional_fn]["Prefix"] + inputs + core_functional[additional_fn]["Suffix"] inputs = core_functional[additional_fn]["Prefix"] + inputs + core_functional[additional_fn]["Suffix"]
if core_functional[additional_fn].get("AutoClearHistory", False): if core_functional[additional_fn].get("AutoClearHistory", False):

View File

@@ -190,10 +190,10 @@ def get_crazy_functions():
"Info": "多线程解析并翻译此项目的源码 | 不需要输入参数", "Info": "多线程解析并翻译此项目的源码 | 不需要输入参数",
"Function": HotReload(解析项目本身) "Function": HotReload(解析项目本身)
}, },
"[插件demo]历史上的今天": { "历史上的今天": {
"Group": "对话", "Group": "对话",
"AsButton": True, "AsButton": True,
"Info": "查看历史上的今天事件 | 不需要输入参数", "Info": "查看历史上的今天事件 (这是一个面向开发者的插件Demo) | 不需要输入参数",
"Function": HotReload(高阶功能模板函数) "Function": HotReload(高阶功能模板函数)
}, },
"精准翻译PDF论文": { "精准翻译PDF论文": {
@@ -252,7 +252,7 @@ def get_crazy_functions():
"Function": HotReload(Latex中文润色) "Function": HotReload(Latex中文润色)
}, },
# 被新插件取代 # 已经被新插件取代
# "Latex项目全文中译英输入路径或上传压缩包": { # "Latex项目全文中译英输入路径或上传压缩包": {
# "Group": "学术", # "Group": "学术",
# "Color": "stop", # "Color": "stop",
@@ -260,6 +260,8 @@ def get_crazy_functions():
# "Info": "对Latex项目全文进行中译英处理 | 输入参数为路径或上传压缩包", # "Info": "对Latex项目全文进行中译英处理 | 输入参数为路径或上传压缩包",
# "Function": HotReload(Latex中译英) # "Function": HotReload(Latex中译英)
# }, # },
# 已经被新插件取代
# "Latex项目全文英译中输入路径或上传压缩包": { # "Latex项目全文英译中输入路径或上传压缩包": {
# "Group": "学术", # "Group": "学术",
# "Color": "stop", # "Color": "stop",
@@ -347,18 +349,40 @@ def get_crazy_functions():
print('Load function plugin failed') print('Load function plugin failed')
try: try:
from crazy_functions.图片生成 import 图片生成 from crazy_functions.图片生成 import 图片生成_DALLE2, 图片生成_DALLE3, 图片修改_DALLE2
function_plugins.update({ function_plugins.update({
"图片生成先切换模型到openai或api2d": { "图片生成_DALLE2先切换模型到openai或api2d": {
"Group": "对话", "Group": "对话",
"Color": "stop", "Color": "stop",
"AsButton": False, "AsButton": False,
"AdvancedArgs": True, # 调用时唤起高级参数输入区默认False "AdvancedArgs": True, # 调用时唤起高级参数输入区默认False
"ArgsReminder": "在这里输入分辨率, 如256x256默认", # 高级参数输入区的显示提示 "ArgsReminder": "在这里输入分辨率, 如1024x1024默认支持 256x256, 512x512, 1024x1024", # 高级参数输入区的显示提示
"Info": "图片生成 | 输入参数字符串,提供图像的内容", "Info": "使用DALLE2生成图片 | 输入参数字符串,提供图像的内容",
"Function": HotReload(图片生成) "Function": HotReload(图片生成_DALLE2)
}, },
}) })
function_plugins.update({
"图片生成_DALLE3先切换模型到openai或api2d": {
"Group": "对话",
"Color": "stop",
"AsButton": False,
"AdvancedArgs": True, # 调用时唤起高级参数输入区默认False
"ArgsReminder": "在这里输入分辨率, 如1024x1024默认支持 1024x1024, 1792x1024, 1024x1792", # 高级参数输入区的显示提示
"Info": "使用DALLE3生成图片 | 输入参数字符串,提供图像的内容",
"Function": HotReload(图片生成_DALLE3)
},
})
# function_plugins.update({
# "图片修改_DALLE2启动DALLE2图像修改向导程序": {
# "Group": "对话",
# "Color": "stop",
# "AsButton": False,
# "AdvancedArgs": True, # 调用时唤起高级参数输入区默认False
# "ArgsReminder": "在这里输入分辨率, 如1024x1024默认支持 1024x1024, 1792x1024, 1024x1792", # 高级参数输入区的显示提示
# # "Info": "使用DALLE2修改图片 | 输入参数字符串,提供图像的内容",
# "Function": HotReload(图片修改_DALLE2)
# },
# })
except: except:
print('Load function plugin failed') print('Load function plugin failed')
@@ -395,7 +419,7 @@ def get_crazy_functions():
try: try:
from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言 from crazy_functions.批量Markdown翻译 import Markdown翻译指定语言
function_plugins.update({ function_plugins.update({
"Markdown翻译手动指定语言)": { "Markdown翻译指定翻译成何种语言)": {
"Group": "编程", "Group": "编程",
"Color": "stop", "Color": "stop",
"AsButton": False, "AsButton": False,
@@ -440,7 +464,7 @@ def get_crazy_functions():
try: try:
from crazy_functions.交互功能函数模板 import 交互功能模板函数 from crazy_functions.交互功能函数模板 import 交互功能模板函数
function_plugins.update({ function_plugins.update({
"交互功能模板函数": { "交互功能模板Demo函数查找wallhaven.cc的壁纸": {
"Group": "对话", "Group": "对话",
"Color": "stop", "Color": "stop",
"AsButton": False, "AsButton": False,
@@ -496,15 +520,15 @@ def get_crazy_functions():
try: try:
from toolbox import get_conf from toolbox import get_conf
ENABLE_AUDIO, = get_conf('ENABLE_AUDIO') ENABLE_AUDIO = get_conf('ENABLE_AUDIO')
if ENABLE_AUDIO: if ENABLE_AUDIO:
from crazy_functions.语音助手 import 语音助手 from crazy_functions.语音助手 import 语音助手
function_plugins.update({ function_plugins.update({
"实时音频采集": { "实时语音对话": {
"Group": "对话", "Group": "对话",
"Color": "stop", "Color": "stop",
"AsButton": True, "AsButton": True,
"Info": "开始语言对话 | 没有输入参数", "Info": "这是一个时刻聆听着的语音对话助手 | 没有输入参数",
"Function": HotReload(语音助手) "Function": HotReload(语音助手)
} }
}) })
@@ -537,18 +561,15 @@ def get_crazy_functions():
except: except:
print('Load function plugin failed') print('Load function plugin failed')
# try: from crazy_functions.多智能体 import 多智能体终端
# from crazy_functions.CodeInterpreter import 虚空终端CodeInterpreter function_plugins.update({
# function_plugins.update({ "多智能体终端微软AutoGen": {
# "CodeInterpreter开发中仅供测试": { "Group": "智能体",
# "Group": "编程|对话", "Color": "stop",
# "Color": "stop", "AsButton": True,
# "AsButton": False, "Function": HotReload(多智能体终端)
# "Function": HotReload(虚空终端CodeInterpreter) }
# } })
# })
# except:
# print('Load function plugin failed')
# try: # try:
# from crazy_functions.chatglm微调工具 import 微调数据集生成 # from crazy_functions.chatglm微调工具 import 微调数据集生成

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui, trimmed_format_exc, promote_file_to_downloadzone, get_log_folder from toolbox import update_ui, trimmed_format_exc, promote_file_to_downloadzone, get_log_folder
from toolbox import CatchException, report_execption, write_history_to_file, zip_folder from toolbox import CatchException, report_exception, write_history_to_file, zip_folder
class PaperFileGroup(): class PaperFileGroup():
@@ -11,7 +11,7 @@ class PaperFileGroup():
self.sp_file_tag = [] self.sp_file_tag = []
# count_token # count_token
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
self.get_token_num = get_token_num self.get_token_num = get_token_num
@@ -146,7 +146,7 @@ def Latex英文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -157,12 +157,12 @@ def Latex英文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en') yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en')
@@ -184,7 +184,7 @@ def Latex中文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -195,12 +195,12 @@ def Latex中文润色(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh') yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh')
@@ -220,7 +220,7 @@ def Latex英文纠错(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -231,12 +231,12 @@ def Latex英文纠错(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en', mode='proofread') yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en', mode='proofread')

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui, promote_file_to_downloadzone from toolbox import update_ui, promote_file_to_downloadzone
from toolbox import CatchException, report_execption, write_history_to_file from toolbox import CatchException, report_exception, write_history_to_file
fast_debug = False fast_debug = False
class PaperFileGroup(): class PaperFileGroup():
@@ -11,7 +11,7 @@ class PaperFileGroup():
self.sp_file_tag = [] self.sp_file_tag = []
# count_token # count_token
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
self.get_token_num = get_token_num self.get_token_num = get_token_num
@@ -117,7 +117,7 @@ def Latex英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -128,12 +128,12 @@ def Latex英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh') yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en->zh')
@@ -154,7 +154,7 @@ def Latex中译英(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -165,12 +165,12 @@ def Latex中译英(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prom
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh->en') yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh->en')

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui, trimmed_format_exc, get_conf, get_log_folder, promote_file_to_downloadzone from toolbox import update_ui, trimmed_format_exc, get_conf, get_log_folder, promote_file_to_downloadzone
from toolbox import CatchException, report_execption, update_ui_lastest_msg, zip_result, gen_time_str from toolbox import CatchException, report_exception, update_ui_lastest_msg, zip_result, gen_time_str
from functools import partial from functools import partial
import glob, os, requests, time import glob, os, requests, time
pj = os.path.join pj = os.path.join
@@ -129,7 +129,7 @@ def arxiv_download(chatbot, history, txt, allow_cache=True):
yield from update_ui_lastest_msg("调用缓存", chatbot=chatbot, history=history) # 刷新界面 yield from update_ui_lastest_msg("调用缓存", chatbot=chatbot, history=history) # 刷新界面
else: else:
yield from update_ui_lastest_msg("开始下载", chatbot=chatbot, history=history) # 刷新界面 yield from update_ui_lastest_msg("开始下载", chatbot=chatbot, history=history) # 刷新界面
proxies, = get_conf('proxies') proxies = get_conf('proxies')
r = requests.get(url_tar, proxies=proxies) r = requests.get(url_tar, proxies=proxies)
with open(dst, 'wb+') as f: with open(dst, 'wb+') as f:
f.write(r.content) f.write(r.content)
@@ -171,12 +171,12 @@ def Latex英文纠错加PDF对比(txt, llm_kwargs, plugin_kwargs, chatbot, histo
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -249,7 +249,7 @@ def Latex翻译中文并重新编译PDF(txt, llm_kwargs, plugin_kwargs, chatbot,
history = [] history = []
txt, arxiv_id = yield from arxiv_download(chatbot, history, txt, allow_cache) txt, arxiv_id = yield from arxiv_download(chatbot, history, txt, allow_cache)
if txt.endswith('.pdf'): if txt.endswith('.pdf'):
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"发现已经存在翻译好的PDF文档") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"发现已经存在翻译好的PDF文档")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -258,13 +258,13 @@ def Latex翻译中文并重新编译PDF(txt, llm_kwargs, plugin_kwargs, chatbot,
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无法处理: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无法处理: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -0,0 +1,23 @@
from toolbox import CatchException, update_ui, gen_time_str, trimmed_format_exc, ProxyNetworkActivate
from toolbox import report_exception, get_log_folder, update_ui_lastest_msg, Singleton
from crazy_functions.agent_fns.pipe import PluginMultiprocessManager, PipeCom
from crazy_functions.agent_fns.general import AutoGenGeneral
class AutoGenMath(AutoGenGeneral):
def define_agents(self):
from autogen import AssistantAgent, UserProxyAgent
return [
{
"name": "assistant", # name of the agent.
"cls": AssistantAgent, # class of the agent.
},
{
"name": "user_proxy", # name of the agent.
"cls": UserProxyAgent, # class of the agent.
"human_input_mode": "ALWAYS", # always ask for human input.
"llm_config": False, # disables llm-based auto reply.
},
]

View File

@@ -0,0 +1,19 @@
from crazy_functions.agent_fns.pipe import PluginMultiprocessManager, PipeCom
class EchoDemo(PluginMultiprocessManager):
def subprocess_worker(self, child_conn):
# ⭐⭐ 子进程
self.child_conn = child_conn
while True:
msg = self.child_conn.recv() # PipeCom
if msg.cmd == "user_input":
# wait futher user input
self.child_conn.send(PipeCom("show", msg.content))
wait_success = self.subprocess_worker_wait_user_feedback(wait_msg="我准备好处理下一个问题了.")
if not wait_success:
# wait timeout, terminate this subprocess_worker
break
elif msg.cmd == "terminate":
self.child_conn.send(PipeCom("done", ""))
break
print('[debug] subprocess_worker terminated')

View File

@@ -0,0 +1,134 @@
from toolbox import trimmed_format_exc, get_conf, ProxyNetworkActivate
from crazy_functions.agent_fns.pipe import PluginMultiprocessManager, PipeCom
from request_llms.bridge_all import predict_no_ui_long_connection
import time
def gpt_academic_generate_oai_reply(
self,
messages,
sender,
config,
):
llm_config = self.llm_config if config is None else config
if llm_config is False:
return False, None
if messages is None:
messages = self._oai_messages[sender]
inputs = messages[-1]['content']
history = []
for message in messages[:-1]:
history.append(message['content'])
context=messages[-1].pop("context", None)
assert context is None, "预留参数 context 未实现"
reply = predict_no_ui_long_connection(
inputs=inputs,
llm_kwargs=llm_config,
history=history,
sys_prompt=self._oai_system_message[0]['content'],
console_slience=True
)
assumed_done = reply.endswith('\nTERMINATE')
return True, reply
class AutoGenGeneral(PluginMultiprocessManager):
def gpt_academic_print_override(self, user_proxy, message, sender):
# ⭐⭐ run in subprocess
self.child_conn.send(PipeCom("show", sender.name + "\n\n---\n\n" + message["content"]))
def gpt_academic_get_human_input(self, user_proxy, message):
# ⭐⭐ run in subprocess
patience = 300
begin_waiting_time = time.time()
self.child_conn.send(PipeCom("interact", message))
while True:
time.sleep(0.5)
if self.child_conn.poll():
wait_success = True
break
if time.time() - begin_waiting_time > patience:
self.child_conn.send(PipeCom("done", ""))
wait_success = False
break
if wait_success:
return self.child_conn.recv().content
else:
raise TimeoutError("等待用户输入超时")
def define_agents(self):
raise NotImplementedError
def exe_autogen(self, input):
# ⭐⭐ run in subprocess
input = input.content
with ProxyNetworkActivate("AutoGen"):
code_execution_config = {"work_dir": self.autogen_work_dir, "use_docker": self.use_docker}
agents = self.define_agents()
user_proxy = None
assistant = None
for agent_kwargs in agents:
agent_cls = agent_kwargs.pop('cls')
kwargs = {
'llm_config':self.llm_kwargs,
'code_execution_config':code_execution_config
}
kwargs.update(agent_kwargs)
agent_handle = agent_cls(**kwargs)
agent_handle._print_received_message = lambda a,b: self.gpt_academic_print_override(agent_kwargs, a, b)
for d in agent_handle._reply_func_list:
if hasattr(d['reply_func'],'__name__') and d['reply_func'].__name__ == 'generate_oai_reply':
d['reply_func'] = gpt_academic_generate_oai_reply
if agent_kwargs['name'] == 'user_proxy':
agent_handle.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)
user_proxy = agent_handle
if agent_kwargs['name'] == 'assistant': assistant = agent_handle
try:
if user_proxy is None or assistant is None: raise Exception("用户代理或助理代理未定义")
user_proxy.initiate_chat(assistant, message=input)
except Exception as e:
tb_str = '```\n' + trimmed_format_exc() + '```'
self.child_conn.send(PipeCom("done", "AutoGen 执行失败: \n\n" + tb_str))
def subprocess_worker(self, child_conn):
# ⭐⭐ run in subprocess
self.child_conn = child_conn
while True:
msg = self.child_conn.recv() # PipeCom
self.exe_autogen(msg)
class AutoGenGroupChat(AutoGenGeneral):
def exe_autogen(self, input):
# ⭐⭐ run in subprocess
import autogen
input = input.content
with ProxyNetworkActivate("AutoGen"):
code_execution_config = {"work_dir": self.autogen_work_dir, "use_docker": self.use_docker}
agents = self.define_agents()
agents_instances = []
for agent_kwargs in agents:
agent_cls = agent_kwargs.pop("cls")
kwargs = {"code_execution_config": code_execution_config}
kwargs.update(agent_kwargs)
agent_handle = agent_cls(**kwargs)
agent_handle._print_received_message = lambda a, b: self.gpt_academic_print_override(agent_kwargs, a, b)
agents_instances.append(agent_handle)
if agent_kwargs["name"] == "user_proxy":
user_proxy = agent_handle
user_proxy.get_human_input = lambda a: self.gpt_academic_get_human_input(user_proxy, a)
try:
groupchat = autogen.GroupChat(agents=agents_instances, messages=[], max_round=50)
manager = autogen.GroupChatManager(groupchat=groupchat, **self.define_group_chat_manager_config())
manager._print_received_message = lambda a, b: self.gpt_academic_print_override(agent_kwargs, a, b)
manager.get_human_input = lambda a: self.gpt_academic_get_human_input(manager, a)
if user_proxy is None:
raise Exception("user_proxy is not defined")
user_proxy.initiate_chat(manager, message=input)
except Exception:
tb_str = "```\n" + trimmed_format_exc() + "```"
self.child_conn.send(PipeCom("done", "AutoGen exe failed: \n\n" + tb_str))
def define_group_chat_manager_config(self):
raise NotImplementedError

View File

@@ -0,0 +1,16 @@
from toolbox import Singleton
@Singleton
class GradioMultiuserManagerForPersistentClasses():
def __init__(self):
self.mapping = {}
def already_alive(self, key):
return (key in self.mapping) and (self.mapping[key].is_alive())
def set(self, key, x):
self.mapping[key] = x
return self.mapping[key]
def get(self, key):
return self.mapping[key]

View File

@@ -0,0 +1,194 @@
from toolbox import get_log_folder, update_ui, gen_time_str, get_conf, promote_file_to_downloadzone
from crazy_functions.agent_fns.watchdog import WatchDog
import time, os
class PipeCom:
def __init__(self, cmd, content) -> None:
self.cmd = cmd
self.content = content
class PluginMultiprocessManager:
def __init__(self, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
# ⭐ run in main process
self.autogen_work_dir = os.path.join(get_log_folder("autogen"), gen_time_str())
self.previous_work_dir_files = {}
self.llm_kwargs = llm_kwargs
self.plugin_kwargs = plugin_kwargs
self.chatbot = chatbot
self.history = history
self.system_prompt = system_prompt
# self.web_port = web_port
self.alive = True
self.use_docker = get_conf("AUTOGEN_USE_DOCKER")
self.last_user_input = ""
# create a thread to monitor self.heartbeat, terminate the instance if no heartbeat for a long time
timeout_seconds = 5 * 60
self.heartbeat_watchdog = WatchDog(timeout=timeout_seconds, bark_fn=self.terminate, interval=5)
self.heartbeat_watchdog.begin_watch()
def feed_heartbeat_watchdog(self):
# feed this `dog`, so the dog will not `bark` (bark_fn will terminate the instance)
self.heartbeat_watchdog.feed()
def is_alive(self):
return self.alive
def launch_subprocess_with_pipe(self):
# ⭐ run in main process
from multiprocessing import Process, Pipe
parent_conn, child_conn = Pipe()
self.p = Process(target=self.subprocess_worker, args=(child_conn,))
self.p.daemon = True
self.p.start()
return parent_conn
def terminate(self):
self.p.terminate()
self.alive = False
print("[debug] instance terminated")
def subprocess_worker(self, child_conn):
# ⭐⭐ run in subprocess
raise NotImplementedError
def send_command(self, cmd):
# ⭐ run in main process
repeated = False
if cmd == self.last_user_input:
repeated = True
cmd = ""
else:
self.last_user_input = cmd
self.parent_conn.send(PipeCom("user_input", cmd))
return repeated, cmd
def immediate_showoff_when_possible(self, fp):
# ⭐ 主进程
# 获取fp的拓展名
file_type = fp.split('.')[-1]
# 如果是文本文件, 则直接显示文本内容
if file_type.lower() in ['png', 'jpg']:
image_path = os.path.abspath(fp)
self.chatbot.append([
'检测到新生图像:',
f'本地文件预览: <br/><div align="center"><img src="file={image_path}"></div>'
])
yield from update_ui(chatbot=self.chatbot, history=self.history)
def overwatch_workdir_file_change(self):
# ⭐ 主进程 Docker 外挂文件夹监控
path_to_overwatch = self.autogen_work_dir
change_list = []
# 扫描路径下的所有文件, 并与self.previous_work_dir_files中所记录的文件进行对比
# 如果有新文件出现或者文件的修改时间发生变化则更新self.previous_work_dir_files中
# 把新文件和发生变化的文件的路径记录到 change_list 中
for root, dirs, files in os.walk(path_to_overwatch):
for file in files:
file_path = os.path.join(root, file)
if file_path not in self.previous_work_dir_files.keys():
last_modified_time = os.stat(file_path).st_mtime
self.previous_work_dir_files.update({file_path: last_modified_time})
change_list.append(file_path)
else:
last_modified_time = os.stat(file_path).st_mtime
if last_modified_time != self.previous_work_dir_files[file_path]:
self.previous_work_dir_files[file_path] = last_modified_time
change_list.append(file_path)
if len(change_list) > 0:
file_links = ""
for f in change_list:
res = promote_file_to_downloadzone(f)
file_links += f'<br/><a href="file={res}" target="_blank">{res}</a>'
yield from self.immediate_showoff_when_possible(f)
self.chatbot.append(['检测到新生文档.', f'文档清单如下: {file_links}'])
yield from update_ui(chatbot=self.chatbot, history=self.history)
return change_list
def main_process_ui_control(self, txt, create_or_resume) -> str:
# ⭐ 主进程
if create_or_resume == 'create':
self.cnt = 1
self.parent_conn = self.launch_subprocess_with_pipe() # ⭐⭐⭐
repeated, cmd_to_autogen = self.send_command(txt)
if txt == 'exit':
self.chatbot.append([f"结束", "结束信号已明确终止AutoGen程序。"])
yield from update_ui(chatbot=self.chatbot, history=self.history)
self.terminate()
return "terminate"
# patience = 10
while True:
time.sleep(0.5)
if not self.alive:
# the heartbeat watchdog might have it killed
self.terminate()
return "terminate"
if self.parent_conn.poll():
self.feed_heartbeat_watchdog()
if "[GPT-Academic] 等待中" in self.chatbot[-1][-1]:
self.chatbot.pop(-1) # remove the last line
if "等待您的进一步指令" in self.chatbot[-1][-1]:
self.chatbot.pop(-1) # remove the last line
if '[GPT-Academic] 等待中' in self.chatbot[-1][-1]:
self.chatbot.pop(-1) # remove the last line
msg = self.parent_conn.recv() # PipeCom
if msg.cmd == "done":
self.chatbot.append([f"结束", msg.content])
self.cnt += 1
yield from update_ui(chatbot=self.chatbot, history=self.history)
self.terminate()
break
if msg.cmd == "show":
yield from self.overwatch_workdir_file_change()
notice = ""
if repeated: notice = "(自动忽略重复的输入)"
self.chatbot.append([f"运行阶段-{self.cnt}(上次用户反馈输入为: 「{cmd_to_autogen}{notice}", msg.content])
self.cnt += 1
yield from update_ui(chatbot=self.chatbot, history=self.history)
if msg.cmd == "interact":
yield from self.overwatch_workdir_file_change()
self.chatbot.append([f"程序抵达用户反馈节点.", msg.content +
"\n\n等待您的进一步指令." +
"\n\n(1) 一般情况下您不需要说什么, 清空输入区, 然后直接点击“提交”以继续. " +
"\n\n(2) 如果您需要补充些什么, 输入要反馈的内容, 直接点击“提交”以继续. " +
"\n\n(3) 如果您想终止程序, 输入exit, 直接点击“提交”以终止AutoGen并解锁. "
])
yield from update_ui(chatbot=self.chatbot, history=self.history)
# do not terminate here, leave the subprocess_worker instance alive
return "wait_feedback"
else:
self.feed_heartbeat_watchdog()
if '[GPT-Academic] 等待中' not in self.chatbot[-1][-1]:
# begin_waiting_time = time.time()
self.chatbot.append(["[GPT-Academic] 等待AutoGen执行结果 ...", "[GPT-Academic] 等待中"])
self.chatbot[-1] = [self.chatbot[-1][0], self.chatbot[-1][1].replace("[GPT-Academic] 等待中", "[GPT-Academic] 等待中.")]
yield from update_ui(chatbot=self.chatbot, history=self.history)
# if time.time() - begin_waiting_time > patience:
# self.chatbot.append([f"结束", "等待超时, 终止AutoGen程序。"])
# yield from update_ui(chatbot=self.chatbot, history=self.history)
# self.terminate()
# return "terminate"
self.terminate()
return "terminate"
def subprocess_worker_wait_user_feedback(self, wait_msg="wait user feedback"):
# ⭐⭐ run in subprocess
patience = 5 * 60
begin_waiting_time = time.time()
self.child_conn.send(PipeCom("interact", wait_msg))
while True:
time.sleep(0.5)
if self.child_conn.poll():
wait_success = True
break
if time.time() - begin_waiting_time > patience:
self.child_conn.send(PipeCom("done", ""))
wait_success = False
break
return wait_success

View File

@@ -0,0 +1,28 @@
import threading, time
class WatchDog():
def __init__(self, timeout, bark_fn, interval=3, msg="") -> None:
self.last_feed = None
self.timeout = timeout
self.bark_fn = bark_fn
self.interval = interval
self.msg = msg
self.kill_dog = False
def watch(self):
while True:
if self.kill_dog: break
if time.time() - self.last_feed > self.timeout:
if len(self.msg) > 0: print(self.msg)
self.bark_fn()
break
time.sleep(self.interval)
def begin_watch(self):
self.last_feed = time.time()
th = threading.Thread(target=self.watch)
th.daemon = True
th.start()
def feed(self):
self.last_feed = time.time()

View File

@@ -5,7 +5,7 @@ import logging
def input_clipping(inputs, history, max_token_limit): def input_clipping(inputs, history, max_token_limit):
import numpy as np import numpy as np
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
@@ -63,18 +63,21 @@ def request_gpt_model_in_new_thread_with_ui_alive(
""" """
import time import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from request_llm.bridge_all import predict_no_ui_long_connection from request_llms.bridge_all import predict_no_ui_long_connection
# 用户反馈 # 用户反馈
chatbot.append([inputs_show_user, ""]) chatbot.append([inputs_show_user, ""])
yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面 yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面
executor = ThreadPoolExecutor(max_workers=16) executor = ThreadPoolExecutor(max_workers=16)
mutable = ["", time.time(), ""] mutable = ["", time.time(), ""]
# 看门狗耐心
watch_dog_patience = 5
# 请求任务
def _req_gpt(inputs, history, sys_prompt): def _req_gpt(inputs, history, sys_prompt):
retry_op = retry_times_at_unknown_error retry_op = retry_times_at_unknown_error
exceeded_cnt = 0 exceeded_cnt = 0
while True: while True:
# watchdog error # watchdog error
if len(mutable) >= 2 and (time.time()-mutable[1]) > 5: if len(mutable) >= 2 and (time.time()-mutable[1]) > watch_dog_patience:
raise RuntimeError("检测到程序终止。") raise RuntimeError("检测到程序终止。")
try: try:
# 【第一种情况】:顺利完成 # 【第一种情况】:顺利完成
@@ -174,11 +177,11 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
""" """
import time, random import time, random
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from request_llm.bridge_all import predict_no_ui_long_connection from request_llms.bridge_all import predict_no_ui_long_connection
assert len(inputs_array) == len(history_array) assert len(inputs_array) == len(history_array)
assert len(inputs_array) == len(sys_prompt_array) assert len(inputs_array) == len(sys_prompt_array)
if max_workers == -1: # 读取配置文件 if max_workers == -1: # 读取配置文件
try: max_workers, = get_conf('DEFAULT_WORKER_NUM') try: max_workers = get_conf('DEFAULT_WORKER_NUM')
except: max_workers = 8 except: max_workers = 8
if max_workers <= 0: max_workers = 3 if max_workers <= 0: max_workers = 3
# 屏蔽掉 chatglm的多线程可能会导致严重卡顿 # 屏蔽掉 chatglm的多线程可能会导致严重卡顿
@@ -193,6 +196,9 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
# 跨线程传递 # 跨线程传递
mutable = [["", time.time(), "等待中"] for _ in range(n_frag)] mutable = [["", time.time(), "等待中"] for _ in range(n_frag)]
# 看门狗耐心
watch_dog_patience = 5
# 子线程任务 # 子线程任务
def _req_gpt(index, inputs, history, sys_prompt): def _req_gpt(index, inputs, history, sys_prompt):
gpt_say = "" gpt_say = ""
@@ -201,7 +207,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
mutable[index][2] = "执行中" mutable[index][2] = "执行中"
while True: while True:
# watchdog error # watchdog error
if len(mutable[index]) >= 2 and (time.time()-mutable[index][1]) > 5: if len(mutable[index]) >= 2 and (time.time()-mutable[index][1]) > watch_dog_patience:
raise RuntimeError("检测到程序终止。") raise RuntimeError("检测到程序终止。")
try: try:
# 【第一种情况】:顺利完成 # 【第一种情况】:顺利完成
@@ -275,7 +281,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
# 在前端打印些好玩的东西 # 在前端打印些好玩的东西
for thread_index, _ in enumerate(worker_done): for thread_index, _ in enumerate(worker_done):
print_something_really_funny = "[ ...`"+mutable[thread_index][0][-scroller_max_len:].\ print_something_really_funny = "[ ...`"+mutable[thread_index][0][-scroller_max_len:].\
replace('\n', '').replace('```', '...').replace( replace('\n', '').replace('`', '.').replace(
' ', '.').replace('<br/>', '.....').replace('$', '.')+"`... ]" ' ', '.').replace('<br/>', '.....').replace('$', '.')+"`... ]"
observe_win.append(print_something_really_funny) observe_win.append(print_something_really_funny)
# 在前端打印些好玩的东西 # 在前端打印些好玩的东西
@@ -301,7 +307,7 @@ def request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency(
gpt_res = f.result() gpt_res = f.result()
chatbot.append([inputs_show_user, gpt_res]) chatbot.append([inputs_show_user, gpt_res])
yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面 yield from update_ui(chatbot=chatbot, history=[]) # 刷新界面
time.sleep(0.3) time.sleep(0.5)
return gpt_response_collection return gpt_response_collection
@@ -596,7 +602,7 @@ def get_files_from_everything(txt, type): # type='.md'
import requests import requests
from toolbox import get_conf from toolbox import get_conf
from toolbox import get_log_folder, gen_time_str from toolbox import get_log_folder, gen_time_str
proxies, = get_conf('proxies') proxies = get_conf('proxies')
try: try:
r = requests.get(txt, proxies=proxies) r = requests.get(txt, proxies=proxies)
except: except:
@@ -715,8 +721,10 @@ class nougat_interface():
def nougat_with_timeout(self, command, cwd, timeout=3600): def nougat_with_timeout(self, command, cwd, timeout=3600):
import subprocess import subprocess
from toolbox import ProxyNetworkActivate
logging.info(f'正在执行命令 {command}') logging.info(f'正在执行命令 {command}')
process = subprocess.Popen(command, shell=True, cwd=cwd) with ProxyNetworkActivate("Nougat_Download"):
process = subprocess.Popen(command, shell=True, cwd=cwd, env=os.environ)
try: try:
stdout, stderr = process.communicate(timeout=timeout) stdout, stderr = process.communicate(timeout=timeout)
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
@@ -740,7 +748,7 @@ class nougat_interface():
yield from update_ui_lastest_msg("正在解析论文, 请稍候。进度正在加载NOUGAT... 提示首次运行需要花费较长时间下载NOUGAT参数", yield from update_ui_lastest_msg("正在解析论文, 请稍候。进度正在加载NOUGAT... 提示首次运行需要花费较长时间下载NOUGAT参数",
chatbot=chatbot, history=history, delay=0) chatbot=chatbot, history=history, delay=0)
self.nougat_with_timeout(f'nougat --out "{os.path.abspath(dst)}" "{os.path.abspath(fp)}"', os.getcwd(), timeout=3600) self.nougat_with_timeout(f'nougat --out "{os.path.abspath(dst)}" "{os.path.abspath(fp)}" --recompute --no-skipping --markdown --batchsize 8', os.getcwd(), timeout=3600)
res = glob.glob(os.path.join(dst,'*.mmd')) res = glob.glob(os.path.join(dst,'*.mmd'))
if len(res) == 0: if len(res) == 0:
self.threadLock.release() self.threadLock.release()
@@ -761,54 +769,6 @@ def try_install_deps(deps, reload_m=[]):
importlib.reload(__import__(m)) importlib.reload(__import__(m))
HTML_CSS = """
.row {
display: flex;
flex-wrap: wrap;
}
.column {
flex: 1;
padding: 10px;
}
.table-header {
font-weight: bold;
border-bottom: 1px solid black;
}
.table-row {
border-bottom: 1px solid lightgray;
}
.table-cell {
padding: 5px;
}
"""
TABLE_CSS = """
<div class="row table-row">
<div class="column table-cell">REPLACE_A</div>
<div class="column table-cell">REPLACE_B</div>
</div>
"""
class construct_html():
def __init__(self) -> None:
self.css = HTML_CSS
self.html_string = f'<!DOCTYPE html><head><meta charset="utf-8"><title>翻译结果</title><style>{self.css}</style></head>'
def add_row(self, a, b):
tmp = TABLE_CSS
from toolbox import markdown_convertion
tmp = tmp.replace('REPLACE_A', markdown_convertion(a))
tmp = tmp.replace('REPLACE_B', markdown_convertion(b))
self.html_string += tmp
def save_file(self, file_name):
with open(os.path.join(get_log_folder(), file_name), 'w', encoding='utf8') as f:
f.write(self.html_string.encode('utf-8', 'ignore').decode())
return os.path.join(get_log_folder(), file_name)
def get_plugin_arg(plugin_kwargs, key, default): def get_plugin_arg(plugin_kwargs, key, default):
# 如果参数是空的 # 如果参数是空的
if (key in plugin_kwargs) and (plugin_kwargs[key] == ""): plugin_kwargs.pop(key) if (key in plugin_kwargs) and (plugin_kwargs[key] == ""): plugin_kwargs.pop(key)

View File

@@ -165,7 +165,7 @@ class LatexPaperFileGroup():
self.sp_file_tag = [] self.sp_file_tag = []
# count_token # count_token
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
self.get_token_num = get_token_num self.get_token_num = get_token_num
@@ -423,7 +423,7 @@ def write_html(sp_file_contents, sp_file_result, chatbot, project_folder):
# write html # write html
try: try:
import shutil import shutil
from ..crazy_utils import construct_html from crazy_functions.pdf_fns.report_gen_html import construct_html
from toolbox import gen_time_str from toolbox import gen_time_str
ch = construct_html() ch = construct_html()
orig = "" orig = ""

View File

@@ -308,7 +308,10 @@ def merge_tex_files_(project_foler, main_file, mode):
fp = os.path.join(project_foler, f) fp = os.path.join(project_foler, f)
fp_ = find_tex_file_ignore_case(fp) fp_ = find_tex_file_ignore_case(fp)
if fp_: if fp_:
try:
with open(fp_, 'r', encoding='utf-8', errors='replace') as fx: c = fx.read() with open(fp_, 'r', encoding='utf-8', errors='replace') as fx: c = fx.read()
except:
c = f"\n\nWarning from GPT-Academic: LaTex source file is missing!\n\n"
else: else:
raise RuntimeError(f'找不到{fp}Tex源文件缺失') raise RuntimeError(f'找不到{fp}Tex源文件缺失')
c = merge_tex_files_(project_foler, c, mode) c = merge_tex_files_(project_foler, c, mode)
@@ -342,10 +345,41 @@ def merge_tex_files(project_foler, main_file, mode):
pattern_opt2 = re.compile(r"\\abstract\{(.*?)\}", flags=re.DOTALL) pattern_opt2 = re.compile(r"\\abstract\{(.*?)\}", flags=re.DOTALL)
match_opt1 = pattern_opt1.search(main_file) match_opt1 = pattern_opt1.search(main_file)
match_opt2 = pattern_opt2.search(main_file) match_opt2 = pattern_opt2.search(main_file)
if (match_opt1 is None) and (match_opt2 is None):
# "Cannot find paper abstract section!"
main_file = insert_abstract(main_file)
match_opt1 = pattern_opt1.search(main_file)
match_opt2 = pattern_opt2.search(main_file)
assert (match_opt1 is not None) or (match_opt2 is not None), "Cannot find paper abstract section!" assert (match_opt1 is not None) or (match_opt2 is not None), "Cannot find paper abstract section!"
return main_file return main_file
insert_missing_abs_str = r"""
\begin{abstract}
The GPT-Academic program cannot find abstract section in this paper.
\end{abstract}
"""
def insert_abstract(tex_content):
if "\\maketitle" in tex_content:
# find the position of "\maketitle"
find_index = tex_content.index("\\maketitle")
# find the nearest ending line
end_line_index = tex_content.find("\n", find_index)
# insert "abs_str" on the next line
modified_tex = tex_content[:end_line_index+1] + '\n\n' + insert_missing_abs_str + '\n\n' + tex_content[end_line_index+1:]
return modified_tex
elif r"\begin{document}" in tex_content:
# find the position of "\maketitle"
find_index = tex_content.index(r"\begin{document}")
# find the nearest ending line
end_line_index = tex_content.find("\n", find_index)
# insert "abs_str" on the next line
modified_tex = tex_content[:end_line_index+1] + '\n\n' + insert_missing_abs_str + '\n\n' + tex_content[end_line_index+1:]
return modified_tex
else:
return tex_content
""" """
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Post process Post process

View File

@@ -1,4 +1,106 @@
import time, logging, json import time, logging, json, sys, struct
import numpy as np
from scipy.io.wavfile import WAVE_FORMAT
def write_numpy_to_wave(filename, rate, data, add_header=False):
"""
Write a NumPy array as a WAV file.
"""
def _array_tofile(fid, data):
# ravel gives a c-contiguous buffer
fid.write(data.ravel().view('b').data)
if hasattr(filename, 'write'):
fid = filename
else:
fid = open(filename, 'wb')
fs = rate
try:
dkind = data.dtype.kind
if not (dkind == 'i' or dkind == 'f' or (dkind == 'u' and
data.dtype.itemsize == 1)):
raise ValueError("Unsupported data type '%s'" % data.dtype)
header_data = b''
header_data += b'RIFF'
header_data += b'\x00\x00\x00\x00'
header_data += b'WAVE'
# fmt chunk
header_data += b'fmt '
if dkind == 'f':
format_tag = WAVE_FORMAT.IEEE_FLOAT
else:
format_tag = WAVE_FORMAT.PCM
if data.ndim == 1:
channels = 1
else:
channels = data.shape[1]
bit_depth = data.dtype.itemsize * 8
bytes_per_second = fs*(bit_depth // 8)*channels
block_align = channels * (bit_depth // 8)
fmt_chunk_data = struct.pack('<HHIIHH', format_tag, channels, fs,
bytes_per_second, block_align, bit_depth)
if not (dkind == 'i' or dkind == 'u'):
# add cbSize field for non-PCM files
fmt_chunk_data += b'\x00\x00'
header_data += struct.pack('<I', len(fmt_chunk_data))
header_data += fmt_chunk_data
# fact chunk (non-PCM files)
if not (dkind == 'i' or dkind == 'u'):
header_data += b'fact'
header_data += struct.pack('<II', 4, data.shape[0])
# check data size (needs to be immediately before the data chunk)
if ((len(header_data)-4-4) + (4+4+data.nbytes)) > 0xFFFFFFFF:
raise ValueError("Data exceeds wave file size limit")
if add_header:
fid.write(header_data)
# data chunk
fid.write(b'data')
fid.write(struct.pack('<I', data.nbytes))
if data.dtype.byteorder == '>' or (data.dtype.byteorder == '=' and
sys.byteorder == 'big'):
data = data.byteswap()
_array_tofile(fid, data)
if add_header:
# Determine file size and place it in correct
# position at start of the file.
size = fid.tell()
fid.seek(4)
fid.write(struct.pack('<I', size-8))
finally:
if not hasattr(filename, 'write'):
fid.close()
else:
fid.seek(0)
def is_speaker_speaking(vad, data, sample_rate):
# Function to detect if the speaker is speaking
# The WebRTC VAD only accepts 16-bit mono PCM audio,
# sampled at 8000, 16000, 32000 or 48000 Hz.
# A frame must be either 10, 20, or 30 ms in duration:
frame_duration = 30
n_bit_each = int(sample_rate * frame_duration / 1000)*2 # x2 because audio is 16 bit (2 bytes)
res_list = []
for t in range(len(data)):
if t!=0 and t % n_bit_each == 0:
res_list.append(vad.is_speech(data[t-n_bit_each:t], sample_rate))
info = ''.join(['^' if r else '.' for r in res_list])
info = info[:10]
if any(res_list):
return True, info
else:
return False, info
class AliyunASR(): class AliyunASR():
@@ -66,12 +168,22 @@ class AliyunASR():
on_close=self.test_on_close, on_close=self.test_on_close,
callback_args=[uuid.hex] callback_args=[uuid.hex]
) )
timeout_limit_second = 20
r = sr.start(aformat="pcm", r = sr.start(aformat="pcm",
timeout=timeout_limit_second,
enable_intermediate_result=True, enable_intermediate_result=True,
enable_punctuation_prediction=True, enable_punctuation_prediction=True,
enable_inverse_text_normalization=True) enable_inverse_text_normalization=True)
import webrtcvad
vad = webrtcvad.Vad()
vad.set_mode(1)
is_previous_frame_transmitted = False # 上一帧是否有人说话
previous_frame_data = None
echo_cnt = 0 # 在没有声音之后继续向服务器发送n次音频数据
echo_cnt_max = 4 # 在没有声音之后继续向服务器发送n次音频数据
keep_alive_last_send_time = time.time()
while not self.stop: while not self.stop:
# time.sleep(self.capture_interval) # time.sleep(self.capture_interval)
audio = rad.read(uuid.hex) audio = rad.read(uuid.hex)
@@ -79,12 +191,32 @@ class AliyunASR():
# convert to pcm file # convert to pcm file
temp_file = f'{temp_folder}/{uuid.hex}.pcm' # temp_file = f'{temp_folder}/{uuid.hex}.pcm' #
dsdata = change_sample_rate(audio, rad.rate, NEW_SAMPLERATE) # 48000 --> 16000 dsdata = change_sample_rate(audio, rad.rate, NEW_SAMPLERATE) # 48000 --> 16000
io.wavfile.write(temp_file, NEW_SAMPLERATE, dsdata) write_numpy_to_wave(temp_file, NEW_SAMPLERATE, dsdata)
# read pcm binary # read pcm binary
with open(temp_file, "rb") as f: data = f.read() with open(temp_file, "rb") as f: data = f.read()
# print('audio len:', len(audio), '\t ds len:', len(dsdata), '\t need n send:', len(data)//640) is_speaking, info = is_speaker_speaking(vad, data, NEW_SAMPLERATE)
if is_speaking or echo_cnt > 0:
# 如果话筒激活 / 如果处于回声收尾阶段
echo_cnt -= 1
if not is_previous_frame_transmitted: # 上一帧没有人声,但是我们把上一帧同样加上
if previous_frame_data is not None: data = previous_frame_data + data
if is_speaking:
echo_cnt = echo_cnt_max
slices = zip(*(iter(data),) * 640) # 640个字节为一组 slices = zip(*(iter(data),) * 640) # 640个字节为一组
for i in slices: sr.send_audio(bytes(i)) for i in slices: sr.send_audio(bytes(i))
keep_alive_last_send_time = time.time()
is_previous_frame_transmitted = True
else:
is_previous_frame_transmitted = False
echo_cnt = 0
# 保持链接激活,即使没有声音,也根据时间间隔,发送一些音频片段给服务器
if time.time() - keep_alive_last_send_time > timeout_limit_second/2:
slices = zip(*(iter(data),) * 640) # 640个字节为一组
for i in slices: sr.send_audio(bytes(i))
keep_alive_last_send_time = time.time()
is_previous_frame_transmitted = True
self.audio_shape = info
else: else:
time.sleep(0.1) time.sleep(0.1)

View File

@@ -35,7 +35,7 @@ class RealtimeAudioDistribution():
def read(self, uuid): def read(self, uuid):
if uuid in self.data: if uuid in self.data:
res = self.data.pop(uuid) res = self.data.pop(uuid)
print('\r read-', len(res), '-', max(res), end='', flush=True) # print('\r read-', len(res), '-', max(res), end='', flush=True)
else: else:
res = None res = None
return res return res

View File

@@ -0,0 +1,45 @@
from pydantic import BaseModel, Field
from typing import List
from toolbox import update_ui_lastest_msg, disable_auto_promotion
from request_llms.bridge_all import predict_no_ui_long_connection
from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError
import time
import pickle
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
class GptAcademicState():
def __init__(self):
self.reset()
def reset(self):
pass
def lock_plugin(self, chatbot):
chatbot._cookies['plugin_state'] = pickle.dumps(self)
def unlock_plugin(self, chatbot):
self.reset()
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, cls=None):
state = chatbot._cookies.get('plugin_state', None)
if state is not None: state = pickle.loads(state)
elif cls is not None: state = cls()
else: state = GptAcademicState()
state.chatbot = chatbot
return state
class GatherMaterials():
def __init__(self, materials) -> None:
materials = ['image', 'prompt']

View File

@@ -14,7 +14,7 @@ import math
class GROBID_OFFLINE_EXCEPTION(Exception): pass class GROBID_OFFLINE_EXCEPTION(Exception): pass
def get_avail_grobid_url(): def get_avail_grobid_url():
GROBID_URLS, = get_conf('GROBID_URLS') GROBID_URLS = get_conf('GROBID_URLS')
if len(GROBID_URLS) == 0: return None if len(GROBID_URLS) == 0: return None
try: try:
_grobid_url = random.choice(GROBID_URLS) # 随机负载均衡 _grobid_url = random.choice(GROBID_URLS) # 随机负载均衡
@@ -73,7 +73,7 @@ def produce_report_markdown(gpt_response_collection, meta, paper_meta_info, chat
return res_path return res_path
def translate_pdf(article_dict, llm_kwargs, chatbot, fp, generated_conclusion_files, TOKEN_LIMIT_PER_FRAGMENT, DST_LANG): def translate_pdf(article_dict, llm_kwargs, chatbot, fp, generated_conclusion_files, TOKEN_LIMIT_PER_FRAGMENT, DST_LANG):
from crazy_functions.crazy_utils import construct_html from crazy_functions.pdf_fns.report_gen_html import construct_html
from crazy_functions.crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf from crazy_functions.crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from crazy_functions.crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency from crazy_functions.crazy_utils import request_gpt_model_multi_threads_with_very_awesome_ui_and_high_efficiency
@@ -103,7 +103,7 @@ def translate_pdf(article_dict, llm_kwargs, chatbot, fp, generated_conclusion_fi
inputs_show_user_array = [] inputs_show_user_array = []
# get_token_num # get_token_num
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info[llm_kwargs['llm_model']]['tokenizer'] enc = model_info[llm_kwargs['llm_model']]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))

View File

@@ -0,0 +1,58 @@
from toolbox import update_ui, get_conf, trimmed_format_exc, get_log_folder
import os
class construct_html():
def __init__(self) -> None:
self.html_string = ""
def add_row(self, a, b):
from toolbox import markdown_convertion
template = """
{
primary_col: {
header: String.raw`__PRIMARY_HEADER__`,
msg: String.raw`__PRIMARY_MSG__`,
},
secondary_rol: {
header: String.raw`__SECONDARY_HEADER__`,
msg: String.raw`__SECONDARY_MSG__`,
}
},
"""
def std(str):
str = str.replace(r'`',r'&#96;')
if str.endswith("\\"): str += ' '
if str.endswith("}"): str += ' '
if str.endswith("$"): str += ' '
return str
template_ = template
a_lines = a.split('\n')
b_lines = b.split('\n')
if len(a_lines) == 1 or len(a_lines[0]) > 50:
template_ = template_.replace("__PRIMARY_HEADER__", std(a[:20]))
template_ = template_.replace("__PRIMARY_MSG__", std(markdown_convertion(a)))
else:
template_ = template_.replace("__PRIMARY_HEADER__", std(a_lines[0]))
template_ = template_.replace("__PRIMARY_MSG__", std(markdown_convertion('\n'.join(a_lines[1:]))))
if len(b_lines) == 1 or len(b_lines[0]) > 50:
template_ = template_.replace("__SECONDARY_HEADER__", std(b[:20]))
template_ = template_.replace("__SECONDARY_MSG__", std(markdown_convertion(b)))
else:
template_ = template_.replace("__SECONDARY_HEADER__", std(b_lines[0]))
template_ = template_.replace("__SECONDARY_MSG__", std(markdown_convertion('\n'.join(b_lines[1:]))))
self.html_string += template_
def save_file(self, file_name):
from toolbox import get_log_folder
with open('crazy_functions/pdf_fns/report_template.html', 'r', encoding='utf8') as f:
html_template = f.read()
html_template = html_template.replace("__TF_ARR__", self.html_string)
with open(os.path.join(get_log_folder(), file_name), 'w', encoding='utf8') as f:
f.write(html_template.encode('utf-8', 'ignore').decode())
return os.path.join(get_log_folder(), file_name)

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing import List from typing import List
from toolbox import update_ui_lastest_msg, disable_auto_promotion from toolbox import update_ui_lastest_msg, disable_auto_promotion
from request_llm.bridge_all import predict_no_ui_long_connection from request_llms.bridge_all import predict_no_ui_long_connection
from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError
import copy, json, pickle, os, sys, time import copy, json, pickle, os, sys, time

View File

@@ -1,13 +1,13 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing import List from typing import List
from toolbox import update_ui_lastest_msg, get_conf from toolbox import update_ui_lastest_msg, get_conf
from request_llm.bridge_all import predict_no_ui_long_connection from request_llms.bridge_all import predict_no_ui_long_connection
from crazy_functions.json_fns.pydantic_io import GptJsonIO from crazy_functions.json_fns.pydantic_io import GptJsonIO
import copy, json, pickle, os, sys import copy, json, pickle, os, sys
def modify_configuration_hot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention): def modify_configuration_hot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention):
ALLOW_RESET_CONFIG, = get_conf('ALLOW_RESET_CONFIG') ALLOW_RESET_CONFIG = get_conf('ALLOW_RESET_CONFIG')
if not ALLOW_RESET_CONFIG: if not ALLOW_RESET_CONFIG:
yield from update_ui_lastest_msg( yield from update_ui_lastest_msg(
lastmsg=f"当前配置不允许被修改如需激活本功能请在config.py中设置ALLOW_RESET_CONFIG=True后重启软件。", lastmsg=f"当前配置不允许被修改如需激活本功能请在config.py中设置ALLOW_RESET_CONFIG=True后重启软件。",
@@ -66,7 +66,7 @@ def modify_configuration_hot(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
) )
def modify_configuration_reboot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention): def modify_configuration_reboot(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, user_intention):
ALLOW_RESET_CONFIG, = get_conf('ALLOW_RESET_CONFIG') ALLOW_RESET_CONFIG = get_conf('ALLOW_RESET_CONFIG')
if not ALLOW_RESET_CONFIG: if not ALLOW_RESET_CONFIG:
yield from update_ui_lastest_msg( yield from update_ui_lastest_msg(
lastmsg=f"当前配置不允许被修改如需激活本功能请在config.py中设置ALLOW_RESET_CONFIG=True后重启软件。", lastmsg=f"当前配置不允许被修改如需激活本功能请在config.py中设置ALLOW_RESET_CONFIG=True后重启软件。",

View File

@@ -1,6 +1,6 @@
from toolbox import update_ui, get_log_folder from toolbox import update_ui, get_log_folder
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from toolbox import CatchException, report_execption, get_conf from toolbox import CatchException, report_exception, get_conf
import re, requests, unicodedata, os import re, requests, unicodedata, os
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
def download_arxiv_(url_pdf): def download_arxiv_(url_pdf):
@@ -43,7 +43,7 @@ def download_arxiv_(url_pdf):
file_path = download_dir+title_str file_path = download_dir+title_str
print('下载中') print('下载中')
proxies, = get_conf('proxies') proxies = get_conf('proxies')
r = requests.get(requests_pdf_url, proxies=proxies) r = requests.get(requests_pdf_url, proxies=proxies)
with open(file_path, 'wb+') as f: with open(file_path, 'wb+') as f:
f.write(r.content) f.write(r.content)
@@ -77,7 +77,7 @@ def get_name(_url_):
# print('在缓存中') # print('在缓存中')
# return arxiv_recall[_url_] # return arxiv_recall[_url_]
proxies, = get_conf('proxies') proxies = get_conf('proxies')
res = requests.get(_url_, proxies=proxies) res = requests.get(_url_, proxies=proxies)
bs = BeautifulSoup(res.text, 'html.parser') bs = BeautifulSoup(res.text, 'html.parser')
@@ -144,7 +144,7 @@ def 下载arxiv论文并翻译摘要(txt, llm_kwargs, plugin_kwargs, chatbot, hi
try: try:
import bs4 import bs4
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -157,7 +157,7 @@ def 下载arxiv论文并翻译摘要(txt, llm_kwargs, plugin_kwargs, chatbot, hi
try: try:
pdf_path, info = download_arxiv_(txt) pdf_path, info = download_arxiv_(txt)
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"下载pdf文件未成功") b = f"下载pdf文件未成功")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面

View File

@@ -1,13 +1,12 @@
from toolbox import CatchException, update_ui, get_conf, select_api_key, get_log_folder from toolbox import CatchException, update_ui, get_conf, select_api_key, get_log_folder
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from crazy_functions.multi_stage.multi_stage_utils import GptAcademicState
import datetime
def gen_image(llm_kwargs, prompt, resolution="256x256"): def gen_image(llm_kwargs, prompt, resolution="1024x1024", model="dall-e-2"):
import requests, json, time, os import requests, json, time, os
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
proxies, = get_conf('proxies') proxies = get_conf('proxies')
# Set up OpenAI API key and model # Set up OpenAI API key and model
api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model']) api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])
chat_endpoint = model_info[llm_kwargs['llm_model']]['endpoint'] chat_endpoint = model_info[llm_kwargs['llm_model']]['endpoint']
@@ -23,6 +22,7 @@ def gen_image(llm_kwargs, prompt, resolution="256x256"):
'prompt': prompt, 'prompt': prompt,
'n': 1, 'n': 1,
'size': resolution, 'size': resolution,
'model': model,
'response_format': 'url' 'response_format': 'url'
} }
response = requests.post(url, headers=headers, json=data, proxies=proxies) response = requests.post(url, headers=headers, json=data, proxies=proxies)
@@ -42,9 +42,48 @@ def gen_image(llm_kwargs, prompt, resolution="256x256"):
return image_url, file_path+file_name return image_url, file_path+file_name
def edit_image(llm_kwargs, prompt, image_path, resolution="1024x1024", model="dall-e-2"):
import requests, json, time, os
from request_llms.bridge_all import model_info
proxies = get_conf('proxies')
api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])
chat_endpoint = model_info[llm_kwargs['llm_model']]['endpoint']
# 'https://api.openai.com/v1/chat/completions'
img_endpoint = chat_endpoint.replace('chat/completions','images/edits')
# # Generate the image
url = img_endpoint
headers = {
'Authorization': f"Bearer {api_key}",
'Content-Type': 'application/json'
}
data = {
'image': open(image_path, 'rb'),
'prompt': prompt,
'n': 1,
'size': resolution,
'model': model,
'response_format': 'url'
}
response = requests.post(url, headers=headers, json=data, proxies=proxies)
print(response.content)
try:
image_url = json.loads(response.content.decode('utf8'))['data'][0]['url']
except:
raise RuntimeError(response.content.decode())
# 文件保存到本地
r = requests.get(image_url, proxies=proxies)
file_path = f'{get_log_folder()}/image_gen/'
os.makedirs(file_path, exist_ok=True)
file_name = 'Image' + time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.png'
with open(file_path+file_name, 'wb+') as f: f.write(r.content)
return image_url, file_path+file_name
@CatchException @CatchException
def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port): def 图片生成_DALLE2(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
""" """
txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径 txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径
llm_kwargs gpt模型参数如温度和top_p等一般原样传递下去就行 llm_kwargs gpt模型参数如温度和top_p等一般原样传递下去就行
@@ -58,7 +97,7 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 .....")) chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 ....."))
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新
if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg") if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
resolution = plugin_kwargs.get("advanced_arg", '256x256') resolution = plugin_kwargs.get("advanced_arg", '1024x1024')
image_url, image_path = gen_image(llm_kwargs, prompt, resolution) image_url, image_path = gen_image(llm_kwargs, prompt, resolution)
chatbot.append([prompt, chatbot.append([prompt,
f'图像中转网址: <br/>`{image_url}`<br/>'+ f'图像中转网址: <br/>`{image_url}`<br/>'+
@@ -67,3 +106,92 @@ def 图片生成(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
f'本地文件预览: <br/><div align="center"><img src="file={image_path}"></div>' f'本地文件预览: <br/><div align="center"><img src="file={image_path}"></div>'
]) ])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新
@CatchException
def 图片生成_DALLE3(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
history = [] # 清空历史,以免输入溢出
chatbot.append(("这是什么功能?", "[Local Message] 生成图像, 请先把模型切换至gpt-*或者api2d-*。如果中文效果不理想, 请尝试英文Prompt。正在处理中 ....."))
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新
if ("advanced_arg" in plugin_kwargs) and (plugin_kwargs["advanced_arg"] == ""): plugin_kwargs.pop("advanced_arg")
resolution = plugin_kwargs.get("advanced_arg", '1024x1024')
image_url, image_path = gen_image(llm_kwargs, prompt, resolution)
chatbot.append([prompt,
f'图像中转网址: <br/>`{image_url}`<br/>'+
f'中转网址预览: <br/><div align="center"><img src="{image_url}"></div>'
f'本地文件地址: <br/>`{image_path}`<br/>'+
f'本地文件预览: <br/><div align="center"><img src="file={image_path}"></div>'
])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新
class ImageEditState(GptAcademicState):
def get_image_file(self, x):
import os, glob
if len(x) == 0: return False, None
if not os.path.exists(x): return False, None
if x.endswith('.png'): return True, x
file_manifest = [f for f in glob.glob(f'{x}/**/*.png', recursive=True)]
confirm = (len(file_manifest) >= 1 and file_manifest[0].endswith('.png') and os.path.exists(file_manifest[0]))
file = None if not confirm else file_manifest[0]
return confirm, file
def get_resolution(self, x):
return (x in ['256x256', '512x512', '1024x1024']), x
def get_prompt(self, x):
confirm = (len(x)>=5) and (not self.get_resolution(x)[0]) and (not self.get_image_file(x)[0])
return confirm, x
def reset(self):
self.req = [
{'value':None, 'description': '请先上传图像(必须是.png格式, 然后再次点击本插件', 'verify_fn': self.get_image_file},
{'value':None, 'description': '请输入分辨率可选256x256, 512x512 或 1024x1024', 'verify_fn': self.get_resolution},
{'value':None, 'description': '请输入修改需求,建议您使用英文提示词', 'verify_fn': self.get_prompt},
]
self.info = ""
def feed(self, prompt, chatbot):
for r in self.req:
if r['value'] is None:
confirm, res = r['verify_fn'](prompt)
if confirm:
r['value'] = res
self.set_state(chatbot, 'dummy_key', 'dummy_value')
break
return self
def next_req(self):
for r in self.req:
if r['value'] is None:
return r['description']
return "已经收集到所有信息"
def already_obtained_all_materials(self):
return all([x['value'] is not None for x in self.req])
@CatchException
def 图片修改_DALLE2(prompt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
history = [] # 清空历史
state = ImageEditState.get_state(chatbot, ImageEditState)
state = state.feed(prompt, chatbot)
if not state.already_obtained_all_materials():
chatbot.append(["图片修改(先上传图片,再输入修改需求,最后输入分辨率)", state.next_req()])
yield from update_ui(chatbot=chatbot, history=history)
return
image_path = state.req[0]
resolution = state.req[1]
prompt = state.req[2]
chatbot.append(["图片修改, 执行中", f"图片:`{image_path}`<br/>分辨率:`{resolution}`<br/>修改需求:`{prompt}`"])
yield from update_ui(chatbot=chatbot, history=history)
image_url, image_path = edit_image(llm_kwargs, prompt, image_path, resolution)
chatbot.append([state.prompt,
f'图像中转网址: <br/>`{image_url}`<br/>'+
f'中转网址预览: <br/><div align="center"><img src="{image_url}"></div>'
f'本地文件地址: <br/>`{image_path}`<br/>'+
f'本地文件预览: <br/><div align="center"><img src="file={image_path}"></div>'
])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 界面更新

View File

@@ -0,0 +1,108 @@
# 本源代码中, ⭐ = 关键步骤
"""
测试:
- show me the solution of $x^2=cos(x)$, solve this problem with figure, and plot and save image to t.jpg
"""
from toolbox import CatchException, update_ui, gen_time_str, trimmed_format_exc, ProxyNetworkActivate
from toolbox import get_conf, select_api_key, update_ui_lastest_msg, Singleton
from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, get_plugin_arg
from crazy_functions.crazy_utils import input_clipping, try_install_deps
from crazy_functions.agent_fns.persistent import GradioMultiuserManagerForPersistentClasses
from crazy_functions.agent_fns.auto_agent import AutoGenMath
import time
def remove_model_prefix(llm):
if llm.startswith('api2d-'): llm = llm.replace('api2d-', '')
if llm.startswith('azure-'): llm = llm.replace('azure-', '')
return llm
@CatchException
def 多智能体终端(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
"""
txt 输入栏用户输入的文本,例如需要翻译的一段话,再例如一个包含了待处理文件的路径
llm_kwargs gpt模型参数如温度和top_p等一般原样传递下去就行
plugin_kwargs 插件模型的参数
chatbot 聊天显示框的句柄,用于显示给用户
history 聊天历史,前情提要
system_prompt 给gpt的静默提醒
web_port 当前软件运行的端口号
"""
# 检查当前的模型是否符合要求
supported_llms = [
"gpt-3.5-turbo-16k",
'gpt-3.5-turbo-1106',
"gpt-4",
"gpt-4-32k",
'gpt-4-1106-preview',
"azure-gpt-3.5-turbo-16k",
"azure-gpt-3.5-16k",
"azure-gpt-4",
"azure-gpt-4-32k",
]
from request_llms.bridge_all import model_info
if model_info[llm_kwargs['llm_model']]["max_token"] < 8000: # 至少是8k上下文的模型
chatbot.append([f"处理任务: {txt}", f"当前插件只支持{str(supported_llms)}, 当前模型{llm_kwargs['llm_model']}的最大上下文长度太短, 不能支撑AutoGen运行。"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
if model_info[llm_kwargs['llm_model']]["endpoint"] is not None: # 如果不是本地模型加载API_KEY
llm_kwargs['api_key'] = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])
# 检查当前的模型是否符合要求
API_URL_REDIRECT = get_conf('API_URL_REDIRECT')
if len(API_URL_REDIRECT) > 0:
chatbot.append([f"处理任务: {txt}", f"暂不支持中转."])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
# 尝试导入依赖,如果缺少依赖,则给出安装建议
try:
import autogen
if get_conf("AUTOGEN_USE_DOCKER"):
import docker
except:
chatbot.append([ f"处理任务: {txt}",
f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pyautogen docker```。"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
# 尝试导入依赖,如果缺少依赖,则给出安装建议
try:
import autogen
import glob, os, time, subprocess
if get_conf("AUTOGEN_USE_DOCKER"):
subprocess.Popen(["docker", "--version"])
except:
chatbot.append([f"处理任务: {txt}", f"缺少docker运行环境"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
# 解锁插件
chatbot.get_cookies()['lock_plugin'] = None
persistent_class_multi_user_manager = GradioMultiuserManagerForPersistentClasses()
user_uuid = chatbot.get_cookies().get('uuid')
persistent_key = f"{user_uuid}->多智能体终端"
if persistent_class_multi_user_manager.already_alive(persistent_key):
# 当已经存在一个正在运行的多智能体终端时,直接将用户输入传递给它,而不是再次启动一个新的多智能体终端
print('[debug] feed new user input')
executor = persistent_class_multi_user_manager.get(persistent_key)
exit_reason = yield from executor.main_process_ui_control(txt, create_or_resume="resume")
else:
# 运行多智能体终端 (首次)
print('[debug] create new executor instance')
history = []
chatbot.append(["正在启动: 多智能体终端", "插件动态生成, 执行开始, 作者 Microsoft & Binary-Husky."])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
executor = AutoGenMath(llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port)
persistent_class_multi_user_manager.set(persistent_key, executor)
exit_reason = yield from executor.main_process_ui_control(txt, create_or_resume="create")
if exit_reason == "wait_feedback":
# 当用户点击了“等待反馈”按钮时将executor存储到cookie中等待用户的再次调用
executor.chatbot.get_cookies()['lock_plugin'] = 'crazy_functions.多智能体->多智能体终端'
else:
executor.chatbot.get_cookies()['lock_plugin'] = None
yield from update_ui(chatbot=executor.chatbot, history=executor.history) # 更新状态

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
fast_debug = False fast_debug = False
@@ -32,7 +32,7 @@ def 解析docx(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot
print(file_content) print(file_content)
# private_upload里面的文件名在解压zip后容易出现乱码rar和7z格式正常故可以只分析文章内容不输入文件名 # private_upload里面的文件名在解压zip后容易出现乱码rar和7z格式正常故可以只分析文章内容不输入文件名
from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
max_token = model_info[llm_kwargs['llm_model']]['max_token'] max_token = model_info[llm_kwargs['llm_model']]['max_token']
TOKEN_LIMIT_PER_FRAGMENT = max_token * 3 // 4 TOKEN_LIMIT_PER_FRAGMENT = max_token * 3 // 4
paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf( paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf(
@@ -97,7 +97,7 @@ def 总结word文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pr
try: try:
from docx import Document from docx import Document
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade python-docx pywin32```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -111,7 +111,7 @@ def 总结word文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pr
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -124,7 +124,7 @@ def 总结word文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pr
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何.docx或doc文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,4 +1,4 @@
from toolbox import CatchException, report_execption, select_api_key, update_ui, get_conf from toolbox import CatchException, report_exception, select_api_key, update_ui, get_conf
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from toolbox import write_history_to_file, promote_file_to_downloadzone, get_log_folder from toolbox import write_history_to_file, promote_file_to_downloadzone, get_log_folder
@@ -41,7 +41,7 @@ def split_audio_file(filename, split_duration=1000):
def AnalyAudio(parse_prompt, file_manifest, llm_kwargs, chatbot, history): def AnalyAudio(parse_prompt, file_manifest, llm_kwargs, chatbot, history):
import os, requests import os, requests
from moviepy.editor import AudioFileClip from moviepy.editor import AudioFileClip
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
# 设置OpenAI密钥和模型 # 设置OpenAI密钥和模型
api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model']) api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])
@@ -79,7 +79,7 @@ def AnalyAudio(parse_prompt, file_manifest, llm_kwargs, chatbot, history):
chatbot.append([f"{i} 发送到openai音频解析终端 (whisper),当前参数:{parse_prompt}", "正在处理 ..."]) chatbot.append([f"{i} 发送到openai音频解析终端 (whisper),当前参数:{parse_prompt}", "正在处理 ..."])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
proxies, = get_conf('proxies') proxies = get_conf('proxies')
response = requests.post(url, headers=headers, files=files, data=data, proxies=proxies).text response = requests.post(url, headers=headers, files=files, data=data, proxies=proxies).text
chatbot.append(["音频解析结果", response]) chatbot.append(["音频解析结果", response])
@@ -144,7 +144,7 @@ def 总结音视频(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
try: try:
from moviepy.editor import AudioFileClip from moviepy.editor import AudioFileClip
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade moviepy```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade moviepy```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -158,7 +158,7 @@ def 总结音视频(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -174,7 +174,7 @@ def 总结音视频(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何音频或视频文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何音频或视频文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,6 +1,6 @@
import glob, time, os, re, logging import glob, time, os, re, logging
from toolbox import update_ui, trimmed_format_exc, gen_time_str, disable_auto_promotion from toolbox import update_ui, trimmed_format_exc, gen_time_str, disable_auto_promotion
from toolbox import CatchException, report_execption, get_log_folder from toolbox import CatchException, report_exception, get_log_folder
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
fast_debug = False fast_debug = False
@@ -13,7 +13,7 @@ class PaperFileGroup():
self.sp_file_tag = [] self.sp_file_tag = []
# count_token # count_token
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
self.get_token_num = get_token_num self.get_token_num = get_token_num
@@ -118,7 +118,7 @@ def get_files_from_everything(txt, preference=''):
if txt.startswith('http'): if txt.startswith('http'):
import requests import requests
from toolbox import get_conf from toolbox import get_conf
proxies, = get_conf('proxies') proxies = get_conf('proxies')
# 网络的远程文件 # 网络的远程文件
if preference == 'Github': if preference == 'Github':
logging.info('正在从github下载资源 ...') logging.info('正在从github下载资源 ...')
@@ -165,7 +165,7 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -177,12 +177,12 @@ def Markdown英译中(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
if not success: if not success:
# 什么都没有 # 什么都没有
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -205,7 +205,7 @@ def Markdown中译英(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -215,11 +215,11 @@ def Markdown中译英(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
if not success: if not success:
# 什么都没有 # 什么都没有
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh->en') yield from 多文件翻译(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='zh->en')
@@ -238,7 +238,7 @@ def Markdown翻译指定语言(txt, llm_kwargs, plugin_kwargs, chatbot, history,
try: try:
import tiktoken import tiktoken
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -248,11 +248,11 @@ def Markdown翻译指定语言(txt, llm_kwargs, plugin_kwargs, chatbot, history,
if not success: if not success:
# 什么都没有 # 什么都没有
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.md文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui, promote_file_to_downloadzone, gen_time_str from toolbox import update_ui, promote_file_to_downloadzone, gen_time_str
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from .crazy_utils import read_and_clean_pdf_text from .crazy_utils import read_and_clean_pdf_text
@@ -21,7 +21,7 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
TOKEN_LIMIT_PER_FRAGMENT = 2500 TOKEN_LIMIT_PER_FRAGMENT = 2500
from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf( paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf(
@@ -119,7 +119,7 @@ def 批量总结PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
try: try:
import fitz import fitz
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -133,7 +133,7 @@ def 批量总结PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -142,7 +142,7 @@ def 批量总结PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或.pdf文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
@@ -138,7 +138,7 @@ def 批量总结PDF文档pdfminer(txt, llm_kwargs, plugin_kwargs, chatbot, histo
try: try:
import pdfminer, bs4 import pdfminer, bs4
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pdfminer beautifulsoup4```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -147,7 +147,7 @@ def 批量总结PDF文档pdfminer(txt, llm_kwargs, plugin_kwargs, chatbot, histo
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] + \
@@ -155,7 +155,7 @@ def 批量总结PDF文档pdfminer(txt, llm_kwargs, plugin_kwargs, chatbot, histo
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \ # [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex或pdf文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析Paper(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析Paper(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)

View File

@@ -1,4 +1,4 @@
from toolbox import CatchException, report_execption, get_log_folder, gen_time_str from toolbox import CatchException, report_exception, get_log_folder, gen_time_str
from toolbox import update_ui, promote_file_to_downloadzone, update_ui_lastest_msg, disable_auto_promotion from toolbox import update_ui, promote_file_to_downloadzone, update_ui_lastest_msg, disable_auto_promotion
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
@@ -57,30 +57,35 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
"批量翻译PDF文档。函数插件贡献者: Binary-Husky"]) "批量翻译PDF文档。函数插件贡献者: Binary-Husky"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
# 尝试导入依赖,如果缺少依赖,则给出安装建议
try:
import nougat
import tiktoken
except:
report_execption(chatbot, history,
a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade nougat-ocr tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
# 清空历史,以免输入溢出 # 清空历史,以免输入溢出
history = [] history = []
from .crazy_utils import get_files_from_everything from .crazy_utils import get_files_from_everything
success, file_manifest, project_folder = get_files_from_everything(txt, type='.pdf') success, file_manifest, project_folder = get_files_from_everything(txt, type='.pdf')
if len(file_manifest) > 0:
# 尝试导入依赖,如果缺少依赖,则给出安装建议
try:
import nougat
import tiktoken
except:
report_exception(chatbot, history,
a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade nougat-ocr tiktoken```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return
success_mmd, file_manifest_mmd, _ = get_files_from_everything(txt, type='.mmd')
success = success or success_mmd
file_manifest += file_manifest_mmd
chatbot.append(["文件列表:", ", ".join([e.split('/')[-1] for e in file_manifest])]);
yield from update_ui( chatbot=chatbot, history=history)
# 检测输入参数,如没有给定输入参数,直接退出 # 检测输入参数,如没有给定输入参数,直接退出
if not success: if not success:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.pdf拓展名的文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -97,12 +102,17 @@ def 解析PDF_基于NOUGAT(file_manifest, project_folder, llm_kwargs, plugin_kwa
generated_conclusion_files = [] generated_conclusion_files = []
generated_html_files = [] generated_html_files = []
DST_LANG = "中文" DST_LANG = "中文"
from crazy_functions.crazy_utils import nougat_interface, construct_html from crazy_functions.crazy_utils import nougat_interface
from crazy_functions.pdf_fns.report_gen_html import construct_html
nougat_handle = nougat_interface() nougat_handle = nougat_interface()
for index, fp in enumerate(file_manifest): for index, fp in enumerate(file_manifest):
if fp.endswith('pdf'):
chatbot.append(["当前进度:", f"正在解析论文请稍候。第一次运行时需要花费较长时间下载NOUGAT参数"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 chatbot.append(["当前进度:", f"正在解析论文请稍候。第一次运行时需要花费较长时间下载NOUGAT参数"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
fpp = yield from nougat_handle.NOUGAT_parse_pdf(fp, chatbot, history) fpp = yield from nougat_handle.NOUGAT_parse_pdf(fp, chatbot, history)
promote_file_to_downloadzone(fpp, rename_file=os.path.basename(fpp)+'.nougat.mmd', chatbot=chatbot) promote_file_to_downloadzone(fpp, rename_file=os.path.basename(fpp)+'.nougat.mmd', chatbot=chatbot)
else:
chatbot.append(["当前论文无需解析:", fp]); yield from update_ui( chatbot=chatbot, history=history)
fpp = fp
with open(fpp, 'r', encoding='utf8') as f: with open(fpp, 'r', encoding='utf8') as f:
article_content = f.readlines() article_content = f.readlines()
article_dict = markdown_to_dict(article_content) article_dict = markdown_to_dict(article_content)

View File

@@ -1,4 +1,4 @@
from toolbox import CatchException, report_execption, get_log_folder, gen_time_str from toolbox import CatchException, report_exception, get_log_folder, gen_time_str
from toolbox import update_ui, promote_file_to_downloadzone, update_ui_lastest_msg, disable_auto_promotion from toolbox import update_ui, promote_file_to_downloadzone, update_ui_lastest_msg, disable_auto_promotion
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
@@ -26,7 +26,7 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
import tiktoken import tiktoken
import scipdf import scipdf
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", a=f"解析项目: {txt}",
b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken scipdf_parser```。") b=f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf tiktoken scipdf_parser```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -43,8 +43,8 @@ def 批量翻译PDF文档(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.pdf拓展名的文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -63,7 +63,7 @@ def 解析PDF_基于GROBID(file_manifest, project_folder, llm_kwargs, plugin_kwa
generated_conclusion_files = [] generated_conclusion_files = []
generated_html_files = [] generated_html_files = []
DST_LANG = "中文" DST_LANG = "中文"
from crazy_functions.crazy_utils import construct_html from crazy_functions.pdf_fns.report_gen_html import construct_html
for index, fp in enumerate(file_manifest): for index, fp in enumerate(file_manifest):
chatbot.append(["当前进度:", f"正在连接GROBID服务请稍候: {grobid_url}\n如果等待时间过长请修改config中的GROBID_URL可修改成本地GROBID服务。"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 chatbot.append(["当前进度:", f"正在连接GROBID服务请稍候: {grobid_url}\n如果等待时间过长请修改config中的GROBID_URL可修改成本地GROBID服务。"]); yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
article_dict = parse_pdf(fp, grobid_url) article_dict = parse_pdf(fp, grobid_url)
@@ -86,7 +86,7 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
TOKEN_LIMIT_PER_FRAGMENT = 1024 TOKEN_LIMIT_PER_FRAGMENT = 1024
generated_conclusion_files = [] generated_conclusion_files = []
generated_html_files = [] generated_html_files = []
from crazy_functions.crazy_utils import construct_html from crazy_functions.pdf_fns.report_gen_html import construct_html
for index, fp in enumerate(file_manifest): for index, fp in enumerate(file_manifest):
# 读取PDF文件 # 读取PDF文件
file_content, page_one = read_and_clean_pdf_text(fp) file_content, page_one = read_and_clean_pdf_text(fp)
@@ -95,7 +95,7 @@ def 解析PDF(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot,
# 递归地切割PDF文件 # 递归地切割PDF文件
from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf( paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf(

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from .crazy_utils import read_and_clean_pdf_text from .crazy_utils import read_and_clean_pdf_text
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
fast_debug = False fast_debug = False
@@ -19,7 +19,7 @@ def 解析PDF(file_name, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
TOKEN_LIMIT_PER_FRAGMENT = 2500 TOKEN_LIMIT_PER_FRAGMENT = 2500
from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf from .crazy_utils import breakdown_txt_to_satisfy_token_limit_for_pdf
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len(enc.encode(txt, disallowed_special=())) def get_token_num(txt): return len(enc.encode(txt, disallowed_special=()))
paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf( paper_fragments = breakdown_txt_to_satisfy_token_limit_for_pdf(
@@ -49,7 +49,7 @@ def 解析PDF(file_name, llm_kwargs, plugin_kwargs, chatbot, history, system_pro
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(i_say, i_say_show_user, # i_say=真正给chatgpt的提问 i_say_show_user=给用户看的提问 gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(i_say, i_say_show_user, # i_say=真正给chatgpt的提问 i_say_show_user=给用户看的提问
llm_kwargs, chatbot, llm_kwargs, chatbot,
history=["The main idea of the previous section is?", last_iteration_result], # 迭代上一次的结果 history=["The main idea of the previous section is?", last_iteration_result], # 迭代上一次的结果
sys_prompt="Extract the main idea of this section." # 提示 sys_prompt="Extract the main idea of this section, answer me with Chinese." # 提示
) )
iteration_results.append(gpt_say) iteration_results.append(gpt_say)
last_iteration_result = gpt_say last_iteration_result = gpt_say
@@ -81,7 +81,7 @@ def 理解PDF文档内容标准文件输入(txt, llm_kwargs, plugin_kwargs, chat
try: try:
import fitz import fitz
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade pymupdf```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@@ -96,7 +96,7 @@ def 理解PDF文档内容标准文件输入(txt, llm_kwargs, plugin_kwargs, chat
else: else:
if txt == "": if txt == "":
txt = '空空如也的输入栏' txt = '空空如也的输入栏'
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -105,7 +105,7 @@ def 理解PDF文档内容标准文件输入(txt, llm_kwargs, plugin_kwargs, chat
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.pdf', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.pdf', recursive=True)]
# 如果没找到任何文件 # 如果没找到任何文件
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.tex或.pdf文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
fast_debug = False fast_debug = False
@@ -43,14 +43,14 @@ def 批量生成函数注释(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 生成函数注释(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 生成函数注释(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)

View File

@@ -2,7 +2,7 @@ from toolbox import CatchException, update_ui
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, input_clipping from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, input_clipping
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
def google(query, proxies): def google(query, proxies):
query = query # 在此处替换您要搜索的关键词 query = query # 在此处替换您要搜索的关键词
@@ -72,7 +72,7 @@ def 连接网络回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
# ------------- < 第1步爬取搜索引擎的结果 > ------------- # ------------- < 第1步爬取搜索引擎的结果 > -------------
from toolbox import get_conf from toolbox import get_conf
proxies, = get_conf('proxies') proxies = get_conf('proxies')
urls = google(txt, proxies) urls = google(txt, proxies)
history = [] history = []
if len(urls) == 0: if len(urls) == 0:

View File

@@ -2,7 +2,7 @@ from toolbox import CatchException, update_ui
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, input_clipping from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive, input_clipping
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
def bing_search(query, proxies=None): def bing_search(query, proxies=None):
@@ -72,7 +72,7 @@ def 连接bing搜索回答问题(txt, llm_kwargs, plugin_kwargs, chatbot, histor
# ------------- < 第1步爬取搜索引擎的结果 > ------------- # ------------- < 第1步爬取搜索引擎的结果 > -------------
from toolbox import get_conf from toolbox import get_conf
proxies, = get_conf('proxies') proxies = get_conf('proxies')
urls = bing_search(txt, proxies) urls = bing_search(txt, proxies)
history = [] history = []
if len(urls) == 0: if len(urls) == 0:

View File

@@ -48,7 +48,7 @@ from pydantic import BaseModel, Field
from typing import List from typing import List
from toolbox import CatchException, update_ui, is_the_upload_folder from toolbox import CatchException, update_ui, is_the_upload_folder
from toolbox import update_ui_lastest_msg, disable_auto_promotion from toolbox import update_ui_lastest_msg, disable_auto_promotion
from request_llm.bridge_all import predict_no_ui_long_connection from request_llms.bridge_all import predict_no_ui_long_connection
from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from crazy_functions.crazy_utils import input_clipping from crazy_functions.crazy_utils import input_clipping
from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError from crazy_functions.json_fns.pydantic_io import GptJsonIO, JsonStringError

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
fast_debug = True fast_debug = True
@@ -13,7 +13,7 @@ class PaperFileGroup():
self.sp_file_tag = [] self.sp_file_tag = []
# count_token # count_token
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
enc = model_info["gpt-3.5-turbo"]['tokenizer'] enc = model_info["gpt-3.5-turbo"]['tokenizer']
def get_token_num(txt): return len( def get_token_num(txt): return len(
enc.encode(txt, disallowed_special=())) enc.encode(txt, disallowed_special=()))
@@ -131,7 +131,7 @@ def 解析ipynb文件(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
else: else:
if txt == "": if txt == "":
txt = '空空如也的输入栏' txt = '空空如也的输入栏'
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
@@ -141,7 +141,7 @@ def 解析ipynb文件(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
file_manifest = [f for f in glob.glob( file_manifest = [f for f in glob.glob(
f'{project_folder}/**/*.ipynb', recursive=True)] f'{project_folder}/**/*.ipynb', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, report_exception(chatbot, history,
a=f"解析项目: {txt}", b=f"找不到任何.ipynb文件: {txt}") a=f"解析项目: {txt}", b=f"找不到任何.ipynb文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui, promote_file_to_downloadzone, disable_auto_promotion from toolbox import update_ui, promote_file_to_downloadzone, disable_auto_promotion
from toolbox import CatchException, report_execption, write_history_to_file from toolbox import CatchException, report_exception, write_history_to_file
from .crazy_utils import input_clipping from .crazy_utils import input_clipping
def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt): def 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt):
@@ -113,7 +113,7 @@ def 解析项目本身(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_
[f for f in glob.glob('./*/*.py')] [f for f in glob.glob('./*/*.py')]
project_folder = './' project_folder = './'
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -126,12 +126,12 @@ def 解析一个Python项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.py', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何python文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -144,12 +144,12 @@ def 解析一个Matlab项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析Matlab项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析Matlab项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.m', recursive=True)] file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.m', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析Matlab项目: {txt}", b = f"找不到任何`.m`源文件: {txt}") report_exception(chatbot, history, a = f"解析Matlab项目: {txt}", b = f"找不到任何`.m`源文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -162,14 +162,14 @@ def 解析一个C项目的头文件(txt, llm_kwargs, plugin_kwargs, chatbot, his
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \ [f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] #+ \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -182,7 +182,7 @@ def 解析一个C项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.h', recursive=True)] + \
@@ -190,7 +190,7 @@ def 解析一个C项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, system
[f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.hpp', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.h头文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -204,7 +204,7 @@ def 解析一个Java项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.java', recursive=True)] + \
@@ -212,7 +212,7 @@ def 解析一个Java项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys
[f for f in glob.glob(f'{project_folder}/**/*.xml', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.xml', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.sh', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何java文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -226,7 +226,7 @@ def 解析一个前端项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.ts', recursive=True)] + \
@@ -241,7 +241,7 @@ def 解析一个前端项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
[f for f in glob.glob(f'{project_folder}/**/*.css', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.css', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.jsx', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何前端相关文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何前端相关文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -255,7 +255,7 @@ def 解析一个Golang项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.go', recursive=True)] + \
@@ -263,7 +263,7 @@ def 解析一个Golang项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
[f for f in glob.glob(f'{project_folder}/**/go.sum', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/go.sum', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/go.work', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/go.work', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -276,14 +276,14 @@ def 解析一个Rust项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.rs', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.rs', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.toml', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.toml', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.lock', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.lock', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}") report_exception(chatbot, history, a=f"解析项目: {txt}", b=f"找不到任何golang文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -296,7 +296,7 @@ def 解析一个Lua项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.lua', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.lua', recursive=True)] + \
@@ -304,7 +304,7 @@ def 解析一个Lua项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
[f for f in glob.glob(f'{project_folder}/**/*.json', recursive=True)] + \ [f for f in glob.glob(f'{project_folder}/**/*.json', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.toml', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.toml', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何lua文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何lua文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -318,13 +318,13 @@ def 解析一个CSharp项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, s
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.cs', recursive=True)] + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.cs', recursive=True)] + \
[f for f in glob.glob(f'{project_folder}/**/*.csproj', recursive=True)] [f for f in glob.glob(f'{project_folder}/**/*.csproj', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何CSharp文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何CSharp文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
@@ -352,7 +352,7 @@ def 解析任意code项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
# 若上传压缩文件, 先寻找到解压的文件夹路径, 从而避免解析压缩文件 # 若上传压缩文件, 先寻找到解压的文件夹路径, 从而避免解析压缩文件
@@ -365,7 +365,7 @@ def 解析任意code项目(txt, llm_kwargs, plugin_kwargs, chatbot, history, sys
file_manifest = [f for pattern in pattern_include for f in glob.glob(f'{extract_folder_path}/**/{pattern}', recursive=True) if "" != extract_folder_path and \ file_manifest = [f for pattern in pattern_include for f in glob.glob(f'{extract_folder_path}/**/{pattern}', recursive=True) if "" != extract_folder_path and \
os.path.isfile(f) and (not re.search(pattern_except, f) or pattern.endswith('.' + re.search(pattern_except, f).group().split('.')[-1]))] os.path.isfile(f) and (not re.search(pattern_except, f) or pattern.endswith('.' + re.search(pattern_except, f).group().split('.')[-1]))]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析源代码新(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)

View File

@@ -1,4 +1,4 @@
from toolbox import CatchException, update_ui from toolbox import CatchException, update_ui, get_conf
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
import datetime import datetime
@CatchException @CatchException
@@ -13,11 +13,12 @@ def 同时问询(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt
web_port 当前软件运行的端口号 web_port 当前软件运行的端口号
""" """
history = [] # 清空历史,以免输入溢出 history = [] # 清空历史,以免输入溢出
chatbot.append((txt, "正在同时咨询ChatGPT和ChatGLM……")) MULTI_QUERY_LLM_MODELS = get_conf('MULTI_QUERY_LLM_MODELS')
chatbot.append((txt, "正在同时咨询" + MULTI_QUERY_LLM_MODELS))
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 # 由于请求gpt需要一段时间我们先及时地做一次界面更新
# llm_kwargs['llm_model'] = 'chatglm&gpt-3.5-turbo&api2d-gpt-3.5-turbo' # 支持任意数量的llm接口用&符号分隔 # llm_kwargs['llm_model'] = 'chatglm&gpt-3.5-turbo&api2d-gpt-3.5-turbo' # 支持任意数量的llm接口用&符号分隔
llm_kwargs['llm_model'] = 'chatglm&gpt-3.5-turbo' # 支持任意数量的llm接口用&符号分隔 llm_kwargs['llm_model'] = MULTI_QUERY_LLM_MODELS # 支持任意数量的llm接口用&符号分隔
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive( gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
inputs=txt, inputs_show_user=txt, inputs=txt, inputs_show_user=txt,
llm_kwargs=llm_kwargs, chatbot=chatbot, history=history, llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,

View File

@@ -1,47 +1,35 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, get_conf, markdown_convertion from toolbox import CatchException, get_conf, markdown_convertion
from crazy_functions.crazy_utils import input_clipping from crazy_functions.crazy_utils import input_clipping
from request_llm.bridge_all import predict_no_ui_long_connection from crazy_functions.agent_fns.watchdog import WatchDog
from request_llms.bridge_all import predict_no_ui_long_connection
import threading, time import threading, time
import numpy as np import numpy as np
from .live_audio.aliyunASR import AliyunASR from .live_audio.aliyunASR import AliyunASR
import json import json
import re
class WatchDog():
def __init__(self, timeout, bark_fn, interval=3, msg="") -> None:
self.last_feed = None
self.timeout = timeout
self.bark_fn = bark_fn
self.interval = interval
self.msg = msg
self.kill_dog = False
def watch(self):
while True:
if self.kill_dog: break
if time.time() - self.last_feed > self.timeout:
if len(self.msg) > 0: print(self.msg)
self.bark_fn()
break
time.sleep(self.interval)
def begin_watch(self):
self.last_feed = time.time()
th = threading.Thread(target=self.watch)
th.daemon = True
th.start()
def feed(self):
self.last_feed = time.time()
def chatbot2history(chatbot): def chatbot2history(chatbot):
history = [] history = []
for c in chatbot: for c in chatbot:
for q in c: for q in c:
if q not in ["[请讲话]", "[等待GPT响应]", "[正在等您说完问题]"]: if q in ["[ 请讲话 ]", "[ 等待GPT响应 ]", "[ 正在等您说完问题 ]"]:
continue
elif q.startswith("[ 正在等您说完问题 ]"):
continue
else:
history.append(q.strip('<div class="markdown-body">').strip('</div>').strip('<p>').strip('</p>')) history.append(q.strip('<div class="markdown-body">').strip('</div>').strip('<p>').strip('</p>'))
return history return history
def visualize_audio(chatbot, audio_shape):
if len(chatbot) == 0: chatbot.append(["[ 请讲话 ]", "[ 正在等您说完问题 ]"])
chatbot[-1] = list(chatbot[-1])
p1 = ''
p2 = ''
chatbot[-1][-1] = re.sub(p1+r'(.*)'+p2, '', chatbot[-1][-1])
chatbot[-1][-1] += (p1+f"`{audio_shape}`"+p2)
class AsyncGptTask(): class AsyncGptTask():
def __init__(self) -> None: def __init__(self) -> None:
self.observe_future = [] self.observe_future = []
@@ -81,8 +69,9 @@ class InterviewAssistant(AliyunASR):
self.capture_interval = 0.5 # second self.capture_interval = 0.5 # second
self.stop = False self.stop = False
self.parsed_text = "" # 下个句子中已经说完的部分, 由 test_on_result_chg() 写入 self.parsed_text = "" # 下个句子中已经说完的部分, 由 test_on_result_chg() 写入
self.parsed_sentence = "" # 某段话的整个句子,由 test_on_sentence_end() 写入 self.parsed_sentence = "" # 某段话的整个句子, 由 test_on_sentence_end() 写入
self.buffered_sentence = "" # self.buffered_sentence = "" #
self.audio_shape = "" # 音频的可视化表现, 由 audio_convertion_thread() 写入
self.event_on_result_chg = threading.Event() self.event_on_result_chg = threading.Event()
self.event_on_entence_end = threading.Event() self.event_on_entence_end = threading.Event()
self.event_on_commit_question = threading.Event() self.event_on_commit_question = threading.Event()
@@ -117,7 +106,7 @@ class InterviewAssistant(AliyunASR):
def begin(self, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt): def begin(self, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt):
# main plugin function # main plugin function
self.init(chatbot) self.init(chatbot)
chatbot.append(["[请讲话]", "[正在等您说完问题]"]) chatbot.append(["[ 请讲话 ]", "[ 正在等您说完问题 ]"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
self.plugin_wd.begin_watch() self.plugin_wd.begin_watch()
self.agt = AsyncGptTask() self.agt = AsyncGptTask()
@@ -157,14 +146,18 @@ class InterviewAssistant(AliyunASR):
self.commit_wd.begin_watch() self.commit_wd.begin_watch()
chatbot[-1] = list(chatbot[-1]) chatbot[-1] = list(chatbot[-1])
chatbot[-1] = [self.buffered_sentence, "[等待GPT响应]"] chatbot[-1] = [self.buffered_sentence, "[ 等待GPT响应 ]"]
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
# add gpt task 创建子线程请求gpt避免线程阻塞 # add gpt task 创建子线程请求gpt避免线程阻塞
history = chatbot2history(chatbot) history = chatbot2history(chatbot)
self.agt.add_async_gpt_task(self.buffered_sentence, len(chatbot)-1, llm_kwargs, history, system_prompt) self.agt.add_async_gpt_task(self.buffered_sentence, len(chatbot)-1, llm_kwargs, history, system_prompt)
self.buffered_sentence = "" self.buffered_sentence = ""
chatbot.append(["[请讲话]", "[正在等您说完问题]"]) chatbot.append(["[ 请讲话 ]", "[ 正在等您说完问题 ]"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
if not self.event_on_result_chg.is_set() and not self.event_on_entence_end.is_set() and not self.event_on_commit_question.is_set():
visualize_audio(chatbot, self.audio_shape)
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
if len(self.stop_msg) != 0: if len(self.stop_msg) != 0:
@@ -183,7 +176,7 @@ def 语音助手(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt
import nls import nls
from scipy import io from scipy import io
except: except:
chatbot.append(["导入依赖失败", "使用该模块需要额外依赖, 安装方法:```pip install --upgrade aliyun-python-sdk-core==2.13.3 pyOpenSSL scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git```"]) chatbot.append(["导入依赖失败", "使用该模块需要额外依赖, 安装方法:```pip install --upgrade aliyun-python-sdk-core==2.13.3 pyOpenSSL webrtcvad scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git```"])
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return

View File

@@ -1,5 +1,5 @@
from toolbox import update_ui from toolbox import update_ui
from toolbox import CatchException, report_execption from toolbox import CatchException, report_exception
from toolbox import write_history_to_file, promote_file_to_downloadzone from toolbox import write_history_to_file, promote_file_to_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
@@ -51,14 +51,14 @@ def 读文章写摘要(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_
project_folder = txt project_folder = txt
else: else:
if txt == "": txt = '空空如也的输入栏' if txt == "": txt = '空空如也的输入栏'
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到本地项目或无权访问: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \ file_manifest = [f for f in glob.glob(f'{project_folder}/**/*.tex', recursive=True)] # + \
# [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \ # [f for f in glob.glob(f'{project_folder}/**/*.cpp', recursive=True)] + \
# [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)] # [f for f in glob.glob(f'{project_folder}/**/*.c', recursive=True)]
if len(file_manifest) == 0: if len(file_manifest) == 0:
report_execption(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}") report_exception(chatbot, history, a = f"解析项目: {txt}", b = f"找不到任何.tex文件: {txt}")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return return
yield from 解析Paper(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt) yield from 解析Paper(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)

View File

@@ -1,5 +1,5 @@
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from toolbox import CatchException, report_execption, promote_file_to_downloadzone from toolbox import CatchException, report_exception, promote_file_to_downloadzone
from toolbox import update_ui, update_ui_lastest_msg, disable_auto_promotion, write_history_to_file from toolbox import update_ui, update_ui_lastest_msg, disable_auto_promotion, write_history_to_file
import logging import logging
import requests import requests
@@ -17,7 +17,7 @@ def get_meta_information(url, chatbot, history):
from urllib.parse import urlparse from urllib.parse import urlparse
session = requests.session() session = requests.session()
proxies, = get_conf('proxies') proxies = get_conf('proxies')
headers = { headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
'Accept-Encoding': 'gzip, deflate, br', 'Accept-Encoding': 'gzip, deflate, br',
@@ -26,7 +26,13 @@ def get_meta_information(url, chatbot, history):
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Connection': 'keep-alive' 'Connection': 'keep-alive'
} }
try:
session.proxies.update(proxies) session.proxies.update(proxies)
except:
report_exception(chatbot, history,
a=f"获取代理失败 无代理状态下很可能无法访问OpenAI家族的模型及谷歌学术 建议检查USE_PROXY选项是否修改。",
b=f"尝试直接连接")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
session.headers.update(headers) session.headers.update(headers)
response = session.get(url) response = session.get(url)
@@ -140,7 +146,7 @@ def 谷歌检索小助手(txt, llm_kwargs, plugin_kwargs, chatbot, history, syst
import math import math
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
except: except:
report_execption(chatbot, history, report_exception(chatbot, history,
a = f"解析项目: {txt}", a = f"解析项目: {txt}",
b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。") b = f"导入软件依赖失败。使用该模块需要额外依赖,安装方法```pip install --upgrade beautifulsoup4 arxiv```。")
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history) # 刷新界面

View File

@@ -1,4 +1,28 @@
#【请修改完参数后删除此行】请在以下方案中选择一种然后删除其他的方案最后docker-compose up运行 | Please choose from one of these options below, delete other options as well as This Line ## ===================================================
# docker-compose.yml
## ===================================================
# 1. 请在以下方案中选择任意一种,然后删除其他的方案
# 2. 修改你选择的方案中的environment环境变量详情请见github wiki或者config.py
# 3. 选择一种暴露服务端口的方法,并对相应的配置做出修改:
# 【方法1: 适用于Linux很方便可惜windows不支持】与宿主的网络融合为一体这个是默认配置
# network_mode: "host"
# 【方法2: 适用于所有系统包括Windows和MacOS】端口映射把容器的端口映射到宿主的端口注意您需要先删除network_mode: "host",再追加以下内容)
# ports:
# - "12345:12345" # 注意12345必须与WEB_PORT环境变量相互对应
# 4. 最后`docker-compose up`运行
# 5. 如果希望使用显卡,请关注 LOCAL_MODEL_DEVICE 和 英伟达显卡运行时 选项
## ===================================================
# 1. Please choose one of the following options and delete the others.
# 2. Modify the environment variables in the selected option, see GitHub wiki or config.py for more details.
# 3. Choose a method to expose the server port and make the corresponding configuration changes:
# [Method 1: Suitable for Linux, convenient, but not supported for Windows] Fusion with the host network, this is the default configuration
# network_mode: "host"
# [Method 2: Suitable for all systems including Windows and MacOS] Port mapping, mapping the container port to the host port (note that you need to delete network_mode: "host" first, and then add the following content)
# ports:
# - "12345: 12345" # Note! 12345 must correspond to the WEB_PORT environment variable.
# 4. Finally, run `docker-compose up`.
# 5. If you want to use a graphics card, pay attention to the LOCAL_MODEL_DEVICE and Nvidia GPU runtime options.
## ===================================================
## =================================================== ## ===================================================
## 【方案零】 部署项目的全部能力这个是包含cuda和latex的大型镜像。如果您网速慢、硬盘小或没有显卡则不推荐使用这个 ## 【方案零】 部署项目的全部能力这个是包含cuda和latex的大型镜像。如果您网速慢、硬盘小或没有显卡则不推荐使用这个
@@ -39,10 +63,14 @@ services:
# count: 1 # count: 1
# capabilities: [gpu] # capabilities: [gpu]
# 与宿主的网络融合 # 【WEB_PORT暴露方法1: 适用于Linux】与宿主的网络融合
network_mode: "host" network_mode: "host"
# 不使用代理网络拉取最新代码 # 【WEB_PORT暴露方法2: 适用于所有系统】端口映射
# ports:
# - "12345:12345" # 12345必须与WEB_PORT相互对应
# 启动容器后运行main.py主程序
command: > command: >
bash -c "python3 -u main.py" bash -c "python3 -u main.py"
@@ -109,7 +137,7 @@ services:
# P.S. 通过对 command 进行微调,可以便捷地安装额外的依赖 # P.S. 通过对 command 进行微调,可以便捷地安装额外的依赖
# command: > # command: >
# bash -c "pip install -r request_llm/requirements_qwen.txt && python3 -u main.py" # bash -c "pip install -r request_llms/requirements_qwen.txt && python3 -u main.py"
### =================================================== ### ===================================================
### 【方案三】 如果需要运行ChatGPT + LLAMA + 盘古 + RWKV本地模型 ### 【方案三】 如果需要运行ChatGPT + LLAMA + 盘古 + RWKV本地模型

View File

@@ -14,18 +14,18 @@ RUN python3 -m pip install colorama Markdown pygments pymupdf
RUN python3 -m pip install python-docx moviepy pdfminer RUN python3 -m pip install python-docx moviepy pdfminer
RUN python3 -m pip install zh_langchain==0.2.1 pypinyin RUN python3 -m pip install zh_langchain==0.2.1 pypinyin
RUN python3 -m pip install rarfile py7zr RUN python3 -m pip install rarfile py7zr
RUN python3 -m pip install aliyun-python-sdk-core==2.13.3 pyOpenSSL scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git RUN python3 -m pip install aliyun-python-sdk-core==2.13.3 pyOpenSSL webrtcvad scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git
# 下载分支 # 下载分支
WORKDIR /gpt WORKDIR /gpt
RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git
WORKDIR /gpt/gpt_academic WORKDIR /gpt/gpt_academic
RUN git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llm/moss RUN git clone --depth=1 https://github.com/OpenLMLab/MOSS.git request_llms/moss
RUN python3 -m pip install -r requirements.txt RUN python3 -m pip install -r requirements.txt
RUN python3 -m pip install -r request_llm/requirements_moss.txt RUN python3 -m pip install -r request_llms/requirements_moss.txt
RUN python3 -m pip install -r request_llm/requirements_qwen.txt RUN python3 -m pip install -r request_llms/requirements_qwen.txt
RUN python3 -m pip install -r request_llm/requirements_chatglm.txt RUN python3 -m pip install -r request_llms/requirements_chatglm.txt
RUN python3 -m pip install -r request_llm/requirements_newbing.txt RUN python3 -m pip install -r request_llms/requirements_newbing.txt
RUN python3 -m pip install nougat-ocr RUN python3 -m pip install nougat-ocr

View File

@@ -14,12 +14,12 @@ RUN python3 -m pip install torch --extra-index-url https://download.pytorch.org/
WORKDIR /gpt WORKDIR /gpt
RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git
WORKDIR /gpt/gpt_academic WORKDIR /gpt/gpt_academic
RUN git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss RUN git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss
RUN python3 -m pip install -r requirements.txt RUN python3 -m pip install -r requirements.txt
RUN python3 -m pip install -r request_llm/requirements_moss.txt RUN python3 -m pip install -r request_llms/requirements_moss.txt
RUN python3 -m pip install -r request_llm/requirements_qwen.txt RUN python3 -m pip install -r request_llms/requirements_qwen.txt
RUN python3 -m pip install -r request_llm/requirements_chatglm.txt RUN python3 -m pip install -r request_llms/requirements_chatglm.txt
RUN python3 -m pip install -r request_llm/requirements_newbing.txt RUN python3 -m pip install -r request_llms/requirements_newbing.txt

View File

@@ -16,12 +16,12 @@ WORKDIR /gpt
RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git RUN git clone --depth=1 https://github.com/binary-husky/gpt_academic.git
WORKDIR /gpt/gpt_academic WORKDIR /gpt/gpt_academic
RUN python3 -m pip install -r requirements.txt RUN python3 -m pip install -r requirements.txt
RUN python3 -m pip install -r request_llm/requirements_chatglm.txt RUN python3 -m pip install -r request_llms/requirements_chatglm.txt
RUN python3 -m pip install -r request_llm/requirements_newbing.txt RUN python3 -m pip install -r request_llms/requirements_newbing.txt
RUN python3 -m pip install -r request_llm/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I RUN python3 -m pip install -r request_llms/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I
# 下载JittorLLMs # 下载JittorLLMs
RUN git clone https://github.com/binary-husky/JittorLLMs.git --depth 1 request_llm/jittorllms RUN git clone https://github.com/binary-husky/JittorLLMs.git --depth 1 request_llms/jittorllms
# 禁用缓存,确保更新代码 # 禁用缓存,确保更新代码
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache

View File

@@ -4,16 +4,19 @@
# - 3 运行 docker run -v /home/fuqingxu/arxiv_cache:/root/arxiv_cache --rm -it --net=host gpt-academic-nolocal-latex # - 3 运行 docker run -v /home/fuqingxu/arxiv_cache:/root/arxiv_cache --rm -it --net=host gpt-academic-nolocal-latex
FROM fuqingxu/python311_texlive_ctex:latest FROM fuqingxu/python311_texlive_ctex:latest
ENV PATH "$PATH:/usr/local/texlive/2022/bin/x86_64-linux"
ENV PATH "$PATH:/usr/local/texlive/2023/bin/x86_64-linux"
ENV PATH "$PATH:/usr/local/texlive/2024/bin/x86_64-linux"
ENV PATH "$PATH:/usr/local/texlive/2025/bin/x86_64-linux"
ENV PATH "$PATH:/usr/local/texlive/2026/bin/x86_64-linux"
# 指定路径 # 指定路径
WORKDIR /gpt WORKDIR /gpt
RUN pip3 install gradio openai numpy arxiv rich RUN pip3 install openai numpy arxiv rich
RUN pip3 install colorama Markdown pygments pymupdf RUN pip3 install colorama Markdown pygments pymupdf
RUN pip3 install python-docx moviepy pdfminer RUN pip3 install python-docx pdfminer
RUN pip3 install zh_langchain==0.2.1
RUN pip3 install nougat-ocr RUN pip3 install nougat-ocr
RUN pip3 install aliyun-python-sdk-core==2.13.3 pyOpenSSL scipy git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git
# 装载项目文件 # 装载项目文件
COPY . . COPY . .

View File

@@ -103,12 +103,12 @@ python -m pip install -r requirements.txt # Same step as pip installation
[Optional Step] If supporting Tsinghua ChatGLM/Fudan MOSS as backend, additional dependencies need to be installed (Prerequisites: Familiar with Python + Used Pytorch + Sufficient computer configuration): [Optional Step] If supporting Tsinghua ChatGLM/Fudan MOSS as backend, additional dependencies need to be installed (Prerequisites: Familiar with Python + Used Pytorch + Sufficient computer configuration):
```sh ```sh
# [Optional Step I] Support Tsinghua ChatGLM. Remark: If encountering "Call ChatGLM fail Cannot load ChatGLM parameters", please refer to the following: 1: The above default installation is torch+cpu version. To use cuda, uninstall torch and reinstall torch+cuda; 2: If the model cannot be loaded due to insufficient machine configuration, you can modify the model precision in `request_llm/bridge_chatglm.py`, and modify all AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # [Optional Step I] Support Tsinghua ChatGLM. Remark: If encountering "Call ChatGLM fail Cannot load ChatGLM parameters", please refer to the following: 1: The above default installation is torch+cpu version. To use cuda, uninstall torch and reinstall torch+cuda; 2: If the model cannot be loaded due to insufficient machine configuration, you can modify the model precision in `request_llms/bridge_chatglm.py`, and modify all AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# [Optional Step II] Support Fudan MOSS # [Optional Step II] Support Fudan MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # When executing this line of code, you must be in the project root path git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # When executing this line of code, you must be in the project root path
# [Optional Step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the expected models. Currently supported models are as follows (jittorllms series currently only supports docker solutions): # [Optional Step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the expected models. Currently supported models are as follows (jittorllms series currently only supports docker solutions):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -109,12 +109,12 @@ python -m pip install -r requirements.txt # questo passaggio funziona allo stess
【Passaggio facoltativo】 Se si desidera supportare ChatGLM di Tsinghua/MOSS di Fudan come backend, è necessario installare ulteriori dipendenze (prerequisiti: conoscenza di Python, esperienza con Pytorch e computer sufficientemente potente): 【Passaggio facoltativo】 Se si desidera supportare ChatGLM di Tsinghua/MOSS di Fudan come backend, è necessario installare ulteriori dipendenze (prerequisiti: conoscenza di Python, esperienza con Pytorch e computer sufficientemente potente):
```sh ```sh
# 【Passaggio facoltativo I】 Supporto a ChatGLM di Tsinghua. Note su ChatGLM di Tsinghua: in caso di errore "Call ChatGLM fail 不能正常加载ChatGLM的参数" , fare quanto segue: 1. Per impostazione predefinita, viene installata la versione di torch + cpu; per usare CUDA, è necessario disinstallare torch e installare nuovamente torch + cuda; 2. Se non è possibile caricare il modello a causa di una configurazione insufficiente del computer, è possibile modificare la precisione del modello in request_llm/bridge_chatglm.py, cambiando AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) in AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # 【Passaggio facoltativo I】 Supporto a ChatGLM di Tsinghua. Note su ChatGLM di Tsinghua: in caso di errore "Call ChatGLM fail 不能正常加载ChatGLM的参数" , fare quanto segue: 1. Per impostazione predefinita, viene installata la versione di torch + cpu; per usare CUDA, è necessario disinstallare torch e installare nuovamente torch + cuda; 2. Se non è possibile caricare il modello a causa di una configurazione insufficiente del computer, è possibile modificare la precisione del modello in request_llms/bridge_chatglm.py, cambiando AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) in AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# 【Passaggio facoltativo II】 Supporto a MOSS di Fudan # 【Passaggio facoltativo II】 Supporto a MOSS di Fudan
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # Si prega di notare che quando si esegue questa riga di codice, si deve essere nella directory radice del progetto git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # Si prega di notare che quando si esegue questa riga di codice, si deve essere nella directory radice del progetto
# 【Passaggio facoltativo III】 Assicurati che il file di configurazione config.py includa tutti i modelli desiderati, al momento tutti i modelli supportati sono i seguenti (i modelli della serie jittorllms attualmente supportano solo la soluzione docker): # 【Passaggio facoltativo III】 Assicurati che il file di configurazione config.py includa tutti i modelli desiderati, al momento tutti i modelli supportati sono i seguenti (i modelli della serie jittorllms attualmente supportano solo la soluzione docker):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -104,11 +104,11 @@ python -m pip install -r requirements.txt # 이 단계도 pip install의 단계
# 1 : 기본 설치된 것들은 torch + cpu 버전입니다. cuda를 사용하려면 torch를 제거한 다음 torch + cuda를 다시 설치해야합니다. # 1 : 기본 설치된 것들은 torch + cpu 버전입니다. cuda를 사용하려면 torch를 제거한 다음 torch + cuda를 다시 설치해야합니다.
# 2 : 모델을 로드할 수 없는 기계 구성 때문에, AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)를 # 2 : 모델을 로드할 수 없는 기계 구성 때문에, AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)를
# AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)로 변경합니다. # AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)로 변경합니다.
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# [선택 사항 II] Fudan MOSS 지원 # [선택 사항 II] Fudan MOSS 지원
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # 다음 코드 줄을 실행할 때 프로젝트 루트 경로에 있어야합니다. git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # 다음 코드 줄을 실행할 때 프로젝트 루트 경로에 있어야합니다.
# [선택 사항III] AVAIL_LLM_MODELS config.py 구성 파일에 기대하는 모델이 포함되어 있는지 확인하십시오. # [선택 사항III] AVAIL_LLM_MODELS config.py 구성 파일에 기대하는 모델이 포함되어 있는지 확인하십시오.
# 현재 지원되는 전체 모델 : # 현재 지원되는 전체 모델 :

View File

@@ -119,12 +119,12 @@ python -m pip install -r requirements.txt # This step is the same as the pip ins
[Optional Step] If you need to support Tsinghua ChatGLM / Fudan MOSS as the backend, you need to install more dependencies (prerequisite: familiar with Python + used Pytorch + computer configuration is strong): [Optional Step] If you need to support Tsinghua ChatGLM / Fudan MOSS as the backend, you need to install more dependencies (prerequisite: familiar with Python + used Pytorch + computer configuration is strong):
```sh ```sh
# 【Optional Step I】support Tsinghua ChatGLM。Tsinghua ChatGLM Note: If you encounter a "Call ChatGLM fails cannot load ChatGLM parameters normally" error, refer to the following: 1: The default installed is torch+cpu version, and using cuda requires uninstalling torch and reinstalling torch+cuda; 2: If the model cannot be loaded due to insufficient computer configuration, you can modify the model accuracy in request_llm/bridge_chatglm.py and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # 【Optional Step I】support Tsinghua ChatGLM。Tsinghua ChatGLM Note: If you encounter a "Call ChatGLM fails cannot load ChatGLM parameters normally" error, refer to the following: 1: The default installed is torch+cpu version, and using cuda requires uninstalling torch and reinstalling torch+cuda; 2: If the model cannot be loaded due to insufficient computer configuration, you can modify the model accuracy in request_llms/bridge_chatglm.py and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# 【Optional Step II】support Fudan MOSS # 【Optional Step II】support Fudan MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # Note: When executing this line of code, you must be in the project root path git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # Note: When executing this line of code, you must be in the project root path
# 【Optional Step III】Make sure that the AVAIL_LLM_MODELS in the config.py configuration file contains the expected model. Currently, all supported models are as follows (jittorllms series currently only supports docker solutions): # 【Optional Step III】Make sure that the AVAIL_LLM_MODELS in the config.py configuration file contains the expected model. Currently, all supported models are as follows (jittorllms series currently only supports docker solutions):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -106,12 +106,12 @@ python -m pip install -r requirements.txt # this step is the same as pip install
[Optional step] If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, you need to install more dependencies (prerequisites: familiar with Python + used Pytorch + computer configuration is strong enough): [Optional step] If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, you need to install more dependencies (prerequisites: familiar with Python + used Pytorch + computer configuration is strong enough):
```sh ```sh
# [Optional Step I] Support Tsinghua ChatGLM. Tsinghua ChatGLM remarks: if you encounter the "Call ChatGLM fail cannot load ChatGLM parameters" error, refer to this: 1: The default installation above is torch + cpu version, to use cuda, you need to uninstall torch and reinstall torch + cuda; 2: If the model cannot be loaded due to insufficient local configuration, you can modify the model accuracy in request_llm/bridge_chatglm.py, and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code = True) # [Optional Step I] Support Tsinghua ChatGLM. Tsinghua ChatGLM remarks: if you encounter the "Call ChatGLM fail cannot load ChatGLM parameters" error, refer to this: 1: The default installation above is torch + cpu version, to use cuda, you need to uninstall torch and reinstall torch + cuda; 2: If the model cannot be loaded due to insufficient local configuration, you can modify the model accuracy in request_llms/bridge_chatglm.py, and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code = True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# [Optional Step II] Support Fudan MOSS # [Optional Step II] Support Fudan MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # When executing this line of code, you must be in the root directory of the project git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # When executing this line of code, you must be in the root directory of the project
# [Optional Step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file includes the expected models. Currently supported models are as follows (the jittorllms series only supports the docker solution for the time being): # [Optional Step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file includes the expected models. Currently supported models are as follows (the jittorllms series only supports the docker solution for the time being):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -111,12 +111,12 @@ python -m pip install -r requirements.txt # Same step as pip instalation
【Optional】 Si vous souhaitez prendre en charge THU ChatGLM/FDU MOSS en tant que backend, des dépendances supplémentaires doivent être installées (prérequis: compétent en Python + utilisez Pytorch + configuration suffisante de l'ordinateur): 【Optional】 Si vous souhaitez prendre en charge THU ChatGLM/FDU MOSS en tant que backend, des dépendances supplémentaires doivent être installées (prérequis: compétent en Python + utilisez Pytorch + configuration suffisante de l'ordinateur):
```sh ```sh
# 【Optional Step I】 Support THU ChatGLM. Remarque sur THU ChatGLM: Si vous rencontrez l'erreur "Appel à ChatGLM échoué, les paramètres ChatGLM ne peuvent pas être chargés normalement", reportez-vous à ce qui suit: 1: La version par défaut installée est torch+cpu, si vous souhaitez utiliser cuda, vous devez désinstaller torch et réinstaller torch+cuda; 2: Si le modèle ne peut pas être chargé en raison d'une configuration insuffisante de l'ordinateur local, vous pouvez modifier la précision du modèle dans request_llm/bridge_chatglm.py, modifier AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) par AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # 【Optional Step I】 Support THU ChatGLM. Remarque sur THU ChatGLM: Si vous rencontrez l'erreur "Appel à ChatGLM échoué, les paramètres ChatGLM ne peuvent pas être chargés normalement", reportez-vous à ce qui suit: 1: La version par défaut installée est torch+cpu, si vous souhaitez utiliser cuda, vous devez désinstaller torch et réinstaller torch+cuda; 2: Si le modèle ne peut pas être chargé en raison d'une configuration insuffisante de l'ordinateur local, vous pouvez modifier la précision du modèle dans request_llms/bridge_chatglm.py, modifier AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) par AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# 【Optional Step II】 Support FDU MOSS # 【Optional Step II】 Support FDU MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # Note: When running this line of code, you must be in the project root path. git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # Note: When running this line of code, you must be in the project root path.
# 【Optional Step III】Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the desired model. Currently, all models supported are as follows (the jittorllms series currently only supports the docker scheme): # 【Optional Step III】Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the desired model. Currently, all models supported are as follows (the jittorllms series currently only supports the docker scheme):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -120,12 +120,12 @@ python -m pip install -r requirements.txt # This step is the same as the pip ins
[Optional Steps] If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, you need to install more dependencies (precondition: familiar with Python + used Pytorch + computer configuration). Strong enough): [Optional Steps] If you need to support Tsinghua ChatGLM/Fudan MOSS as a backend, you need to install more dependencies (precondition: familiar with Python + used Pytorch + computer configuration). Strong enough):
```sh ```sh
# Optional step I: support Tsinghua ChatGLM. Tsinghua ChatGLM remarks: If you encounter the error "Call ChatGLM fail cannot load ChatGLM parameters normally", refer to the following: 1: The version installed above is torch+cpu version, using cuda requires uninstalling torch and reinstalling torch+cuda; 2: If the model cannot be loaded due to insufficient local configuration, you can modify the model accuracy in request_llm/bridge_chatglm.py, and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True). # Optional step I: support Tsinghua ChatGLM. Tsinghua ChatGLM remarks: If you encounter the error "Call ChatGLM fail cannot load ChatGLM parameters normally", refer to the following: 1: The version installed above is torch+cpu version, using cuda requires uninstalling torch and reinstalling torch+cuda; 2: If the model cannot be loaded due to insufficient local configuration, you can modify the model accuracy in request_llms/bridge_chatglm.py, and change AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True).
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# Optional Step II: Support Fudan MOSS. # Optional Step II: Support Fudan MOSS.
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # Note that when executing this line of code, it must be in the project root. git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # Note that when executing this line of code, it must be in the project root.
# 【Optional Step III】Ensure that the AVAIL_LLM_MODELS in the config.py configuration file contains the expected model. Currently, all supported models are as follows (jittorllms series currently only supports the docker solution): # 【Optional Step III】Ensure that the AVAIL_LLM_MODELS in the config.py configuration file contains the expected model. Currently, all supported models are as follows (jittorllms series currently only supports the docker solution):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -108,12 +108,12 @@ python -m pip install -r requirements.txt # This step is the same as the pip ins
[Optional step] If you need to support Tsinghua ChatGLM/Fudan MOSS as backend, you need to install more dependencies (prerequisites: familiar with Python + have used Pytorch + computer configuration is strong): [Optional step] If you need to support Tsinghua ChatGLM/Fudan MOSS as backend, you need to install more dependencies (prerequisites: familiar with Python + have used Pytorch + computer configuration is strong):
```sh ```sh
# [Optional step I] Support Tsinghua ChatGLM. Tsinghua ChatGLM note: If you encounter the "Call ChatGLM fail cannot load ChatGLM parameters normally" error, refer to the following: 1: The default installation above is torch+cpu version, and cuda is used Need to uninstall torch and reinstall torch+cuda; 2: If you cannot load the model due to insufficient local configuration, you can modify the model accuracy in request_llm/bridge_chatglm.py, AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) Modify to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True) # [Optional step I] Support Tsinghua ChatGLM. Tsinghua ChatGLM note: If you encounter the "Call ChatGLM fail cannot load ChatGLM parameters normally" error, refer to the following: 1: The default installation above is torch+cpu version, and cuda is used Need to uninstall torch and reinstall torch+cuda; 2: If you cannot load the model due to insufficient local configuration, you can modify the model accuracy in request_llms/bridge_chatglm.py, AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) Modify to AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
python -m pip install -r request_llm/requirements_chatglm.txt python -m pip install -r request_llms/requirements_chatglm.txt
# [Optional step II] Support Fudan MOSS # [Optional step II] Support Fudan MOSS
python -m pip install -r request_llm/requirements_moss.txt python -m pip install -r request_llms/requirements_moss.txt
git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss # Note that when executing this line of code, you must be in the project root path git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss # Note that when executing this line of code, you must be in the project root path
# [Optional step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the expected models. Currently, all supported models are as follows (the jittorllms series currently only supports the docker solution): # [Optional step III] Make sure the AVAIL_LLM_MODELS in the config.py configuration file contains the expected models. Currently, all supported models are as follows (the jittorllms series currently only supports the docker solution):
AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"] AVAIL_LLM_MODELS = ["gpt-3.5-turbo", "api2d-gpt-3.5-turbo", "gpt-4", "api2d-gpt-4", "chatglm", "newbing", "moss"] # + ["jittorllms_rwkv", "jittorllms_pangualpha", "jittorllms_llama"]

View File

@@ -16,7 +16,7 @@ nano config.py
+ demo.queue(concurrency_count=CONCURRENT_COUNT) + demo.queue(concurrency_count=CONCURRENT_COUNT)
- # 如果需要在二级路径下运行 - # 如果需要在二级路径下运行
- # CUSTOM_PATH, = get_conf('CUSTOM_PATH') - # CUSTOM_PATH = get_conf('CUSTOM_PATH')
- # if CUSTOM_PATH != "/": - # if CUSTOM_PATH != "/":
- # from toolbox import run_gradio_in_subpath - # from toolbox import run_gradio_in_subpath
- # run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH) - # run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)
@@ -24,7 +24,7 @@ nano config.py
- # demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png") - # demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png")
+ 如果需要在二级路径下运行 + 如果需要在二级路径下运行
+ CUSTOM_PATH, = get_conf('CUSTOM_PATH') + CUSTOM_PATH = get_conf('CUSTOM_PATH')
+ if CUSTOM_PATH != "/": + if CUSTOM_PATH != "/":
+ from toolbox import run_gradio_in_subpath + from toolbox import run_gradio_in_subpath
+ run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH) + run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)

View File

@@ -38,20 +38,20 @@
| crazy_functions\读文章写摘要.py | 对论文进行解析和全文摘要生成 | | crazy_functions\读文章写摘要.py | 对论文进行解析和全文摘要生成 |
| crazy_functions\谷歌检索小助手.py | 提供谷歌学术搜索页面中相关文章的元数据信息。 | | crazy_functions\谷歌检索小助手.py | 提供谷歌学术搜索页面中相关文章的元数据信息。 |
| crazy_functions\高级功能函数模板.py | 使用Unsplash API发送相关图片以回复用户的输入。 | | crazy_functions\高级功能函数模板.py | 使用Unsplash API发送相关图片以回复用户的输入。 |
| request_llm\bridge_all.py | 基于不同LLM模型进行对话。 | | request_llms\bridge_all.py | 基于不同LLM模型进行对话。 |
| request_llm\bridge_chatglm.py | 使用ChatGLM模型生成回复支持单线程和多线程方式。 | | request_llms\bridge_chatglm.py | 使用ChatGLM模型生成回复支持单线程和多线程方式。 |
| request_llm\bridge_chatgpt.py | 基于GPT模型完成对话。 | | request_llms\bridge_chatgpt.py | 基于GPT模型完成对话。 |
| request_llm\bridge_jittorllms_llama.py | 使用JittorLLMs模型完成对话支持单线程和多线程方式。 | | request_llms\bridge_jittorllms_llama.py | 使用JittorLLMs模型完成对话支持单线程和多线程方式。 |
| request_llm\bridge_jittorllms_pangualpha.py | 使用JittorLLMs模型完成对话基于多进程和多线程方式。 | | request_llms\bridge_jittorllms_pangualpha.py | 使用JittorLLMs模型完成对话基于多进程和多线程方式。 |
| request_llm\bridge_jittorllms_rwkv.py | 使用JittorLLMs模型完成聊天功能提供包括历史信息、参数调节等在内的多个功能选项。 | | request_llms\bridge_jittorllms_rwkv.py | 使用JittorLLMs模型完成聊天功能提供包括历史信息、参数调节等在内的多个功能选项。 |
| request_llm\bridge_moss.py | 加载Moss模型完成对话功能。 | | request_llms\bridge_moss.py | 加载Moss模型完成对话功能。 |
| request_llm\bridge_newbing.py | 使用Newbing聊天机器人进行对话支持单线程和多线程方式。 | | request_llms\bridge_newbing.py | 使用Newbing聊天机器人进行对话支持单线程和多线程方式。 |
| request_llm\bridge_newbingfree.py | 基于Bing chatbot API实现聊天机器人的文本生成功能。 | | request_llms\bridge_newbingfree.py | 基于Bing chatbot API实现聊天机器人的文本生成功能。 |
| request_llm\bridge_stackclaude.py | 基于Slack API实现Claude与用户的交互。 | | request_llms\bridge_stackclaude.py | 基于Slack API实现Claude与用户的交互。 |
| request_llm\bridge_tgui.py | 通过websocket实现聊天机器人与UI界面交互。 | | request_llms\bridge_tgui.py | 通过websocket实现聊天机器人与UI界面交互。 |
| request_llm\edge_gpt.py | 调用Bing chatbot API提供聊天机器人服务。 | | request_llms\edge_gpt.py | 调用Bing chatbot API提供聊天机器人服务。 |
| request_llm\edge_gpt_free.py | 实现聊天机器人API采用aiohttp和httpx工具库。 | | request_llms\edge_gpt_free.py | 实现聊天机器人API采用aiohttp和httpx工具库。 |
| request_llm\test_llms.py | 对llm模型进行单元测试。 | | request_llms\test_llms.py | 对llm模型进行单元测试。 |
## 接下来请你逐文件分析下面的工程[0/48] 请对下面的程序文件做一个概述: check_proxy.py ## 接下来请你逐文件分析下面的工程[0/48] 请对下面的程序文件做一个概述: check_proxy.py
@@ -129,7 +129,7 @@ toolbox.py是一个工具类库其中主要包含了一些函数装饰器和
1. `input_clipping`: 该函数用于裁剪输入文本长度,使其不超过一定的限制。 1. `input_clipping`: 该函数用于裁剪输入文本长度,使其不超过一定的限制。
2. `request_gpt_model_in_new_thread_with_ui_alive`: 该函数用于请求 GPT 模型并保持用户界面的响应,支持多线程和实时更新用户界面。 2. `request_gpt_model_in_new_thread_with_ui_alive`: 该函数用于请求 GPT 模型并保持用户界面的响应,支持多线程和实时更新用户界面。
这两个函数都依赖于从 `toolbox``request_llm` 中导入的一些工具函数。函数的输入和输出有详细的描述文档。 这两个函数都依赖于从 `toolbox``request_llms` 中导入的一些工具函数。函数的输入和输出有详细的描述文档。
## [12/48] 请对下面的程序文件做一个概述: crazy_functions\Latex全文润色.py ## [12/48] 请对下面的程序文件做一个概述: crazy_functions\Latex全文润色.py
@@ -137,7 +137,7 @@ toolbox.py是一个工具类库其中主要包含了一些函数装饰器和
## [13/48] 请对下面的程序文件做一个概述: crazy_functions\Latex全文翻译.py ## [13/48] 请对下面的程序文件做一个概述: crazy_functions\Latex全文翻译.py
这个文件包含两个函数 `Latex英译中``Latex中译英`它们都会对整个Latex项目进行翻译。这个文件还包含一个类 `PaperFileGroup`,它拥有一个方法 `run_file_split`,用于把长文本文件分成多个短文件。其中使用了工具库 `toolbox` 中的一些函数和从 `request_llm` 中导入了 `model_info`。接下来的函数把文件读取进来,把它们的注释删除,进行分割,并进行翻译。这个文件还包括了一些异常处理和界面更新的操作。 这个文件包含两个函数 `Latex英译中``Latex中译英`它们都会对整个Latex项目进行翻译。这个文件还包含一个类 `PaperFileGroup`,它拥有一个方法 `run_file_split`,用于把长文本文件分成多个短文件。其中使用了工具库 `toolbox` 中的一些函数和从 `request_llms` 中导入了 `model_info`。接下来的函数把文件读取进来,把它们的注释删除,进行分割,并进行翻译。这个文件还包括了一些异常处理和界面更新的操作。
## [14/48] 请对下面的程序文件做一个概述: crazy_functions\__init__.py ## [14/48] 请对下面的程序文件做一个概述: crazy_functions\__init__.py
@@ -217,7 +217,7 @@ toolbox.py是一个工具类库其中主要包含了一些函数装饰器和
## [31/48] 请对下面的程序文件做一个概述: crazy_functions\读文章写摘要.py ## [31/48] 请对下面的程序文件做一个概述: crazy_functions\读文章写摘要.py
这个程序文件是一个Python模块文件名为crazy_functions\读文章写摘要.py。该模块包含了两个函数其中主要函数是"读文章写摘要"函数其实现了解析给定文件夹中的tex文件对其中每个文件的内容进行摘要生成并根据各论文片段的摘要最终生成全文摘要。第二个函数是"解析Paper"函数用于解析单篇论文文件。其中用到了一些工具函数和库如update_ui、CatchException、report_execption、write_results_to_file等。 这个程序文件是一个Python模块文件名为crazy_functions\读文章写摘要.py。该模块包含了两个函数其中主要函数是"读文章写摘要"函数其实现了解析给定文件夹中的tex文件对其中每个文件的内容进行摘要生成并根据各论文片段的摘要最终生成全文摘要。第二个函数是"解析Paper"函数用于解析单篇论文文件。其中用到了一些工具函数和库如update_ui、CatchException、report_exception、write_results_to_file等。
## [32/48] 请对下面的程序文件做一个概述: crazy_functions\谷歌检索小助手.py ## [32/48] 请对下面的程序文件做一个概述: crazy_functions\谷歌检索小助手.py
@@ -227,19 +227,19 @@ toolbox.py是一个工具类库其中主要包含了一些函数装饰器和
该程序文件定义了一个名为高阶功能模板函数的函数该函数接受多个参数包括输入的文本、gpt模型参数、插件模型参数、聊天显示框的句柄、聊天历史等并利用送出请求使用 Unsplash API 发送相关图片。其中,为了避免输入溢出,函数会在开始时清空历史。函数也有一些 UI 更新的语句。该程序文件还依赖于其他两个模块CatchException 和 update_ui以及一个名为 request_gpt_model_in_new_thread_with_ui_alive 的来自 crazy_utils 模块(应该是自定义的工具包)的函数。 该程序文件定义了一个名为高阶功能模板函数的函数该函数接受多个参数包括输入的文本、gpt模型参数、插件模型参数、聊天显示框的句柄、聊天历史等并利用送出请求使用 Unsplash API 发送相关图片。其中,为了避免输入溢出,函数会在开始时清空历史。函数也有一些 UI 更新的语句。该程序文件还依赖于其他两个模块CatchException 和 update_ui以及一个名为 request_gpt_model_in_new_thread_with_ui_alive 的来自 crazy_utils 模块(应该是自定义的工具包)的函数。
## [34/48] 请对下面的程序文件做一个概述: request_llm\bridge_all.py ## [34/48] 请对下面的程序文件做一个概述: request_llms\bridge_all.py
该文件包含两个函数predict和predict_no_ui_long_connection用于基于不同的LLM模型进行对话。该文件还包含一个lazyloadTiktoken类和一个LLM_CATCH_EXCEPTION修饰器函数。其中lazyloadTiktoken类用于懒加载模型的tokenizerLLM_CATCH_EXCEPTION用于错误处理。整个文件还定义了一些全局变量和模型信息字典用于引用和配置LLM模型。 该文件包含两个函数predict和predict_no_ui_long_connection用于基于不同的LLM模型进行对话。该文件还包含一个lazyloadTiktoken类和一个LLM_CATCH_EXCEPTION修饰器函数。其中lazyloadTiktoken类用于懒加载模型的tokenizerLLM_CATCH_EXCEPTION用于错误处理。整个文件还定义了一些全局变量和模型信息字典用于引用和配置LLM模型。
## [35/48] 请对下面的程序文件做一个概述: request_llm\bridge_chatglm.py ## [35/48] 请对下面的程序文件做一个概述: request_llms\bridge_chatglm.py
这是一个Python程序文件名为`bridge_chatglm.py`,其中定义了一个名为`GetGLMHandle`的类和三个方法:`predict_no_ui_long_connection``predict``stream_chat`。该文件依赖于多个Python库`transformers``sentencepiece`。该文件实现了一个聊天机器人使用ChatGLM模型来生成回复支持单线程和多线程方式。程序启动时需要加载ChatGLM的模型和tokenizer需要一段时间。在配置文件`config.py`中设置参数会影响模型的内存和显存使用,因此程序可能会导致低配计算机卡死。 这是一个Python程序文件名为`bridge_chatglm.py`,其中定义了一个名为`GetGLMHandle`的类和三个方法:`predict_no_ui_long_connection``predict``stream_chat`。该文件依赖于多个Python库`transformers``sentencepiece`。该文件实现了一个聊天机器人使用ChatGLM模型来生成回复支持单线程和多线程方式。程序启动时需要加载ChatGLM的模型和tokenizer需要一段时间。在配置文件`config.py`中设置参数会影响模型的内存和显存使用,因此程序可能会导致低配计算机卡死。
## [36/48] 请对下面的程序文件做一个概述: request_llm\bridge_chatgpt.py ## [36/48] 请对下面的程序文件做一个概述: request_llms\bridge_chatgpt.py
该文件为 Python 代码文件,文件名为 request_llm\bridge_chatgpt.py。该代码文件主要提供三个函数predict、predict_no_ui和 predict_no_ui_long_connection用于发送至 chatGPT 并等待回复,获取输出。该代码文件还包含一些辅助函数,用于处理连接异常、生成 HTTP 请求等。该文件的代码架构清晰,使用了多个自定义函数和模块。 该文件为 Python 代码文件,文件名为 request_llms\bridge_chatgpt.py。该代码文件主要提供三个函数predict、predict_no_ui和 predict_no_ui_long_connection用于发送至 chatGPT 并等待回复,获取输出。该代码文件还包含一些辅助函数,用于处理连接异常、生成 HTTP 请求等。该文件的代码架构清晰,使用了多个自定义函数和模块。
## [37/48] 请对下面的程序文件做一个概述: request_llm\bridge_jittorllms_llama.py ## [37/48] 请对下面的程序文件做一个概述: request_llms\bridge_jittorllms_llama.py
该代码文件实现了一个聊天机器人,其中使用了 JittorLLMs 模型。主要包括以下几个部分: 该代码文件实现了一个聊天机器人,其中使用了 JittorLLMs 模型。主要包括以下几个部分:
1. GetGLMHandle 类:一个进程类,用于加载 JittorLLMs 模型并接收并处理请求。 1. GetGLMHandle 类:一个进程类,用于加载 JittorLLMs 模型并接收并处理请求。
@@ -248,17 +248,17 @@ toolbox.py是一个工具类库其中主要包含了一些函数装饰器和
这个文件中还有一些辅助函数和全局变量,例如 importlib、time、threading 等。 这个文件中还有一些辅助函数和全局变量,例如 importlib、time、threading 等。
## [38/48] 请对下面的程序文件做一个概述: request_llm\bridge_jittorllms_pangualpha.py ## [38/48] 请对下面的程序文件做一个概述: request_llms\bridge_jittorllms_pangualpha.py
这个文件是为了实现使用jittorllms一种机器学习模型来进行聊天功能的代码。其中包括了模型加载、模型的参数加载、消息的收发等相关操作。其中使用了多进程和多线程来提高性能和效率。代码中还包括了处理依赖关系的函数和预处理函数等。 这个文件是为了实现使用jittorllms一种机器学习模型来进行聊天功能的代码。其中包括了模型加载、模型的参数加载、消息的收发等相关操作。其中使用了多进程和多线程来提高性能和效率。代码中还包括了处理依赖关系的函数和预处理函数等。
## [39/48] 请对下面的程序文件做一个概述: request_llm\bridge_jittorllms_rwkv.py ## [39/48] 请对下面的程序文件做一个概述: request_llms\bridge_jittorllms_rwkv.py
这个文件是一个Python程序文件名为request_llm\bridge_jittorllms_rwkv.py。它依赖transformers、time、threading、importlib、multiprocessing等库。在文件中通过定义GetGLMHandle类加载jittorllms模型参数和定义stream_chat方法来实现与jittorllms模型的交互。同时该文件还定义了predict_no_ui_long_connection和predict方法来处理历史信息、调用jittorllms模型、接收回复信息并输出结果。 这个文件是一个Python程序文件名为request_llm\bridge_jittorllms_rwkv.py。它依赖transformers、time、threading、importlib、multiprocessing等库。在文件中通过定义GetGLMHandle类加载jittorllms模型参数和定义stream_chat方法来实现与jittorllms模型的交互。同时该文件还定义了predict_no_ui_long_connection和predict方法来处理历史信息、调用jittorllms模型、接收回复信息并输出结果。
## [40/48] 请对下面的程序文件做一个概述: request_llm\bridge_moss.py ## [40/48] 请对下面的程序文件做一个概述: request_llms\bridge_moss.py
该文件为一个Python源代码文件文件名为 request_llm\bridge_moss.py。代码定义了一个 GetGLMHandle 类和两个函数 predict_no_ui_long_connection 和 predict。 该文件为一个Python源代码文件文件名为 request_llms\bridge_moss.py。代码定义了一个 GetGLMHandle 类和两个函数 predict_no_ui_long_connection 和 predict。
GetGLMHandle 类继承自Process类多进程主要功能是启动一个子进程并加载 MOSS 模型参数,通过 Pipe 进行主子进程的通信。该类还定义了 check_dependency、moss_init、run 和 stream_chat 等方法,其中 check_dependency 和 moss_init 是子进程的初始化方法run 是子进程运行方法stream_chat 实现了主进程和子进程的交互过程。 GetGLMHandle 类继承自Process类多进程主要功能是启动一个子进程并加载 MOSS 模型参数,通过 Pipe 进行主子进程的通信。该类还定义了 check_dependency、moss_init、run 和 stream_chat 等方法,其中 check_dependency 和 moss_init 是子进程的初始化方法run 是子进程运行方法stream_chat 实现了主进程和子进程的交互过程。
@@ -266,7 +266,7 @@ GetGLMHandle 类继承自Process类多进程主要功能是启动一个
函数 predict 是单线程方法,通过调用 update_ui 将交互过程中 MOSS 的回复实时更新到UIUser Interface并执行一个 named functionadditional_fn指定的函数对输入进行预处理。 函数 predict 是单线程方法,通过调用 update_ui 将交互过程中 MOSS 的回复实时更新到UIUser Interface并执行一个 named functionadditional_fn指定的函数对输入进行预处理。
## [41/48] 请对下面的程序文件做一个概述: request_llm\bridge_newbing.py ## [41/48] 请对下面的程序文件做一个概述: request_llms\bridge_newbing.py
这是一个名为`bridge_newbing.py`的程序文件,包含三个部分: 这是一个名为`bridge_newbing.py`的程序文件,包含三个部分:
@@ -276,11 +276,11 @@ GetGLMHandle 类继承自Process类多进程主要功能是启动一个
第三部分定义了一个名为`newbing_handle`的全局变量,并导出了`predict_no_ui_long_connection``predict`这两个方法,以供其他程序可以调用。 第三部分定义了一个名为`newbing_handle`的全局变量,并导出了`predict_no_ui_long_connection``predict`这两个方法,以供其他程序可以调用。
## [42/48] 请对下面的程序文件做一个概述: request_llm\bridge_newbingfree.py ## [42/48] 请对下面的程序文件做一个概述: request_llms\bridge_newbingfree.py
这个Python文件包含了三部分内容。第一部分是来自edge_gpt_free.py文件的聊天机器人程序。第二部分是子进程Worker用于调用主体。第三部分提供了两个函数predict_no_ui_long_connection和predict用于调用NewBing聊天机器人和返回响应。其中predict函数还提供了一些参数用于控制聊天机器人的回复和更新UI界面。 这个Python文件包含了三部分内容。第一部分是来自edge_gpt_free.py文件的聊天机器人程序。第二部分是子进程Worker用于调用主体。第三部分提供了两个函数predict_no_ui_long_connection和predict用于调用NewBing聊天机器人和返回响应。其中predict函数还提供了一些参数用于控制聊天机器人的回复和更新UI界面。
## [43/48] 请对下面的程序文件做一个概述: request_llm\bridge_stackclaude.py ## [43/48] 请对下面的程序文件做一个概述: request_llms\bridge_stackclaude.py
这是一个Python源代码文件文件名为request_llm\bridge_stackclaude.py。代码分为三个主要部分 这是一个Python源代码文件文件名为request_llm\bridge_stackclaude.py。代码分为三个主要部分
@@ -290,21 +290,21 @@ GetGLMHandle 类继承自Process类多进程主要功能是启动一个
第三部分定义了predict_no_ui_long_connection和predict两个函数主要用于通过调用ClaudeHandle对象的stream_chat方法来获取Claude的回复并更新ui以显示相关信息。其中predict函数采用单线程方法而predict_no_ui_long_connection函数使用多线程方法。 第三部分定义了predict_no_ui_long_connection和predict两个函数主要用于通过调用ClaudeHandle对象的stream_chat方法来获取Claude的回复并更新ui以显示相关信息。其中predict函数采用单线程方法而predict_no_ui_long_connection函数使用多线程方法。
## [44/48] 请对下面的程序文件做一个概述: request_llm\bridge_tgui.py ## [44/48] 请对下面的程序文件做一个概述: request_llms\bridge_tgui.py
该文件是一个Python代码文件名为request_llm\bridge_tgui.py。它包含了一些函数用于与chatbot UI交互并通过WebSocket协议与远程LLM模型通信完成文本生成任务其中最重要的函数是predict()和predict_no_ui_long_connection()。这个程序还有其他的辅助函数如random_hash()。整个代码文件在协作的基础上完成了一次修改。 该文件是一个Python代码文件名为request_llm\bridge_tgui.py。它包含了一些函数用于与chatbot UI交互并通过WebSocket协议与远程LLM模型通信完成文本生成任务其中最重要的函数是predict()和predict_no_ui_long_connection()。这个程序还有其他的辅助函数如random_hash()。整个代码文件在协作的基础上完成了一次修改。
## [45/48] 请对下面的程序文件做一个概述: request_llm\edge_gpt.py ## [45/48] 请对下面的程序文件做一个概述: request_llms\edge_gpt.py
该文件是一个用于调用Bing chatbot API的Python程序它由多个类和辅助函数构成可以根据给定的对话连接在对话中提出问题使用websocket与远程服务通信。程序实现了一个聊天机器人可以为用户提供人工智能聊天。 该文件是一个用于调用Bing chatbot API的Python程序它由多个类和辅助函数构成可以根据给定的对话连接在对话中提出问题使用websocket与远程服务通信。程序实现了一个聊天机器人可以为用户提供人工智能聊天。
## [46/48] 请对下面的程序文件做一个概述: request_llm\edge_gpt_free.py ## [46/48] 请对下面的程序文件做一个概述: request_llms\edge_gpt_free.py
该代码文件为一个会话API可通过Chathub发送消息以返回响应。其中使用了 aiohttp 和 httpx 库进行网络请求并发送。代码中包含了一些函数和常量,多数用于生成请求数据或是请求头信息等。同时该代码文件还包含了一个 Conversation 类,调用该类可实现对话交互。 该代码文件为一个会话API可通过Chathub发送消息以返回响应。其中使用了 aiohttp 和 httpx 库进行网络请求并发送。代码中包含了一些函数和常量,多数用于生成请求数据或是请求头信息等。同时该代码文件还包含了一个 Conversation 类,调用该类可实现对话交互。
## [47/48] 请对下面的程序文件做一个概述: request_llm\test_llms.py ## [47/48] 请对下面的程序文件做一个概述: request_llms\test_llms.py
这个文件是用于对llm模型进行单元测试的Python程序。程序导入一个名为"request_llm.bridge_newbingfree"的模块然后三次使用该模块中的predict_no_ui_long_connection()函数进行预测,并输出结果。此外,还有一些注释掉的代码段,这些代码段也是关于模型预测的。 这个文件是用于对llm模型进行单元测试的Python程序。程序导入一个名为"request_llms.bridge_newbingfree"的模块然后三次使用该模块中的predict_no_ui_long_connection()函数进行预测,并输出结果。此外,还有一些注释掉的代码段,这些代码段也是关于模型预测的。
## 用一张Markdown表格简要描述以下文件的功能 ## 用一张Markdown表格简要描述以下文件的功能
check_proxy.py, colorful.py, config.py, config_private.py, core_functional.py, crazy_functional.py, main.py, multi_language.py, theme.py, toolbox.py, crazy_functions\crazy_functions_test.py, crazy_functions\crazy_utils.py, crazy_functions\Latex全文润色.py, crazy_functions\Latex全文翻译.py, crazy_functions\__init__.py, crazy_functions\下载arxiv论文翻译摘要.py。根据以上分析用一句话概括程序的整体功能。 check_proxy.py, colorful.py, config.py, config_private.py, core_functional.py, crazy_functional.py, main.py, multi_language.py, theme.py, toolbox.py, crazy_functions\crazy_functions_test.py, crazy_functions\crazy_utils.py, crazy_functions\Latex全文润色.py, crazy_functions\Latex全文翻译.py, crazy_functions\__init__.py, crazy_functions\下载arxiv论文翻译摘要.py。根据以上分析用一句话概括程序的整体功能。
@@ -355,24 +355,24 @@ crazy_functions\代码重写为全英文_多线程.py, crazy_functions\图片生
概括程序的整体功能:提供了一系列处理文本、文件和代码的功能,使用了各类语言模型、多线程、网络请求和数据解析技术来提高效率和精度。 概括程序的整体功能:提供了一系列处理文本、文件和代码的功能,使用了各类语言模型、多线程、网络请求和数据解析技术来提高效率和精度。
## 用一张Markdown表格简要描述以下文件的功能 ## 用一张Markdown表格简要描述以下文件的功能
crazy_functions\谷歌检索小助手.py, crazy_functions\高级功能函数模板.py, request_llm\bridge_all.py, request_llm\bridge_chatglm.py, request_llm\bridge_chatgpt.py, request_llm\bridge_jittorllms_llama.py, request_llm\bridge_jittorllms_pangualpha.py, request_llm\bridge_jittorllms_rwkv.py, request_llm\bridge_moss.py, request_llm\bridge_newbing.py, request_llm\bridge_newbingfree.py, request_llm\bridge_stackclaude.py, request_llm\bridge_tgui.py, request_llm\edge_gpt.py, request_llm\edge_gpt_free.py, request_llm\test_llms.py。根据以上分析用一句话概括程序的整体功能。 crazy_functions\谷歌检索小助手.py, crazy_functions\高级功能函数模板.py, request_llms\bridge_all.py, request_llms\bridge_chatglm.py, request_llms\bridge_chatgpt.py, request_llms\bridge_jittorllms_llama.py, request_llms\bridge_jittorllms_pangualpha.py, request_llms\bridge_jittorllms_rwkv.py, request_llms\bridge_moss.py, request_llms\bridge_newbing.py, request_llms\bridge_newbingfree.py, request_llms\bridge_stackclaude.py, request_llms\bridge_tgui.py, request_llms\edge_gpt.py, request_llms\edge_gpt_free.py, request_llms\test_llms.py。根据以上分析用一句话概括程序的整体功能。
| 文件名 | 功能描述 | | 文件名 | 功能描述 |
| --- | --- | | --- | --- |
| crazy_functions\谷歌检索小助手.py | 提供谷歌学术搜索页面中相关文章的元数据信息。 | | crazy_functions\谷歌检索小助手.py | 提供谷歌学术搜索页面中相关文章的元数据信息。 |
| crazy_functions\高级功能函数模板.py | 使用Unsplash API发送相关图片以回复用户的输入。 | | crazy_functions\高级功能函数模板.py | 使用Unsplash API发送相关图片以回复用户的输入。 |
| request_llm\bridge_all.py | 基于不同LLM模型进行对话。 | | request_llms\bridge_all.py | 基于不同LLM模型进行对话。 |
| request_llm\bridge_chatglm.py | 使用ChatGLM模型生成回复支持单线程和多线程方式。 | | request_llms\bridge_chatglm.py | 使用ChatGLM模型生成回复支持单线程和多线程方式。 |
| request_llm\bridge_chatgpt.py | 基于GPT模型完成对话。 | | request_llms\bridge_chatgpt.py | 基于GPT模型完成对话。 |
| request_llm\bridge_jittorllms_llama.py | 使用JittorLLMs模型完成对话支持单线程和多线程方式。 | | request_llms\bridge_jittorllms_llama.py | 使用JittorLLMs模型完成对话支持单线程和多线程方式。 |
| request_llm\bridge_jittorllms_pangualpha.py | 使用JittorLLMs模型完成对话基于多进程和多线程方式。 | | request_llms\bridge_jittorllms_pangualpha.py | 使用JittorLLMs模型完成对话基于多进程和多线程方式。 |
| request_llm\bridge_jittorllms_rwkv.py | 使用JittorLLMs模型完成聊天功能提供包括历史信息、参数调节等在内的多个功能选项。 | | request_llms\bridge_jittorllms_rwkv.py | 使用JittorLLMs模型完成聊天功能提供包括历史信息、参数调节等在内的多个功能选项。 |
| request_llm\bridge_moss.py | 加载Moss模型完成对话功能。 | | request_llms\bridge_moss.py | 加载Moss模型完成对话功能。 |
| request_llm\bridge_newbing.py | 使用Newbing聊天机器人进行对话支持单线程和多线程方式。 | | request_llms\bridge_newbing.py | 使用Newbing聊天机器人进行对话支持单线程和多线程方式。 |
| request_llm\bridge_newbingfree.py | 基于Bing chatbot API实现聊天机器人的文本生成功能。 | | request_llms\bridge_newbingfree.py | 基于Bing chatbot API实现聊天机器人的文本生成功能。 |
| request_llm\bridge_stackclaude.py | 基于Slack API实现Claude与用户的交互。 | | request_llms\bridge_stackclaude.py | 基于Slack API实现Claude与用户的交互。 |
| request_llm\bridge_tgui.py | 通过websocket实现聊天机器人与UI界面交互。 | | request_llms\bridge_tgui.py | 通过websocket实现聊天机器人与UI界面交互。 |
| request_llm\edge_gpt.py | 调用Bing chatbot API提供聊天机器人服务。 | | request_llms\edge_gpt.py | 调用Bing chatbot API提供聊天机器人服务。 |
| request_llm\edge_gpt_free.py | 实现聊天机器人API采用aiohttp和httpx工具库。 | | request_llms\edge_gpt_free.py | 实现聊天机器人API采用aiohttp和httpx工具库。 |
| request_llm\test_llms.py | 对llm模型进行单元测试。 | | request_llms\test_llms.py | 对llm模型进行单元测试。 |
| 程序整体功能 | 实现不同种类的聊天机器人,可以根据输入进行文本生成。 | | 程序整体功能 | 实现不同种类的聊天机器人,可以根据输入进行文本生成。 |

View File

@@ -265,7 +265,7 @@
"例如chatglm&gpt-3.5-turbo&api2d-gpt-4": "e.g. chatglm&gpt-3.5-turbo&api2d-gpt-4", "例如chatglm&gpt-3.5-turbo&api2d-gpt-4": "e.g. chatglm&gpt-3.5-turbo&api2d-gpt-4",
"先切换模型到openai或api2d": "Switch the model to openai or api2d first", "先切换模型到openai或api2d": "Switch the model to openai or api2d first",
"在这里输入分辨率": "Enter the resolution here", "在这里输入分辨率": "Enter the resolution here",
"如256x256": "e.g. 256x256", "如1024x1024": "e.g. 1024x1024",
"默认": "Default", "默认": "Default",
"建议您复制一个config_private.py放自己的秘密": "We suggest you to copy a config_private.py file to keep your secrets, such as API and proxy URLs, from being accidentally uploaded to Github and seen by others.", "建议您复制一个config_private.py放自己的秘密": "We suggest you to copy a config_private.py file to keep your secrets, such as API and proxy URLs, from being accidentally uploaded to Github and seen by others.",
"如API和代理网址": "Such as API and proxy URLs", "如API和代理网址": "Such as API and proxy URLs",
@@ -322,7 +322,7 @@
"任何文件": "Any file", "任何文件": "Any file",
"但推荐上传压缩文件": "But it is recommended to upload compressed files", "但推荐上传压缩文件": "But it is recommended to upload compressed files",
"更换模型 & SysPrompt & 交互界面布局": "Change model & SysPrompt & interactive interface layout", "更换模型 & SysPrompt & 交互界面布局": "Change model & SysPrompt & interactive interface layout",
"底部输入区": "Bottom input area", "浮动输入区": "Floating input area",
"输入清除键": "Input clear key", "输入清除键": "Input clear key",
"插件参数区": "Plugin parameter area", "插件参数区": "Plugin parameter area",
"显示/隐藏功能区": "Show/hide function area", "显示/隐藏功能区": "Show/hide function area",
@@ -1184,7 +1184,7 @@
"Call ChatGLM fail 不能正常加载ChatGLM的参数": "Call ChatGLM fail, unable to load parameters for ChatGLM", "Call ChatGLM fail 不能正常加载ChatGLM的参数": "Call ChatGLM fail, unable to load parameters for ChatGLM",
"不能正常加载ChatGLM的参数": "Unable to load parameters for ChatGLM!", "不能正常加载ChatGLM的参数": "Unable to load parameters for ChatGLM!",
"多线程方法": "Multithreading method", "多线程方法": "Multithreading method",
"函数的说明请见 request_llm/bridge_all.py": "For function details, please see request_llm/bridge_all.py", "函数的说明请见 request_llms/bridge_all.py": "For function details, please see request_llms/bridge_all.py",
"程序终止": "Program terminated", "程序终止": "Program terminated",
"单线程方法": "Single-threaded method", "单线程方法": "Single-threaded method",
"等待ChatGLM响应中": "Waiting for response from ChatGLM", "等待ChatGLM响应中": "Waiting for response from ChatGLM",
@@ -1543,7 +1543,7 @@
"str类型": "str type", "str类型": "str type",
"所有音频都总结完成了吗": "Are all audio summaries completed?", "所有音频都总结完成了吗": "Are all audio summaries completed?",
"SummaryAudioVideo内容": "SummaryAudioVideo content", "SummaryAudioVideo内容": "SummaryAudioVideo content",
"使用教程详情见 request_llm/README.md": "See request_llm/README.md for detailed usage instructions", "使用教程详情见 request_llms/README.md": "See request_llms/README.md for detailed usage instructions",
"删除中间文件夹": "Delete intermediate folder", "删除中间文件夹": "Delete intermediate folder",
"Claude组件初始化成功": "Claude component initialized successfully", "Claude组件初始化成功": "Claude component initialized successfully",
"$c$ 是光速": "$c$ is the speed of light", "$c$ 是光速": "$c$ is the speed of light",
@@ -2513,5 +2513,280 @@
"此处待注入的知识库名称id": "The knowledge base name ID to be injected here", "此处待注入的知识库名称id": "The knowledge base name ID to be injected here",
"您需要构建知识库后再运行此插件": "You need to build the knowledge base before running this plugin", "您需要构建知识库后再运行此插件": "You need to build the knowledge base before running this plugin",
"判定是否为公式 | 测试1 写出洛伦兹定律": "Determine whether it is a formula | Test 1 write out the Lorentz law", "判定是否为公式 | 测试1 写出洛伦兹定律": "Determine whether it is a formula | Test 1 write out the Lorentz law",
"构建知识库后": "After building the knowledge base" "构建知识库后": "After building the knowledge base",
"找不到本地项目或无法处理": "Unable to find local project or unable to process",
"再做一个小修改": "Make another small modification",
"解析整个Matlab项目": "Parse the entire Matlab project",
"需要用GPT提取参数": "Need to extract parameters using GPT",
"文件路径": "File path",
"正在排队": "In queue",
"-=-=-=-=-=-=-=-= 写出第1个文件": "-=-=-=-=-=-=-=-= Write the first file",
"仅翻译后的文本 -=-=-=-=-=-=-=-=": "Translated text only -=-=-=-=-=-=-=-=",
"对话通道": "Conversation channel",
"找不到任何": "Unable to find any",
"正在启动": "Starting",
"开始创建新进程并执行代码! 时间限制": "Start creating a new process and executing the code! Time limit",
"解析Matlab项目": "Parse Matlab project",
"更换UI主题": "Change UI theme",
"⭐ 开始啦 ": "⭐ Let's start!",
"先提取当前英文标题": "First extract the current English title",
"睡一会防止触发google反爬虫": "Sleep for a while to prevent triggering Google anti-crawler",
"测试": "Test",
"-=-=-=-=-=-=-=-= 写出Markdown文件 -=-=-=-=-=-=-=-=": "-=-=-=-=-=-=-=-= Write out Markdown file",
"如果index是1的话": "If the index is 1",
"VoidTerminal已经实现了类似的代码": "VoidTerminal has already implemented similar code",
"等待线程锁": "Waiting for thread lock",
"那么我们默认代理生效": "Then we default to proxy",
"结果是一个有效文件": "The result is a valid file",
"⭐ 检查模块": "⭐ Check module",
"备份一份History作为记录": "Backup a copy of History as a record",
"作者Binary-Husky": "Author Binary-Husky",
"将csv文件转excel表格": "Convert CSV file to Excel table",
"获取文章摘要": "Get article summary",
"次代码生成尝试": "Attempt to generate code",
"如果参数是空的": "If the parameter is empty",
"请配置讯飞星火大模型的XFYUN_APPID": "Please configure XFYUN_APPID for the Xunfei Starfire model",
"-=-=-=-=-=-=-=-= 写出第2个文件": "Write the second file",
"代码生成阶段结束": "Code generation phase completed",
"则进行提醒": "Then remind",
"处理异常": "Handle exception",
"可能触发了google反爬虫机制": "May have triggered Google anti-crawler mechanism",
"AnalyzeAMatlabProject的所有源文件": "All source files of AnalyzeAMatlabProject",
"写入": "Write",
"我们5秒后再试一次...": "Let's try again in 5 seconds...",
"判断一下用户是否错误地通过对话通道进入": "Check if the user entered through the dialogue channel by mistake",
"结果": "Result",
"2. 如果没有文件": "2. If there is no file",
"由 test_on_sentence_end": "By test_on_sentence_end",
"则直接使用first section name": "Then directly use the first section name",
"太懒了": "Too lazy",
"记录当前的大章节标题": "Record the current chapter title",
"然后再次点击该插件! 至于您的文件": "Then click the plugin again! As for your file",
"此次我们的错误追踪是": "This time our error tracking is",
"首先在arxiv上搜索": "First search on arxiv",
"被新插件取代": "Replaced by a new plugin",
"正在处理文件": "Processing file",
"除了连接OpenAI之外": "In addition to connecting OpenAI",
"我们检查一下": "Let's check",
"进度": "Progress",
"处理少数情况下的特殊插件的锁定状态": "Handle the locked state of special plugins in a few cases",
"⭐ 开始执行": "⭐ Start execution",
"正常情况": "Normal situation",
"下个句子中已经说完的部分": "The part that has already been said in the next sentence",
"首次运行需要花费较长时间下载NOUGAT参数": "The first run takes a long time to download NOUGAT parameters",
"使用tex格式公式 测试2 给出柯西不等式": "Use the tex format formula to test 2 and give the Cauchy inequality",
"无法从bing获取信息": "Unable to retrieve information from Bing!",
"秒. 请等待任务完成": "Wait for the task to complete",
"开始干正事": "Start doing real work",
"需要花费较长时间下载NOUGAT参数": "It takes a long time to download NOUGAT parameters",
"然后再次点击该插件": "Then click the plugin again",
"受到bing限制": "Restricted by Bing",
"检索文章的历史版本的题目": "Retrieve the titles of historical versions of the article",
"收尾": "Wrap up",
"给定了task": "Given a task",
"某段话的整个句子": "The whole sentence of a paragraph",
"-=-=-=-=-=-=-=-= 写出HTML文件 -=-=-=-=-=-=-=-=": "-=-=-=-=-=-=-=-= Write out HTML file -=-=-=-=-=-=-=-=",
"当前文件": "Current file",
"请在输入框内填写需求": "Please fill in the requirements in the input box",
"结果是一个字符串": "The result is a string",
"用插件实现」": "Implemented with a plugin",
"⭐ 到最后一步了": "⭐ Reached the final step",
"重新修改当前part的标题": "Modify the title of the current part again",
"请勿点击“提交”按钮或者“基础功能区”按钮": "Do not click the 'Submit' button or the 'Basic Function Area' button",
"正在执行命令": "Executing command",
"检测到**滞留的缓存文档**": "Detected **stuck cache document**",
"第三步": "Step three",
"失败了~ 别担心": "Failed~ Don't worry",
"动态代码解释器": "Dynamic code interpreter",
"开始执行": "Start executing",
"不给定task": "No task given",
"正在加载NOUGAT...": "Loading NOUGAT...",
"精准翻译PDF文档": "Accurate translation of PDF documents",
"时间限制TIME_LIMIT": "Time limit TIME_LIMIT",
"翻译前后混合 -=-=-=-=-=-=-=-=": "Mixed translation before and after -=-=-=-=-=-=-=-=",
"搞定代码生成": "Code generation is done",
"插件通道": "Plugin channel",
"智能体": "Intelligent agent",
"切换界面明暗 ☀": "Switch interface brightness ☀",
"交换图像的蓝色通道和红色通道": "Swap blue channel and red channel of the image",
"作为函数参数": "As a function parameter",
"先挑选偶数序列号": "First select even serial numbers",
"仅供测试": "For testing only",
"执行成功了": "Execution succeeded",
"开始逐个文件进行处理": "Start processing files one by one",
"当前文件处理列表": "Current file processing list",
"执行失败了": "Execution failed",
"请及时处理": "Please handle it in time",
"源文件": "Source file",
"裁剪图像": "Crop image",
"插件动态生成插件": "Dynamic generation of plugins",
"正在验证上述代码的有效性": "Validating the above code",
"⭐ = 关键步骤": "⭐ = Key step",
"!= 0 代表“提交”键对话通道": "!= 0 represents the 'Submit' key dialogue channel",
"解析python源代码项目": "Parsing Python source code project",
"请检查PDF是否损坏": "Please check if the PDF is damaged",
"插件动态生成": "Dynamic generation of plugins",
"⭐ 分离代码块": "⭐ Separating code blocks",
"已经被记忆": "Already memorized",
"默认用英文的": "Default to English",
"错误追踪": "Error tracking",
"对话|编程|学术|智能体": "Dialogue|Programming|Academic|Intelligent agent",
"请检查": "Please check",
"检测到被滞留的缓存文档": "Detected cached documents being left behind",
"还有哪些场合允许使用代理": "What other occasions allow the use of proxies",
"1. 如果有文件": "1. If there is a file",
"执行开始": "Execution starts",
"代码生成结束": "Code generation ends",
"请及时点击“**保存当前对话**”获取所有滞留文档": "Please click '**Save Current Dialogue**' in time to obtain all cached documents",
"需点击“**函数插件区**”按钮进行处理": "Click the '**Function Plugin Area**' button for processing",
"此函数已经弃用": "This function has been deprecated",
"以后再写": "Write it later",
"返回给定的url解析出的arxiv_id": "Return the arxiv_id parsed from the given URL",
"⭐ 文件上传区是否有东西": "⭐ Is there anything in the file upload area",
"Nougat解析论文失败": "Nougat failed to parse the paper",
"本源代码中": "In this source code",
"或者基础功能通道": "Or the basic function channel",
"使用zip压缩格式": "Using zip compression format",
"受到google限制": "Restricted by Google",
"如果是": "If it is",
"不用担心": "don't worry",
"显示/隐藏自定义菜单": "Show/Hide Custom Menu",
"1. 输入文本": "1. Enter Text",
"微软AutoGen": "Microsoft AutoGen",
"在没有声音之后": "After No Sound",
"⭐ 主进程 Docker 外挂文件夹监控": "⭐ Main Process Docker External Folder Monitoring",
"请求任务": "Request Task",
"推荐上传压缩文件": "Recommend Uploading Compressed File",
"我准备好处理下一个问题了": "I'm ready to handle the next question",
"输入要反馈的内容": "Enter the content to be feedbacked",
"当已经存在一个正在运行的MultiAgentTerminal时": "When there is already a running MultiAgentTerminal",
"也根据时间间隔": "Also according to the time interval",
"自定义功能": "Custom Function",
"上传文件后会自动把输入区修改为相应路径": "After uploading the file, the input area will be automatically modified to the corresponding path",
"缺少docker运行环境": "Missing docker runtime environment!",
"暂不支持中转": "Transit is not supported temporarily",
"一些第三方接口的出现这样的错误": "Some third-party interfaces encounter such errors",
"项目Wiki": "Project Wiki",
"但是我们把上一帧同样加上": "But we also add the previous frame",
"AutoGen 执行失败": "AutoGen execution failed",
"程序抵达用户反馈节点": "The program reaches the user feedback node",
"预制功能": "Prefabricated Function",
"输入新按钮名称": "Enter the new button name",
"| 不需要输入参数": "| No input parameters required",
"如果有新文件出现": "If there is a new file",
"Bug反馈": "Bug Feedback",
"指定翻译成何种语言": "Specify the language to translate into",
"点击保存当前的对话按钮": "Click the save current conversation button",
"如果您需要补充些什么": "If you need to add something",
"HTTPS 秘钥和证书": "HTTPS Key and Certificate",
"输入exit": "Enter exit",
"输入新提示后缀": "Enter a new prompt suffix",
"如果是文本文件": "If it is a text file",
"支持动态切换主题": "Support dynamic theme switching",
"并与self.previous_work_dir_files中所记录的文件进行对比": "And compare with the files recorded in self.previous_work_dir_files",
"作者 Microsoft & Binary-Husky": "Author Microsoft & Binary-Husky",
"请在自定义菜单中定义提示词前缀": "Please define the prefix of the prompt word in the custom menu",
"一般情况下您不需要说什么": "In general, you don't need to say anything",
"「暗色主题已启用": "Dark theme enabled",
"继续向服务器发送n次音频数据": "Continue to send audio data to the server n times",
"获取fp的拓展名": "Get the extension name of fp",
"指令安装内置Gradio及其他依赖": "Command to install built-in Gradio and other dependencies",
"查看自动更新": "Check for automatic updates",
"则更新self.previous_work_dir_files中": "Then update in self.previous_work_dir_files",
"看门狗耐心": "Watchdog patience",
"检测到新生图像": "Detected new image",
"等待AutoGen执行结果": "Waiting for AutoGen execution result",
"自定义菜单": "Custom menu",
"保持链接激活": "Keep the link active",
"已经被新插件取代": "Has been replaced by a new plugin",
"检查当前的模型是否符合要求": "Check if the current model meets the requirements",
"交互功能模板Demo函数": "Interactive function template Demo function",
"上一帧没有人声": "No human voice in the previous frame",
"用于判断异常": "Used to judge exceptions",
"请阅读Wiki": "Please read the Wiki",
"查找wallhaven.cc的壁纸": "Search for wallpapers on wallhaven.cc",
"2. 点击任意基础功能区按钮": "2. Click any button in the basic function area",
"一些垃圾第三方接口的出现这样的错误": "Some errors caused by garbage third-party interfaces",
"再次点击VoidTerminal": "Click VoidTerminal again",
"结束信号已明确": "The end signal is clear",
"获取代理失败 无代理状态下很可能无法访问OpenAI家族的模型及谷歌学术 建议": "Failed to get proxy. It is very likely that you will not be able to access OpenAI family models and Google Scholar without a proxy. It is recommended",
"界面外观": "Interface appearance",
"如果您想终止程序": "If you want to terminate the program",
"2. 点击任意函数插件区按钮": "Click any function plugin area button",
"绕过openai访问频率限制": "Bypass openai access frequency limit",
"配置暗色主题或亮色主题": "Configure dark theme or light theme",
"自定义按钮的最大数量限制": "Maximum number limit for custom buttons",
"函数插件区使用说明": "Instructions for function plugin area",
"如何语音对话": "How to have a voice conversation",
"清空输入区": "Clear input area",
"文档清单如下": "The document list is as follows",
"由 audio_convertion_thread": "By audio_convertion_thread",
"音频的可视化表现": "Visual representation of audio",
"然后直接点击“提交”以继续": "Then click 'Submit' to continue",
"运行MultiAgentTerminal": "Run MultiAgentTerminal",
"自定义按钮1": "Custom button 1",
"查看历史上的今天事件": "View events from history",
"如遇到Bug请前往": "If you encounter a bug, please go to",
"当前插件只支持": "The current plugin only supports",
"而不是再次启动一个新的MultiAgentTerminal": "Instead of starting a new MultiAgentTerminal again",
"用户代理或助理代理未定义": "User agent or assistant agent is not defined",
"运行阶段-": "Running phase-",
"随机选择": "Random selection",
"直接点击“提交”以继续": "Click 'Submit' to continue",
"使用项目内置Gradio获取最优体验! 请运行": "Use the built-in Gradio for the best experience! Please run",
"直接点击“提交”以终止AutoGen并解锁": "Click 'Submit' to terminate AutoGen and unlock",
"Github源代码开源和更新": "Github source code is open source and updated",
"直接将用户输入传递给它": "Pass user input directly to it",
"这是一个面向开发者的插件Demo": "This is a plugin demo for developers",
"帮助": "Help",
"普通对话使用说明": "Instructions for normal conversation",
"自定义按钮": "Custom button",
"即使没有声音": "Even without sound",
"⭐ 主进程": "⭐ Main process",
"基础功能区使用说明": "Basic Function Area Usage Instructions",
"提前读取一些信息": "Read some information in advance",
"当用户点击了“等待反馈”按钮时": "When the user clicks the 'Wait for Feedback' button",
"选择一个需要自定义基础功能区按钮": "Select a button in the Basic Function Area that needs to be customized",
"VoidTerminal使用说明": "VoidTerminal Usage Instructions",
"兼容一下吧": "Let's make it compatible",
"⭐⭐ 子进程执行": "⭐⭐ Subprocess execution",
"首次": "For the first time",
"则直接显示文本内容": "Then display the text content directly",
"更新状态": "Update status",
"2. 点击提交": "2. Click Submit",
"⭐⭐ 子进程": "⭐⭐ Subprocess",
"输入新提示前缀": "Enter a new prompt prefix",
"等待用户输入超时": "Wait for user input timeout",
"把新文件和发生变化的文件的路径记录到 change_list 中": "Record the paths of new files and files that have changed in change_list",
"或者上传文件": "Or upload a file",
"或者文件的修改时间发生变化": "Or the modification time of the file has changed",
"1. 输入路径/问题": "1. Enter path/question",
"尝试直接连接": "Try to connect directly",
"未来将删除": "Will be deleted in the future",
"请在自定义菜单中定义提示词后缀": "Please define the suffix of the prompt word in the custom menu",
"将executor存储到cookie中": "Store the executor in the cookie",
"1. 输入问题": "1. Enter question",
"发送一些音频片段给服务器": "Send some audio clips to the server",
"点击VoidTerminal": "Click VoidTerminal",
"扫描路径下的所有文件": "Scan all files under the path",
"检测到新生文档": "Detect new documents",
"预热tiktoken模块": "Preheat the tiktoken module",
"等待您的进一步指令": "Waiting for your further instructions",
"实时语音对话": "Real-time voice conversation",
"确认并保存": "Confirm and save",
"「亮色主题已启用": "Light theme enabled",
"终止AutoGen程序": "Terminate AutoGen program",
"然后根据提示输入指令": "Then enter the command as prompted",
"请上传本地文件/压缩包供“函数插件区”功能调用": "Please upload local files/zip packages for 'Function Plugin Area' function call",
"上传文件": "Upload file",
"上一帧是否有人说话": "Was there anyone speaking in the previous frame",
"这是一个时刻聆听着的语音对话助手 | 没有输入参数": "This is a voice conversation assistant that is always listening | No input parameters",
"常见问题请查阅": "Please refer to the FAQ for common questions",
"更换模型 & Prompt": "Change model & Prompt",
"如何保存对话": "How to save the conversation",
"处理任务": "Process task",
"加载已保存": "Load saved",
"打开浏览器页面": "Open browser page",
"解锁插件": "Unlock plugin",
"如果话筒激活 / 如果处于回声收尾阶段": "If the microphone is active / If it is in the echo tail stage"
} }

View File

@@ -782,7 +782,7 @@
"主进程统一调用函数接口": "メインプロセスが関数インターフェースを統一的に呼び出します", "主进程统一调用函数接口": "メインプロセスが関数インターフェースを統一的に呼び出します",
"再例如一个包含了待处理文件的路径": "処理待ちのファイルを含むパスの例", "再例如一个包含了待处理文件的路径": "処理待ちのファイルを含むパスの例",
"负责把学术论文准确翻译成中文": "学術論文を正確に中国語に翻訳する責任があります", "负责把学术论文准确翻译成中文": "学術論文を正確に中国語に翻訳する責任があります",
"函数的说明请见 request_llm/bridge_all.py": "関数の説明については、request_llm/bridge_all.pyを参照してください", "函数的说明请见 request_llms/bridge_all.py": "関数の説明については、request_llms/bridge_all.pyを参照してください",
"然后回车提交": "そしてEnterを押して提出してください", "然后回车提交": "そしてEnterを押して提出してください",
"防止爆token": "トークンの爆発を防止する", "防止爆token": "トークンの爆発を防止する",
"Latex项目全文中译英": "LaTeXプロジェクト全文の中国語から英語への翻訳", "Latex项目全文中译英": "LaTeXプロジェクト全文の中国語から英語への翻訳",
@@ -854,7 +854,7 @@
"查询版本和用户意见": "バージョンとユーザーの意見を検索する", "查询版本和用户意见": "バージョンとユーザーの意見を検索する",
"提取摘要": "要約を抽出する", "提取摘要": "要約を抽出する",
"在gpt输出代码的中途": "GPTがコードを出力する途中で", "在gpt输出代码的中途": "GPTがコードを出力する途中で",
"如256x256": "256x256のように", "如1024x1024": "1024x1024のように",
"概括其内容": "内容を要約する", "概括其内容": "内容を要約する",
"剩下的情况都开头除去": "残りの場合はすべて先頭を除去する", "剩下的情况都开头除去": "残りの場合はすべて先頭を除去する",
"至少一个线程任务意外失败": "少なくとも1つのスレッドタスクが予期しない失敗をした", "至少一个线程任务意外失败": "少なくとも1つのスレッドタスクが予期しない失敗をした",
@@ -1007,7 +1007,6 @@
"第一部分": "第1部分", "第一部分": "第1部分",
"的分析如下": "の分析は以下の通りです", "的分析如下": "の分析は以下の通りです",
"解决一个mdx_math的bug": "mdx_mathのバグを解決する", "解决一个mdx_math的bug": "mdx_mathのバグを解決する",
"底部输入区": "下部の入力エリア",
"函数插件输入输出接驳区": "関数プラグインの入出力接続エリア", "函数插件输入输出接驳区": "関数プラグインの入出力接続エリア",
"打开浏览器": "ブラウザを開く", "打开浏览器": "ブラウザを開く",
"免费用户填3": "無料ユーザーは3を入力してください", "免费用户填3": "無料ユーザーは3を入力してください",
@@ -1617,7 +1616,7 @@
"正在重试": "再試行中", "正在重试": "再試行中",
"从而更全面地理解项目的整体功能": "プロジェクトの全体的な機能をより理解するために", "从而更全面地理解项目的整体功能": "プロジェクトの全体的な機能をより理解するために",
"正在等您说完问题": "質問が完了するのをお待ちしています", "正在等您说完问题": "質問が完了するのをお待ちしています",
"使用教程详情见 request_llm/README.md": "使用方法の詳細については、request_llm/README.mdを参照してください", "使用教程详情见 request_llms/README.md": "使用方法の詳細については、request_llms/README.mdを参照してください",
"6.25 加入判定latex模板的代码": "6.25 テンプレートの判定コードを追加", "6.25 加入判定latex模板的代码": "6.25 テンプレートの判定コードを追加",
"找不到任何音频或视频文件": "音声またはビデオファイルが見つかりません", "找不到任何音频或视频文件": "音声またはビデオファイルが見つかりません",
"请求GPT模型的": "GPTモデルのリクエスト", "请求GPT模型的": "GPTモデルのリクエスト",

View File

@@ -90,5 +90,9 @@
"解析PDF_基于GROBID": "ParsePDF_BasedOnGROBID", "解析PDF_基于GROBID": "ParsePDF_BasedOnGROBID",
"虚空终端主路由": "VoidTerminalMainRoute", "虚空终端主路由": "VoidTerminalMainRoute",
"批量翻译PDF文档_NOUGAT": "BatchTranslatePDFDocuments_NOUGAT", "批量翻译PDF文档_NOUGAT": "BatchTranslatePDFDocuments_NOUGAT",
"解析PDF_基于NOUGAT": "ParsePDF_NOUGAT" "解析PDF_基于NOUGAT": "ParsePDF_NOUGAT",
"解析一个Matlab项目": "AnalyzeAMatlabProject",
"函数动态生成": "DynamicFunctionGeneration",
"多智能体终端": "MultiAgentTerminal",
"多智能体": "MultiAgent"
} }

View File

@@ -123,7 +123,7 @@
"的第": "的第", "的第": "的第",
"减少重复": "減少重複", "减少重复": "減少重複",
"如果超过期限没有喂狗": "如果超過期限沒有餵狗", "如果超过期限没有喂狗": "如果超過期限沒有餵狗",
"函数的说明请见 request_llm/bridge_all.py": "函數的說明請見 request_llm/bridge_all.py", "函数的说明请见 request_llms/bridge_all.py": "函數的說明請見 request_llms/bridge_all.py",
"第7步": "第7步", "第7步": "第7步",
"说": "說", "说": "說",
"中途接收可能的终止指令": "中途接收可能的終止指令", "中途接收可能的终止指令": "中途接收可能的終止指令",
@@ -346,7 +346,6 @@
"情况会好转": "情況會好轉", "情况会好转": "情況會好轉",
"超过512个": "超過512個", "超过512个": "超過512個",
"多线": "多線", "多线": "多線",
"底部输入区": "底部輸入區",
"合并小写字母开头的段落块并替换为空格": "合併小寫字母開頭的段落塊並替換為空格", "合并小写字母开头的段落块并替换为空格": "合併小寫字母開頭的段落塊並替換為空格",
"暗色主题": "暗色主題", "暗色主题": "暗色主題",
"提高限制请查询": "提高限制請查詢", "提高限制请查询": "提高限制請查詢",
@@ -1148,7 +1147,7 @@
"Y+回车=确认": "Y+回車=確認", "Y+回车=确认": "Y+回車=確認",
"正在同时咨询ChatGPT和ChatGLM……": "正在同時諮詢ChatGPT和ChatGLM……", "正在同时咨询ChatGPT和ChatGLM……": "正在同時諮詢ChatGPT和ChatGLM……",
"根据 heuristic 规则": "根據heuristic規則", "根据 heuristic 规则": "根據heuristic規則",
"如256x256": "如256x256", "如1024x1024": "如1024x1024",
"函数插件区": "函數插件區", "函数插件区": "函數插件區",
"*** API_KEY 导入成功": "*** API_KEY 導入成功", "*** API_KEY 导入成功": "*** API_KEY 導入成功",
"请对下面的程序文件做一个概述文件名是": "請對下面的程序文件做一個概述文件名是", "请对下面的程序文件做一个概述文件名是": "請對下面的程序文件做一個概述文件名是",
@@ -1888,7 +1887,7 @@
"请继续分析其他源代码": "請繼續分析其他源代碼", "请继续分析其他源代码": "請繼續分析其他源代碼",
"质能方程式": "質能方程式", "质能方程式": "質能方程式",
"功能尚不稳定": "功能尚不穩定", "功能尚不稳定": "功能尚不穩定",
"使用教程详情见 request_llm/README.md": "使用教程詳情見 request_llm/README.md", "使用教程详情见 request_llms/README.md": "使用教程詳情見 request_llms/README.md",
"从以上搜索结果中抽取信息": "從以上搜索結果中抽取信息", "从以上搜索结果中抽取信息": "從以上搜索結果中抽取信息",
"虽然PDF生成失败了": "雖然PDF生成失敗了", "虽然PDF生成失败了": "雖然PDF生成失敗了",
"找图片": "尋找圖片", "找图片": "尋找圖片",

View File

@@ -1,3 +1,42 @@
# 微软Azure云接入指南
## 方法一旧方法只能接入一个Azure模型
- 通过以下教程获取AZURE_ENDPOINTAZURE_API_KEYAZURE_ENGINE直接修改 config 配置即可。配置的修改方法见本项目wiki。
## 方法二新方法接入多个Azure模型并支持动态切换
- 在方法一的基础上,注册并获取多组 AZURE_ENDPOINTAZURE_API_KEYAZURE_ENGINE
- 修改config中的AZURE_CFG_ARRAY和AVAIL_LLM_MODELS配置项按照格式填入多个Azure模型的配置如下所示
```
AZURE_CFG_ARRAY = {
"azure-gpt-3.5": # 第一个模型azure模型必须以"azure-"开头,注意您还需要将"azure-gpt-3.5"加入AVAIL_LLM_MODELS模型下拉菜单
{
"AZURE_ENDPOINT": "https://你亲手写的api名称.openai.azure.com/",
"AZURE_API_KEY": "cccccccccccccccccccccccccccccccc",
"AZURE_ENGINE": "填入你亲手写的部署名1",
"AZURE_MODEL_MAX_TOKEN": 4096,
},
"azure-gpt-4": # 第二个模型azure模型必须以"azure-"开头,注意您还需要将"azure-gpt-4"加入AVAIL_LLM_MODELS模型下拉菜单
{
"AZURE_ENDPOINT": "https://你亲手写的api名称.openai.azure.com/",
"AZURE_API_KEY": "dddddddddddddddddddddddddddddddd",
"AZURE_ENGINE": "填入你亲手写的部署名2",
"AZURE_MODEL_MAX_TOKEN": 8192,
},
"azure-gpt-3.5-16k": # 第三个模型azure模型必须以"azure-"开头,注意您还需要将"azure-gpt-3.5-16k"加入AVAIL_LLM_MODELS模型下拉菜单
{
"AZURE_ENDPOINT": "https://你亲手写的api名称.openai.azure.com/",
"AZURE_API_KEY": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"AZURE_ENGINE": "填入你亲手写的部署名3",
"AZURE_MODEL_MAX_TOKEN": 16384,
},
}
```
# 通过微软Azure云服务申请 Openai API # 通过微软Azure云服务申请 Openai API
由于Openai和微软的关系现在是可以通过微软的Azure云计算服务直接访问openai的api免去了注册和网络的问题。 由于Openai和微软的关系现在是可以通过微软的Azure云计算服务直接访问openai的api免去了注册和网络的问题。

236
main.py
View File

@@ -1,24 +1,36 @@
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
import pickle
import base64
def main(): def main():
import gradio as gr 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.32.6']:
from request_llm.bridge_all import predict raise ModuleNotFoundError("使用项目内置Gradio获取最优体验! 请运行 `pip install -r requirements.txt` 指令安装内置Gradio及其他依赖, 详情信息见requirements.txt.")
from request_llms.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 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被别人看到 # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION') 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') 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, PATH_LOGGING, AVAIL_THEMES, THEME = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT', 'PATH_LOGGING', 'AVAIL_THEMES', 'THEME') ENABLE_AUDIO, AUTO_CLEAR_TXT, PATH_LOGGING, AVAIL_THEMES, THEME = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT', 'PATH_LOGGING', 'AVAIL_THEMES', 'THEME')
DARK_MODE, NUM_CUSTOM_BASIC_BTN, SSL_KEYFILE, SSL_CERTFILE = get_conf('DARK_MODE', 'NUM_CUSTOM_BASIC_BTN', 'SSL_KEYFILE', 'SSL_CERTFILE')
INIT_SYS_PROMPT = get_conf('INIT_SYS_PROMPT')
# 如果WEB_PORT是-1, 则随机选取WEB端口 # 如果WEB_PORT是-1, 则随机选取WEB端口
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
from check_proxy import get_current_version from check_proxy import get_current_version
from themes.theme import adjust_theme, advanced_css, theme_declaration, load_dynamic_theme from themes.theme import adjust_theme, advanced_css, theme_declaration, load_dynamic_theme
initial_prompt = "Serve me as a writing and programming assistant."
title_html = f"<h1 align=\"center\">GPT 学术优化 {get_current_version()}</h1>{theme_declaration}" title_html = f"<h1 align=\"center\">GPT 学术优化 {get_current_version()}</h1>{theme_declaration}"
description = "代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic)" description = "Github源代码开源和更新[地址🚀](https://github.com/binary-husky/gpt_academic), "
description += "感谢热情的[开发者们❤️](https://github.com/binary-husky/gpt_academic/graphs/contributors)" description += "感谢热情的[开发者们❤️](https://github.com/binary-husky/gpt_academic/graphs/contributors)."
description += "</br></br>常见问题请查阅[项目Wiki](https://github.com/binary-husky/gpt_academic/wiki), "
description += "如遇到Bug请前往[Bug反馈](https://github.com/binary-husky/gpt_academic/issues)."
description += "</br></br>普通对话使用说明: 1. 输入问题; 2. 点击提交"
description += "</br></br>基础功能区使用说明: 1. 输入文本; 2. 点击任意基础功能区按钮"
description += "</br></br>函数插件区使用说明: 1. 输入路径/问题, 或者上传文件; 2. 点击任意函数插件区按钮"
description += "</br></br>虚空终端使用说明: 点击虚空终端, 然后根据提示输入指令, 再次点击虚空终端"
description += "</br></br>如何保存对话: 点击保存当前的对话按钮"
description += "</br></br>如何语音对话: 请阅读Wiki"
# 问询记录, python 版本建议3.9+(越新越好) # 问询记录, python 版本建议3.9+(越新越好)
import logging, uuid import logging, uuid
@@ -35,7 +47,7 @@ def main():
# 高级函数插件 # 高级函数插件
from crazy_functional import get_crazy_functions from crazy_functional import get_crazy_functions
DEFAULT_FN_GROUPS, = get_conf('DEFAULT_FN_GROUPS') DEFAULT_FN_GROUPS = get_conf('DEFAULT_FN_GROUPS')
plugins = get_crazy_functions() plugins = get_crazy_functions()
all_plugin_groups = list(set([g for _, plugin in plugins.items() for g in plugin['Group'].split('|')])) 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('|')]) match_group = lambda tags, groups: any([g in groups for g in tags.split('|')])
@@ -58,9 +70,11 @@ def main():
CHATBOT_HEIGHT /= 2 CHATBOT_HEIGHT /= 2
cancel_handles = [] cancel_handles = []
customize_btns = {}
predefined_btns = {}
with gr.Blocks(title="GPT 学术优化", theme=set_theme, analytics_enabled=False, css=advanced_css) as demo: with gr.Blocks(title="GPT 学术优化", theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
gr.HTML(title_html) gr.HTML(title_html)
secret_css, secret_font = gr.Textbox(visible=False), gr.Textbox(visible=False) secret_css, dark_mode, persistent_cookie = gr.Textbox(visible=False), gr.Textbox(DARK_MODE, visible=False), gr.Textbox(visible=False)
cookies = gr.State(load_chat_cookies()) cookies = gr.State(load_chat_cookies())
with gr_L1(): with gr_L1():
with gr_L2(scale=2, elem_id="gpt-chat"): with gr_L2(scale=2, elem_id="gpt-chat"):
@@ -72,23 +86,28 @@ def main():
with gr.Row(): with gr.Row():
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False) txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
with gr.Row(): with gr.Row():
submitBtn = gr.Button("提交", variant="primary") submitBtn = gr.Button("提交", elem_id="elem_submit", variant="primary")
with gr.Row(): with gr.Row():
resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm") resetBtn = gr.Button("重置", elem_id="elem_reset", variant="secondary"); resetBtn.style(size="sm")
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm") stopBtn = gr.Button("停止", elem_id="elem_stop", variant="secondary"); stopBtn.style(size="sm")
clearBtn = gr.Button("清除", variant="secondary", visible=False); clearBtn.style(size="sm") clearBtn = gr.Button("清除", elem_id="elem_clear", variant="secondary", visible=False); clearBtn.style(size="sm")
if ENABLE_AUDIO: if ENABLE_AUDIO:
with gr.Row(): with gr.Row():
audio_mic = gr.Audio(source="microphone", type="numpy", streaming=True, show_label=False).style(container=False) audio_mic = gr.Audio(source="microphone", type="numpy", elem_id="elem_audio", streaming=True, show_label=False).style(container=False)
with gr.Row(): with gr.Row():
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}", elem_id="state-panel") status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}", elem_id="state-panel")
with gr.Accordion("基础功能区", open=True, elem_id="basic-panel") as area_basic_fn: with gr.Accordion("基础功能区", open=True, elem_id="basic-panel") as area_basic_fn:
with gr.Row(): with gr.Row():
for k in range(NUM_CUSTOM_BASIC_BTN):
customize_btn = gr.Button("自定义按钮" + str(k+1), visible=False, variant="secondary", info_str=f'基础功能区: 自定义按钮')
customize_btn.style(size="sm")
customize_btns.update({"自定义按钮" + str(k+1): customize_btn})
for k in functional: for k in functional:
if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary" variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
functional[k]["Button"] = gr.Button(k, variant=variant) functional[k]["Button"] = gr.Button(k, variant=variant, info_str=f'基础功能区: {k}')
functional[k]["Button"].style(size="sm") functional[k]["Button"].style(size="sm")
predefined_btns.update({k: functional[k]["Button"]})
with gr.Accordion("函数插件区", open=True, elem_id="plugin-panel") as area_crazy_fn: with gr.Accordion("函数插件区", open=True, elem_id="plugin-panel") as area_crazy_fn:
with gr.Row(): with gr.Row():
gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)") gr.Markdown("插件可读取“输入区”文本/路径作为参数(上传文件自动修正路径)")
@@ -100,7 +119,9 @@ def main():
if not plugin.get("AsButton", True): continue if not plugin.get("AsButton", True): continue
visible = True if match_group(plugin['Group'], DEFAULT_FN_GROUPS) else False visible = True if match_group(plugin['Group'], DEFAULT_FN_GROUPS) else False
variant = plugins[k]["Color"] if "Color" in plugin else "secondary" 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") info = plugins[k].get("Info", k)
plugin['Button'] = plugins[k]['Button'] = gr.Button(k, variant=variant,
visible=visible, info_str=f'函数插件区: {info}').style(size="sm")
with gr.Row(): with gr.Row():
with gr.Accordion("更多函数插件", open=True): with gr.Accordion("更多函数插件", open=True):
dropdown_fn_list = [] dropdown_fn_list = []
@@ -117,15 +138,28 @@ def main():
switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary").style(size="sm") switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary").style(size="sm")
with gr.Row(): with gr.Row():
with gr.Accordion("点击展开“文件上传区”。上传本地文件/压缩包供函数插件调用。", open=False) as area_file_up: with gr.Accordion("点击展开“文件上传区”。上传本地文件/压缩包供函数插件调用。", open=False) as area_file_up:
file_upload = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple") file_upload = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple", elem_id="elem_upload")
with gr.Accordion("更换模型 & SysPrompt & 交互界面布局", open=(LAYOUT == "TOP-DOWN"), elem_id="interact-panel"):
system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
with gr.Floating(init_x="0%", init_y="0%", visible=True, width=None, drag="forbidden"):
with gr.Row():
with gr.Tab("上传文件", elem_id="interact-panel"):
gr.Markdown("请上传本地文件/压缩包供“函数插件区”功能调用。请注意: 上传文件后会自动把输入区修改为相应路径。")
file_upload_2 = gr.Files(label="任何文件, 推荐上传压缩文件(zip, tar)", file_count="multiple")
with gr.Tab("更换模型 & Prompt", elem_id="interact-panel"):
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",) top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",) temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",) max_length_sl = gr.Slider(minimum=256, maximum=1024*32, value=4096, step=128, interactive=True, label="Local LLM MaxLength",)
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区") system_prompt = gr.Textbox(show_label=True, lines=2, placeholder=f"System Prompt", label="System prompt", value=INIT_SYS_PROMPT)
md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
with gr.Tab("界面外观", elem_id="interact-panel"):
theme_dropdown = gr.Dropdown(AVAIL_THEMES, value=THEME, label="更换UI主题").style(container=False) theme_dropdown = gr.Dropdown(AVAIL_THEMES, value=THEME, label="更换UI主题").style(container=False)
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "浮动输入区", "输入清除键", "插件参数区"],
value=["基础功能区", "函数插件区"], label="显示/隐藏功能区", elem_id='cbs').style(container=False)
checkboxes_2 = gr.CheckboxGroup(["自定义菜单"],
value=[], label="显示/隐藏自定义菜单", elem_id='cbs').style(container=False)
dark_mode_btn = gr.Button("切换界面明暗 ☀", variant="secondary").style(size="sm") dark_mode_btn = gr.Button("切换界面明暗 ☀", variant="secondary").style(size="sm")
dark_mode_btn.click(None, None, None, _js="""() => { dark_mode_btn.click(None, None, None, _js="""() => {
if (document.querySelectorAll('.dark').length) { if (document.querySelectorAll('.dark').length) {
@@ -135,30 +169,113 @@ def main():
} }
}""", }""",
) )
with gr.Tab("帮助", elem_id="interact-panel"):
gr.Markdown(description) gr.Markdown(description)
with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") as area_input_secondary:
with gr.Row(): with gr.Floating(init_x="20%", init_y="50%", visible=False, width="40%", drag="top") as area_input_secondary:
txt2 = gr.Textbox(show_label=False, placeholder="Input question here.", label="输入区2").style(container=False) with gr.Accordion("浮动输入区", open=True, elem_id="input-panel2"):
with gr.Row(): with gr.Row() as row:
submitBtn2 = gr.Button("提交", variant="primary") row.style(equal_height=True)
with gr.Row(): with gr.Column(scale=10):
txt2 = gr.Textbox(show_label=False, placeholder="Input question here.", lines=8, label="输入区2").style(container=False)
with gr.Column(scale=1, min_width=40):
submitBtn2 = gr.Button("提交", variant="primary"); submitBtn2.style(size="sm")
resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn2.style(size="sm") resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn2.style(size="sm")
stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn2.style(size="sm") stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn2.style(size="sm")
clearBtn2 = gr.Button("清除", variant="secondary", visible=False); clearBtn2.style(size="sm") clearBtn2 = gr.Button("清除", variant="secondary", visible=False); clearBtn2.style(size="sm")
def to_cookie_str(d):
# Pickle the dictionary and encode it as a string
pickled_dict = pickle.dumps(d)
cookie_value = base64.b64encode(pickled_dict).decode('utf-8')
return cookie_value
def from_cookie_str(c):
# Decode the base64-encoded string and unpickle it into a dictionary
pickled_dict = base64.b64decode(c.encode('utf-8'))
return pickle.loads(pickled_dict)
with gr.Floating(init_x="20%", init_y="50%", visible=False, width="40%", drag="top") as area_customize:
with gr.Accordion("自定义菜单", open=True, elem_id="edit-panel"):
with gr.Row() as row:
with gr.Column(scale=10):
AVAIL_BTN = [btn for btn in customize_btns.keys()] + [k for k in functional]
basic_btn_dropdown = gr.Dropdown(AVAIL_BTN, value="自定义按钮1", label="选择一个需要自定义基础功能区按钮").style(container=False)
basic_fn_title = gr.Textbox(show_label=False, placeholder="输入新按钮名称", lines=1).style(container=False)
basic_fn_prefix = gr.Textbox(show_label=False, placeholder="输入新提示前缀", lines=4).style(container=False)
basic_fn_suffix = gr.Textbox(show_label=False, placeholder="输入新提示后缀", lines=4).style(container=False)
with gr.Column(scale=1, min_width=70):
basic_fn_confirm = gr.Button("确认并保存", variant="primary"); basic_fn_confirm.style(size="sm")
basic_fn_load = gr.Button("加载已保存", variant="primary"); basic_fn_load.style(size="sm")
def assign_btn(persistent_cookie_, cookies_, basic_btn_dropdown_, basic_fn_title, basic_fn_prefix, basic_fn_suffix):
ret = {}
customize_fn_overwrite_ = cookies_['customize_fn_overwrite']
customize_fn_overwrite_.update({
basic_btn_dropdown_:
{
"Title":basic_fn_title,
"Prefix":basic_fn_prefix,
"Suffix":basic_fn_suffix,
}
}
)
cookies_.update(customize_fn_overwrite_)
if basic_btn_dropdown_ in customize_btns:
ret.update({customize_btns[basic_btn_dropdown_]: gr.update(visible=True, value=basic_fn_title)})
else:
ret.update({predefined_btns[basic_btn_dropdown_]: gr.update(visible=True, value=basic_fn_title)})
ret.update({cookies: cookies_})
try: persistent_cookie_ = from_cookie_str(persistent_cookie_) # persistent cookie to dict
except: persistent_cookie_ = {}
persistent_cookie_["custom_bnt"] = customize_fn_overwrite_ # dict update new value
persistent_cookie_ = to_cookie_str(persistent_cookie_) # persistent cookie to dict
ret.update({persistent_cookie: persistent_cookie_}) # write persistent cookie
return ret
def reflesh_btn(persistent_cookie_, cookies_):
ret = {}
for k in customize_btns:
ret.update({customize_btns[k]: gr.update(visible=False, value="")})
try: persistent_cookie_ = from_cookie_str(persistent_cookie_) # persistent cookie to dict
except: return ret
customize_fn_overwrite_ = persistent_cookie_.get("custom_bnt", {})
cookies_['customize_fn_overwrite'] = customize_fn_overwrite_
ret.update({cookies: cookies_})
for k,v in persistent_cookie_["custom_bnt"].items():
if v['Title'] == "": continue
if k in customize_btns: ret.update({customize_btns[k]: gr.update(visible=True, value=v['Title'])})
else: ret.update({predefined_btns[k]: gr.update(visible=True, value=v['Title'])})
return ret
basic_fn_load.click(reflesh_btn, [persistent_cookie, cookies],[cookies, *customize_btns.values(), *predefined_btns.values()])
h = basic_fn_confirm.click(assign_btn, [persistent_cookie, cookies, basic_btn_dropdown, basic_fn_title, basic_fn_prefix, basic_fn_suffix],
[persistent_cookie, cookies, *customize_btns.values(), *predefined_btns.values()])
h.then(None, [persistent_cookie], None, _js="""(persistent_cookie)=>{setCookie("persistent_cookie", persistent_cookie, 5);}""") # save persistent cookie
# 功能区显示开关与功能区的互动 # 功能区显示开关与功能区的互动
def fn_area_visibility(a): def fn_area_visibility(a):
ret = {} ret = {}
ret.update({area_basic_fn: gr.update(visible=("基础功能区" in a))}) ret.update({area_basic_fn: gr.update(visible=("基础功能区" in a))})
ret.update({area_crazy_fn: gr.update(visible=("函数插件区" in a))}) ret.update({area_crazy_fn: gr.update(visible=("函数插件区" in a))})
ret.update({area_input_primary: gr.update(visible=("底部输入区" not in a))}) ret.update({area_input_primary: gr.update(visible=("浮动输入区" not in a))})
ret.update({area_input_secondary: gr.update(visible=("底部输入区" in a))}) ret.update({area_input_secondary: gr.update(visible=("浮动输入区" in a))})
ret.update({clearBtn: gr.update(visible=("输入清除键" in a))}) ret.update({clearBtn: gr.update(visible=("输入清除键" in a))})
ret.update({clearBtn2: gr.update(visible=("输入清除键" in a))}) ret.update({clearBtn2: gr.update(visible=("输入清除键" in a))})
ret.update({plugin_advanced_arg: gr.update(visible=("插件参数区" in a))}) ret.update({plugin_advanced_arg: gr.update(visible=("插件参数区" in a))})
if "底部输入区" in a: ret.update({txt: gr.update(value="")}) if "浮动输入区" in a: ret.update({txt: gr.update(value="")})
return ret return ret
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2, plugin_advanced_arg] ) checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2, plugin_advanced_arg] )
# 功能区显示开关与功能区的互动
def fn_area_visibility_2(a):
ret = {}
ret.update({area_customize: gr.update(visible=("自定义菜单" in a))})
return ret
checkboxes_2.select(fn_area_visibility_2, [checkboxes_2], [area_customize] )
# 整理反复出现的控件句柄组合 # 整理反复出现的控件句柄组合
input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg] input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg]
output_combo = [cookies, chatbot, history, status] output_combo = [cookies, chatbot, history, status]
@@ -182,8 +299,12 @@ def main():
if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(k)], outputs=output_combo) 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) cancel_handles.append(click_handle)
for btn in customize_btns.values():
click_handle = btn.click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(btn.value)], outputs=output_combo)
cancel_handles.append(click_handle)
# 文件上传区接收文件后与chatbot的互动 # 文件上传区接收文件后与chatbot的互动
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies]) file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies])
file_upload_2.upload(on_file_uploaded, [file_upload_2, chatbot, txt, txt2, checkboxes, cookies], [chatbot, txt, txt2, cookies])
# 函数插件-固定按钮区 # 函数插件-固定按钮区
for k in plugins: for k in plugins:
if not plugins[k].get("AsButton", True): continue if not plugins[k].get("AsButton", True): continue
@@ -193,7 +314,8 @@ def main():
# 函数插件-下拉菜单与随变按钮的互动 # 函数插件-下拉菜单与随变按钮的互动
def on_dropdown_changed(k): def on_dropdown_changed(k):
variant = plugins[k]["Color"] if "Color" in plugins[k] else "secondary" variant = plugins[k]["Color"] if "Color" in plugins[k] else "secondary"
ret = {switchy_bt: gr.update(value=k, variant=variant)} info = plugins[k].get("Info", k)
ret = {switchy_bt: gr.update(value=k, variant=variant, info_str=f'函数插件区: {info}')}
if plugins[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区 if plugins[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区
ret.update({plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + plugins[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))}) ret.update({plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + plugins[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))})
else: else:
@@ -266,40 +388,60 @@ def main():
cookies.update({'uuid': uuid.uuid4()}) cookies.update({'uuid': uuid.uuid4()})
return cookies return cookies
demo.load(init_cookie, inputs=[cookies, chatbot], outputs=[cookies]) demo.load(init_cookie, inputs=[cookies, chatbot], outputs=[cookies])
demo.load(lambda: 0, inputs=None, outputs=None, _js='()=>{GptAcademicJavaScriptInit();}') darkmode_js = """(dark) => {
dark = dark == "True";
if (document.querySelectorAll('.dark').length) {
if (!dark){
document.querySelectorAll('.dark').forEach(el => el.classList.remove('dark'));
}
} else {
if (dark){
document.querySelector('body').classList.add('dark');
}
}
}"""
load_cookie_js = """(persistent_cookie) => {
return getCookie("persistent_cookie");
}"""
demo.load(None, inputs=None, outputs=[persistent_cookie], _js=load_cookie_js)
demo.load(None, inputs=[dark_mode], outputs=None, _js=darkmode_js) # 配置暗色主题或亮色主题
demo.load(None, inputs=[gr.Textbox(LAYOUT, visible=False)], outputs=None, _js='(LAYOUT)=>{GptAcademicJavaScriptInit(LAYOUT);}')
# gradio的inbrowser触发不太稳定回滚代码到原始的浏览器打开函数 # gradio的inbrowser触发不太稳定回滚代码到原始的浏览器打开函数
def auto_opentab_delay(): def run_delayed_tasks():
import threading, webbrowser, time import threading, webbrowser, time
print(f"如果浏览器没有自动打开请复制并转到以下URL") print(f"如果浏览器没有自动打开请复制并转到以下URL")
print(f"\t(亮色主题): http://localhost:{PORT}") if DARK_MODE: print(f"\t「暗色主题已启用(支持动态切换主题): http://localhost:{PORT}")
print(f"\t(暗色主题): http://localhost:{PORT}/?__theme=dark") else: print(f"\t「亮色主题已启用(支持动态切换主题): http://localhost:{PORT}")
def open():
time.sleep(2) # 打开浏览器
DARK_MODE, = get_conf('DARK_MODE')
if DARK_MODE: webbrowser.open_new_tab(f"http://localhost:{PORT}/?__theme=dark")
else: webbrowser.open_new_tab(f"http://localhost:{PORT}")
threading.Thread(target=open, name="open-browser", daemon=True).start()
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
auto_opentab_delay() def auto_updates(): time.sleep(0); auto_update()
def open_browser(): time.sleep(2); webbrowser.open_new_tab(f"http://localhost:{PORT}")
def warm_up_mods(): time.sleep(4); warm_up_modules()
threading.Thread(target=auto_updates, name="self-upgrade", daemon=True).start() # 查看自动更新
threading.Thread(target=open_browser, name="open-browser", daemon=True).start() # 打开浏览器页面
threading.Thread(target=warm_up_mods, name="warm-up", daemon=True).start() # 预热tiktoken模块
run_delayed_tasks()
demo.queue(concurrency_count=CONCURRENT_COUNT).launch( demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
quiet=True, quiet=True,
server_name="0.0.0.0", server_name="0.0.0.0",
ssl_keyfile=None if SSL_KEYFILE == "" else SSL_KEYFILE,
ssl_certfile=None if SSL_CERTFILE == "" else SSL_CERTFILE,
ssl_verify=False,
server_port=PORT, server_port=PORT,
favicon_path="docs/logo.png", favicon_path=os.path.join(os.path.dirname(__file__), "docs/logo.png"),
auth=AUTHENTICATION if len(AUTHENTICATION) != 0 else None, auth=AUTHENTICATION if len(AUTHENTICATION) != 0 else None,
blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile"]) blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile",f"{PATH_LOGGING}/admin"])
# 如果需要在二级路径下运行 # 如果需要在二级路径下运行
# CUSTOM_PATH, = get_conf('CUSTOM_PATH') # CUSTOM_PATH = get_conf('CUSTOM_PATH')
# if CUSTOM_PATH != "/": # if CUSTOM_PATH != "/":
# from toolbox import run_gradio_in_subpath # from toolbox import run_gradio_in_subpath
# run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH) # run_gradio_in_subpath(demo, auth=AUTHENTICATION, port=PORT, custom_path=CUSTOM_PATH)
# else: # else:
# demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png", # demo.launch(server_name="0.0.0.0", server_port=PORT, auth=AUTHENTICATION, favicon_path="docs/logo.png",
# blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile"]) # blocked_paths=["config.py","config_private.py","docker-compose.yml","Dockerfile",f"{PATH_LOGGING}/admin"])
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -13,6 +13,7 @@
4. Run `python multi_language.py`. 4. Run `python multi_language.py`.
Note: You need to run it multiple times to increase translation coverage because GPT makes mistakes sometimes. Note: You need to run it multiple times to increase translation coverage because GPT makes mistakes sometimes.
(You can also run `CACHE_ONLY=True python multi_language.py` to use cached translation mapping)
5. Find the translated program in `multi-language\English\*` 5. Find the translated program in `multi-language\English\*`
@@ -35,7 +36,9 @@ import pickle
import time import time
from toolbox import get_conf from toolbox import get_conf
CACHE_FOLDER, = get_conf('PATH_LOGGING') CACHE_ONLY = os.environ.get('CACHE_ONLY', False)
CACHE_FOLDER = get_conf('PATH_LOGGING')
blacklist = ['multi-language', CACHE_FOLDER, '.git', 'private_upload', 'multi_language.py', 'build', '.github', '.vscode', '__pycache__', 'venv'] blacklist = ['multi-language', CACHE_FOLDER, '.git', 'private_upload', 'multi_language.py', 'build', '.github', '.vscode', '__pycache__', 'venv']
@@ -336,6 +339,9 @@ def step_1_core_key_translate():
if d not in cached_translation_keys: if d not in cached_translation_keys:
need_translate.append(d) need_translate.append(d)
if CACHE_ONLY:
need_translate_mapping = {}
else:
need_translate_mapping = trans(need_translate, language=LANG_STD, special=True) need_translate_mapping = trans(need_translate, language=LANG_STD, special=True)
map_to_json(need_translate_mapping, language=LANG_STD) map_to_json(need_translate_mapping, language=LANG_STD)
cached_translation = read_map_from_json(language=LANG_STD) cached_translation = read_map_from_json(language=LANG_STD)
@@ -476,7 +482,9 @@ def step_2_core_key_translate():
if d not in cached_translation_keys: if d not in cached_translation_keys:
need_translate.append(d) need_translate.append(d)
if CACHE_ONLY:
up = {}
else:
up = trans_json(need_translate, language=LANG, special=False) up = trans_json(need_translate, language=LANG, special=False)
map_to_json(up, language=LANG) map_to_json(up, language=LANG)
cached_translation = read_map_from_json(language=LANG) cached_translation = read_map_from_json(language=LANG)

View File

@@ -1,167 +0,0 @@
from transformers import AutoModel, AutoTokenizer
import time
import threading
import importlib
from toolbox import update_ui, get_conf, ProxyNetworkActivate
from multiprocessing import Process, Pipe
load_message = "ChatGLM尚未加载加载需要一段时间。注意取决于`config.py`的配置ChatGLM消耗大量的内存CPU或显存GPU也许会导致低配计算机卡死 ……"
#################################################################################
class GetGLMHandle(Process):
def __init__(self):
super().__init__(daemon=True)
self.parent, self.child = Pipe()
self.chatglm_model = None
self.chatglm_tokenizer = None
self.info = ""
self.success = True
self.check_dependency()
self.start()
self.threadLock = threading.Lock()
def check_dependency(self):
try:
import sentencepiece
self.info = "依赖检测通过"
self.success = True
except:
self.info = "缺少ChatGLM的依赖如果要使用ChatGLM除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_chatglm.txt`安装ChatGLM的依赖。"
self.success = False
def ready(self):
return self.chatglm_model is not None
def run(self):
# 子进程执行
# 第一次运行,加载参数
retry = 0
LOCAL_MODEL_QUANT, device = get_conf('LOCAL_MODEL_QUANT', 'LOCAL_MODEL_DEVICE')
if LOCAL_MODEL_QUANT == "INT4": # INT4
_model_name_ = "THUDM/chatglm2-6b-int4"
elif LOCAL_MODEL_QUANT == "INT8": # INT8
_model_name_ = "THUDM/chatglm2-6b-int8"
else:
_model_name_ = "THUDM/chatglm2-6b" # FP16
while True:
try:
with ProxyNetworkActivate('Download_LLM'):
if self.chatglm_model is None:
self.chatglm_tokenizer = AutoTokenizer.from_pretrained(_model_name_, trust_remote_code=True)
if device=='cpu':
self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).float()
else:
self.chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).half().cuda()
self.chatglm_model = self.chatglm_model.eval()
break
else:
break
except:
retry += 1
if retry > 3:
self.child.send('[Local Message] Call ChatGLM fail 不能正常加载ChatGLM的参数。')
raise RuntimeError("不能正常加载ChatGLM的参数")
while True:
# 进入任务等待状态
kwargs = self.child.recv()
# 收到消息,开始请求
try:
for response, history in self.chatglm_model.stream_chat(self.chatglm_tokenizer, **kwargs):
self.child.send(response)
# # 中途接收可能的终止指令(如果有的话)
# if self.child.poll():
# command = self.child.recv()
# if command == '[Terminate]': break
except:
from toolbox import trimmed_format_exc
self.child.send('[Local Message] Call ChatGLM fail.' + '\n```\n' + trimmed_format_exc() + '\n```\n')
# 请求处理结束,开始下一个循环
self.child.send('[Finish]')
def stream_chat(self, **kwargs):
# 主进程执行
self.threadLock.acquire()
self.parent.send(kwargs)
while True:
res = self.parent.recv()
if res != '[Finish]':
yield res
else:
break
self.threadLock.release()
global glm_handle
glm_handle = None
#################################################################################
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
"""
多线程方法
函数的说明请见 request_llm/bridge_all.py
"""
global glm_handle
if glm_handle is None:
glm_handle = GetGLMHandle()
if len(observe_window) >= 1: observe_window[0] = load_message + "\n\n" + glm_handle.info
if not glm_handle.success:
error = glm_handle.info
glm_handle = None
raise RuntimeError(error)
# chatglm 没有 sys_prompt 接口因此把prompt加入 history
history_feedin = []
history_feedin.append(["What can I do?", sys_prompt])
for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]] )
watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
response = ""
for response in glm_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
if len(observe_window) >= 1: observe_window[0] = response
if len(observe_window) >= 2:
if (time.time()-observe_window[1]) > watch_dog_patience:
raise RuntimeError("程序终止。")
return response
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
"""
单线程方法
函数的说明请见 request_llm/bridge_all.py
"""
chatbot.append((inputs, ""))
global glm_handle
if glm_handle is None:
glm_handle = GetGLMHandle()
chatbot[-1] = (inputs, load_message + "\n\n" + glm_handle.info)
yield from update_ui(chatbot=chatbot, history=[])
if not glm_handle.success:
glm_handle = None
return
if additional_fn is not None:
from core_functional import handle_core_functionality
inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot)
# 处理历史信息
history_feedin = []
history_feedin.append(["What can I do?", system_prompt] )
for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收chatglm的回复
response = "[Local Message]: 等待ChatGLM响应中 ..."
for response in glm_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history)
# 总结输出
if response == "[Local Message]: 等待ChatGLM响应中 ...":
response = "[Local Message]: ChatGLM响应异常 ..."
history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -1,180 +0,0 @@
from transformers import AutoModel, AutoTokenizer
import time
import threading
import importlib
from toolbox import update_ui, get_conf, Singleton
from multiprocessing import Process, Pipe
def SingletonLocalLLM(cls):
"""
一个单实例装饰器
"""
_instance = {}
def _singleton(*args, **kargs):
if cls not in _instance:
_instance[cls] = cls(*args, **kargs)
return _instance[cls]
elif _instance[cls].corrupted:
_instance[cls] = cls(*args, **kargs)
return _instance[cls]
else:
return _instance[cls]
return _singleton
class LocalLLMHandle(Process):
def __init__(self):
# ⭐主进程执行
super().__init__(daemon=True)
self.corrupted = False
self.load_model_info()
self.parent, self.child = Pipe()
self.running = True
self._model = None
self._tokenizer = None
self.info = ""
self.check_dependency()
self.start()
self.threadLock = threading.Lock()
def load_model_info(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
raise NotImplementedError("Method not implemented yet")
self.model_name = ""
self.cmd_to_install = ""
def load_model_and_tokenizer(self):
"""
This function should return the model and the tokenizer
"""
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
raise NotImplementedError("Method not implemented yet")
def llm_stream_generator(self, **kwargs):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
raise NotImplementedError("Method not implemented yet")
def try_to_import_special_deps(self, **kwargs):
"""
import something that will raise error if the user does not install requirement_*.txt
"""
# ⭐主进程执行
raise NotImplementedError("Method not implemented yet")
def check_dependency(self):
# ⭐主进程执行
try:
self.try_to_import_special_deps()
self.info = "依赖检测通过"
self.running = True
except:
self.info = f"缺少{self.model_name}的依赖,如果要使用{self.model_name}除了基础的pip依赖以外您还需要运行{self.cmd_to_install}安装{self.model_name}的依赖。"
self.running = False
def run(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
# 第一次运行,加载参数
try:
self._model, self._tokenizer = self.load_model_and_tokenizer()
except:
self.running = False
from toolbox import trimmed_format_exc
self.child.send(f'[Local Message] 不能正常加载{self.model_name}的参数.' + '\n```\n' + trimmed_format_exc() + '\n```\n')
self.child.send('[FinishBad]')
raise RuntimeError(f"不能正常加载{self.model_name}的参数!")
while True:
# 进入任务等待状态
kwargs = self.child.recv()
# 收到消息,开始请求
try:
for response_full in self.llm_stream_generator(**kwargs):
self.child.send(response_full)
self.child.send('[Finish]')
# 请求处理结束,开始下一个循环
except:
from toolbox import trimmed_format_exc
self.child.send(f'[Local Message] 调用{self.model_name}失败.' + '\n```\n' + trimmed_format_exc() + '\n```\n')
self.child.send('[Finish]')
def stream_chat(self, **kwargs):
# ⭐主进程执行
self.threadLock.acquire()
self.parent.send(kwargs)
while True:
res = self.parent.recv()
if res == '[Finish]':
break
if res == '[FinishBad]':
self.running = False
self.corrupted = True
break
else:
yield res
self.threadLock.release()
def get_local_llm_predict_fns(LLMSingletonClass, model_name):
load_message = f"{model_name}尚未加载,加载需要一段时间。注意,取决于`config.py`的配置,{model_name}消耗大量的内存CPU或显存GPU也许会导致低配计算机卡死 ……"
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
"""
⭐多线程方法
函数的说明请见 request_llm/bridge_all.py
"""
_llm_handle = LLMSingletonClass()
if len(observe_window) >= 1: observe_window[0] = load_message + "\n\n" + _llm_handle.info
if not _llm_handle.running: raise RuntimeError(_llm_handle.info)
# chatglm 没有 sys_prompt 接口因此把prompt加入 history
history_feedin = []
history_feedin.append([sys_prompt, "Certainly!"])
for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]] )
watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
response = ""
for response in _llm_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
if len(observe_window) >= 1:
observe_window[0] = response
if len(observe_window) >= 2:
if (time.time()-observe_window[1]) > watch_dog_patience: raise RuntimeError("程序终止。")
return response
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
"""
⭐单线程方法
函数的说明请见 request_llm/bridge_all.py
"""
chatbot.append((inputs, ""))
_llm_handle = LLMSingletonClass()
chatbot[-1] = (inputs, load_message + "\n\n" + _llm_handle.info)
yield from update_ui(chatbot=chatbot, history=[])
if not _llm_handle.running: raise RuntimeError(_llm_handle.info)
if additional_fn is not None:
from core_functional import handle_core_functionality
inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot)
# 处理历史信息
history_feedin = []
history_feedin.append([system_prompt, "Certainly!"])
for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收回复
response = f"[Local Message]: 等待{model_name}响应中 ..."
for response in _llm_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history)
# 总结输出
if response == f"[Local Message]: 等待{model_name}响应中 ...":
response = f"[Local Message]: {model_name}响应异常 ..."
history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history)
return predict_no_ui_long_connection, predict

View File

@@ -2,7 +2,7 @@
## ChatGLM ## ChatGLM
- 安装依赖 `pip install -r request_llm/requirements_chatglm.txt` - 安装依赖 `pip install -r request_llms/requirements_chatglm.txt`
- 修改配置在config.py中将LLM_MODEL的值改为"chatglm" - 修改配置在config.py中将LLM_MODEL的值改为"chatglm"
``` sh ``` sh

View File

@@ -19,8 +19,8 @@ from .bridge_chatgpt import predict as chatgpt_ui
from .bridge_chatglm import predict_no_ui_long_connection as chatglm_noui from .bridge_chatglm import predict_no_ui_long_connection as chatglm_noui
from .bridge_chatglm import predict as chatglm_ui from .bridge_chatglm import predict as chatglm_ui
from .bridge_chatglm import predict_no_ui_long_connection as chatglm_noui from .bridge_chatglm3 import predict_no_ui_long_connection as chatglm3_noui
from .bridge_chatglm import predict as chatglm_ui from .bridge_chatglm3 import predict as chatglm3_ui
from .bridge_qianfan import predict_no_ui_long_connection as qianfan_noui from .bridge_qianfan import predict_no_ui_long_connection as qianfan_noui
from .bridge_qianfan import predict as qianfan_ui from .bridge_qianfan import predict as qianfan_ui
@@ -56,7 +56,7 @@ if not AZURE_ENDPOINT.endswith('/'): AZURE_ENDPOINT += '/'
azure_endpoint = AZURE_ENDPOINT + f'openai/deployments/{AZURE_ENGINE}/chat/completions?api-version=2023-05-15' azure_endpoint = AZURE_ENDPOINT + f'openai/deployments/{AZURE_ENGINE}/chat/completions?api-version=2023-05-15'
# 兼容旧版的配置 # 兼容旧版的配置
try: try:
API_URL, = get_conf("API_URL") API_URL = get_conf("API_URL")
if API_URL != "https://api.openai.com/v1/chat/completions": if API_URL != "https://api.openai.com/v1/chat/completions":
openai_endpoint = API_URL openai_endpoint = API_URL
print("警告API_URL配置选项将被弃用请更换为API_URL_REDIRECT配置") print("警告API_URL配置选项将被弃用请更换为API_URL_REDIRECT配置")
@@ -94,7 +94,7 @@ model_info = {
"fn_with_ui": chatgpt_ui, "fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui, "fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint, "endpoint": openai_endpoint,
"max_token": 1024*16, "max_token": 16385,
"tokenizer": tokenizer_gpt35, "tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35, "token_cnt": get_token_num_gpt35,
}, },
@@ -112,7 +112,16 @@ model_info = {
"fn_with_ui": chatgpt_ui, "fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui, "fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint, "endpoint": openai_endpoint,
"max_token": 1024 * 16, "max_token": 16385,
"tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35,
},
"gpt-3.5-turbo-1106": {#16k
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint,
"max_token": 16385,
"tokenizer": tokenizer_gpt35, "tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35, "token_cnt": get_token_num_gpt35,
}, },
@@ -135,6 +144,24 @@ model_info = {
"token_cnt": get_token_num_gpt4, "token_cnt": get_token_num_gpt4,
}, },
"gpt-4-1106-preview": {
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint,
"max_token": 128000,
"tokenizer": tokenizer_gpt4,
"token_cnt": get_token_num_gpt4,
},
"gpt-3.5-random": {
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint,
"max_token": 4096,
"tokenizer": tokenizer_gpt4,
"token_cnt": get_token_num_gpt4,
},
# azure openai # azure openai
"azure-gpt-3.5":{ "azure-gpt-3.5":{
"fn_with_ui": chatgpt_ui, "fn_with_ui": chatgpt_ui,
@@ -150,11 +177,11 @@ model_info = {
"fn_without_ui": chatgpt_noui, "fn_without_ui": chatgpt_noui,
"endpoint": azure_endpoint, "endpoint": azure_endpoint,
"max_token": 8192, "max_token": 8192,
"tokenizer": tokenizer_gpt35, "tokenizer": tokenizer_gpt4,
"token_cnt": get_token_num_gpt35, "token_cnt": get_token_num_gpt4,
}, },
# api_2d # api_2d (此后不需要在此处添加api2d的接口了因为下面的代码会自动添加)
"api2d-gpt-3.5-turbo": { "api2d-gpt-3.5-turbo": {
"fn_with_ui": chatgpt_ui, "fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui, "fn_without_ui": chatgpt_noui,
@@ -190,6 +217,14 @@ model_info = {
"tokenizer": tokenizer_gpt35, "tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35, "token_cnt": get_token_num_gpt35,
}, },
"chatglm3": {
"fn_with_ui": chatglm3_ui,
"fn_without_ui": chatglm3_noui,
"endpoint": None,
"max_token": 8192,
"tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35,
},
"qianfan": { "qianfan": {
"fn_with_ui": qianfan_ui, "fn_with_ui": qianfan_ui,
"fn_without_ui": qianfan_noui, "fn_without_ui": qianfan_noui,
@@ -200,6 +235,20 @@ model_info = {
}, },
} }
# -=-=-=-=-=-=- api2d 对齐支持 -=-=-=-=-=-=-
for model in AVAIL_LLM_MODELS:
if model.startswith('api2d-') and (model.replace('api2d-','') in model_info.keys()):
mi = model_info[model.replace('api2d-','')]
mi.update({"endpoint": api2d_endpoint})
model_info.update({model: mi})
# -=-=-=-=-=-=- azure 对齐支持 -=-=-=-=-=-=-
for model in AVAIL_LLM_MODELS:
if model.startswith('azure-') and (model.replace('azure-','') in model_info.keys()):
mi = model_info[model.replace('azure-','')]
mi.update({"endpoint": azure_endpoint})
model_info.update({model: mi})
# -=-=-=-=-=-=- 以下部分是新加入的模型,可能附带额外依赖 -=-=-=-=-=-=- # -=-=-=-=-=-=- 以下部分是新加入的模型,可能附带额外依赖 -=-=-=-=-=-=-
if "claude-1-100k" in AVAIL_LLM_MODELS or "claude-2" in AVAIL_LLM_MODELS: if "claude-1-100k" in AVAIL_LLM_MODELS or "claude-2" in AVAIL_LLM_MODELS:
from .bridge_claude import predict_no_ui_long_connection as claude_noui from .bridge_claude import predict_no_ui_long_connection as claude_noui
@@ -433,6 +482,22 @@ if "sparkv2" in AVAIL_LLM_MODELS: # 讯飞星火认知大模型
}) })
except: except:
print(trimmed_format_exc()) print(trimmed_format_exc())
if "sparkv3" in AVAIL_LLM_MODELS: # 讯飞星火认知大模型
try:
from .bridge_spark import predict_no_ui_long_connection as spark_noui
from .bridge_spark import predict as spark_ui
model_info.update({
"sparkv3": {
"fn_with_ui": spark_ui,
"fn_without_ui": spark_noui,
"endpoint": None,
"max_token": 4096,
"tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35,
}
})
except:
print(trimmed_format_exc())
if "llama2" in AVAIL_LLM_MODELS: # llama2 if "llama2" in AVAIL_LLM_MODELS: # llama2
try: try:
from .bridge_llama2 import predict_no_ui_long_connection as llama2_noui from .bridge_llama2 import predict_no_ui_long_connection as llama2_noui
@@ -449,6 +514,46 @@ if "llama2" in AVAIL_LLM_MODELS: # llama2
}) })
except: except:
print(trimmed_format_exc()) print(trimmed_format_exc())
if "zhipuai" in AVAIL_LLM_MODELS: # zhipuai
try:
from .bridge_zhipu import predict_no_ui_long_connection as zhipu_noui
from .bridge_zhipu import predict as zhipu_ui
model_info.update({
"zhipuai": {
"fn_with_ui": zhipu_ui,
"fn_without_ui": zhipu_noui,
"endpoint": None,
"max_token": 4096,
"tokenizer": tokenizer_gpt35,
"token_cnt": get_token_num_gpt35,
}
})
except:
print(trimmed_format_exc())
# <-- 用于定义和切换多个azure模型 -->
AZURE_CFG_ARRAY = get_conf("AZURE_CFG_ARRAY")
if len(AZURE_CFG_ARRAY) > 0:
for azure_model_name, azure_cfg_dict in AZURE_CFG_ARRAY.items():
# 可能会覆盖之前的配置,但这是意料之中的
if not azure_model_name.startswith('azure'):
raise ValueError("AZURE_CFG_ARRAY中配置的模型必须以azure开头")
endpoint_ = azure_cfg_dict["AZURE_ENDPOINT"] + \
f'openai/deployments/{azure_cfg_dict["AZURE_ENGINE"]}/chat/completions?api-version=2023-05-15'
model_info.update({
azure_model_name: {
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": endpoint_,
"azure_api_key": azure_cfg_dict["AZURE_API_KEY"],
"max_token": azure_cfg_dict["AZURE_MODEL_MAX_TOKEN"],
"tokenizer": tokenizer_gpt35, # tokenizer只用于粗估token数量
"token_cnt": get_token_num_gpt35,
}
})
if azure_model_name not in AVAIL_LLM_MODELS:
AVAIL_LLM_MODELS += [azure_model_name]
@@ -466,7 +571,7 @@ def LLM_CATCH_EXCEPTION(f):
return decorated return decorated
def predict_no_ui_long_connection(inputs, llm_kwargs, history, sys_prompt, observe_window, console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history, sys_prompt, observe_window=[], console_slience=False):
""" """
发送至LLM等待回复一次性完成不显示中间过程但内部用stream的方法避免中途网线被掐 发送至LLM等待回复一次性完成不显示中间过程但内部用stream的方法避免中途网线被掐
inputs inputs

View File

@@ -0,0 +1,78 @@
model_name = "ChatGLM"
cmd_to_install = "`pip install -r request_llms/requirements_chatglm.txt`"
from transformers import AutoModel, AutoTokenizer
from toolbox import get_conf, ProxyNetworkActivate
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
# ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------
class GetGLM2Handle(LocalLLMHandle):
def load_model_info(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
self.model_name = model_name
self.cmd_to_install = cmd_to_install
def load_model_and_tokenizer(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
import os, glob
import os
import platform
LOCAL_MODEL_QUANT, device = get_conf('LOCAL_MODEL_QUANT', 'LOCAL_MODEL_DEVICE')
if LOCAL_MODEL_QUANT == "INT4": # INT4
_model_name_ = "THUDM/chatglm2-6b-int4"
elif LOCAL_MODEL_QUANT == "INT8": # INT8
_model_name_ = "THUDM/chatglm2-6b-int8"
else:
_model_name_ = "THUDM/chatglm2-6b" # FP16
with ProxyNetworkActivate('Download_LLM'):
chatglm_tokenizer = AutoTokenizer.from_pretrained(_model_name_, trust_remote_code=True)
if device=='cpu':
chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).float()
else:
chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True).half().cuda()
chatglm_model = chatglm_model.eval()
self._model = chatglm_model
self._tokenizer = chatglm_tokenizer
return self._model, self._tokenizer
def llm_stream_generator(self, **kwargs):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
def adaptor(kwargs):
query = kwargs['query']
max_length = kwargs['max_length']
top_p = kwargs['top_p']
temperature = kwargs['temperature']
history = kwargs['history']
return query, max_length, top_p, temperature, history
query, max_length, top_p, temperature, history = adaptor(kwargs)
for response, history in self._model.stream_chat(self._tokenizer,
query,
history,
max_length=max_length,
top_p=top_p,
temperature=temperature,
):
yield response
def try_to_import_special_deps(self, **kwargs):
# import something that will raise error if the user does not install requirement_*.txt
# 🏃‍♂️🏃‍♂️🏃‍♂️ 主进程执行
import importlib
# importlib.import_module('modelscope')
# ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 GPT-Academic Interface
# ------------------------------------------------------------------------------------------------------------------------
predict_no_ui_long_connection, predict = get_local_llm_predict_fns(GetGLM2Handle, model_name)

View File

@@ -0,0 +1,77 @@
model_name = "ChatGLM3"
cmd_to_install = "`pip install -r request_llms/requirements_chatglm.txt`"
from transformers import AutoModel, AutoTokenizer
from toolbox import get_conf, ProxyNetworkActivate
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
# ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------
class GetGLM3Handle(LocalLLMHandle):
def load_model_info(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
self.model_name = model_name
self.cmd_to_install = cmd_to_install
def load_model_and_tokenizer(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
import os, glob
import os
import platform
LOCAL_MODEL_QUANT, device = get_conf('LOCAL_MODEL_QUANT', 'LOCAL_MODEL_DEVICE')
if LOCAL_MODEL_QUANT == "INT4": # INT4
_model_name_ = "THUDM/chatglm3-6b-int4"
elif LOCAL_MODEL_QUANT == "INT8": # INT8
_model_name_ = "THUDM/chatglm3-6b-int8"
else:
_model_name_ = "THUDM/chatglm3-6b" # FP16
with ProxyNetworkActivate('Download_LLM'):
chatglm_tokenizer = AutoTokenizer.from_pretrained(_model_name_, trust_remote_code=True)
if device=='cpu':
chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True, device='cpu').float()
else:
chatglm_model = AutoModel.from_pretrained(_model_name_, trust_remote_code=True, device='cuda')
chatglm_model = chatglm_model.eval()
self._model = chatglm_model
self._tokenizer = chatglm_tokenizer
return self._model, self._tokenizer
def llm_stream_generator(self, **kwargs):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
def adaptor(kwargs):
query = kwargs['query']
max_length = kwargs['max_length']
top_p = kwargs['top_p']
temperature = kwargs['temperature']
history = kwargs['history']
return query, max_length, top_p, temperature, history
query, max_length, top_p, temperature, history = adaptor(kwargs)
for response, history in self._model.stream_chat(self._tokenizer,
query,
history,
max_length=max_length,
top_p=top_p,
temperature=temperature,
):
yield response
def try_to_import_special_deps(self, **kwargs):
# import something that will raise error if the user does not install requirement_*.txt
# 🏃‍♂️🏃‍♂️🏃‍♂️ 主进程执行
import importlib
# importlib.import_module('modelscope')
# ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 GPT-Academic Interface
# ------------------------------------------------------------------------------------------------------------------------
predict_no_ui_long_connection, predict = get_local_llm_predict_fns(GetGLM3Handle, model_name, history_format='chatglm3')

View File

@@ -44,7 +44,7 @@ class GetGLMFTHandle(Process):
self.info = "依赖检测通过" self.info = "依赖检测通过"
self.success = True self.success = True
except: except:
self.info = "缺少ChatGLMFT的依赖如果要使用ChatGLMFT除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_chatglm.txt`安装ChatGLM的依赖。" self.info = "缺少ChatGLMFT的依赖如果要使用ChatGLMFT除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_chatglm.txt`安装ChatGLM的依赖。"
self.success = False self.success = False
def ready(self): def ready(self):
@@ -59,11 +59,11 @@ class GetGLMFTHandle(Process):
if self.chatglmft_model is None: if self.chatglmft_model is None:
from transformers import AutoConfig from transformers import AutoConfig
import torch import torch
# conf = 'request_llm/current_ptune_model.json' # conf = 'request_llms/current_ptune_model.json'
# if not os.path.exists(conf): raise RuntimeError('找不到微调模型信息') # if not os.path.exists(conf): raise RuntimeError('找不到微调模型信息')
# with open(conf, 'r', encoding='utf8') as f: # with open(conf, 'r', encoding='utf8') as f:
# model_args = json.loads(f.read()) # model_args = json.loads(f.read())
CHATGLM_PTUNING_CHECKPOINT, = get_conf('CHATGLM_PTUNING_CHECKPOINT') CHATGLM_PTUNING_CHECKPOINT = get_conf('CHATGLM_PTUNING_CHECKPOINT')
assert os.path.exists(CHATGLM_PTUNING_CHECKPOINT), "找不到微调模型检查点" assert os.path.exists(CHATGLM_PTUNING_CHECKPOINT), "找不到微调模型检查点"
conf = os.path.join(CHATGLM_PTUNING_CHECKPOINT, "config.json") conf = os.path.join(CHATGLM_PTUNING_CHECKPOINT, "config.json")
with open(conf, 'r', encoding='utf8') as f: with open(conf, 'r', encoding='utf8') as f:
@@ -87,7 +87,7 @@ class GetGLMFTHandle(Process):
new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v
model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict) model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)
if model_args['quantization_bit'] is not None: if model_args['quantization_bit'] is not None and model_args['quantization_bit'] != 0:
print(f"Quantized to {model_args['quantization_bit']} bit") print(f"Quantized to {model_args['quantization_bit']} bit")
model = model.quantize(model_args['quantization_bit']) model = model.quantize(model_args['quantization_bit'])
model = model.cuda() model = model.cuda()
@@ -140,7 +140,7 @@ glmft_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global glmft_handle global glmft_handle
if glmft_handle is None: if glmft_handle is None:
@@ -171,7 +171,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -195,13 +195,13 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
history_feedin.append([history[2*i], history[2*i+1]] ) history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收chatglmft的回复 # 开始接收chatglmft的回复
response = "[Local Message]: 等待ChatGLMFT响应中 ..." response = "[Local Message] 等待ChatGLMFT响应中 ..."
for response in glmft_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in glmft_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response) chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == "[Local Message]: 等待ChatGLMFT响应中 ...": if response == "[Local Message] 等待ChatGLMFT响应中 ...":
response = "[Local Message]: ChatGLMFT响应异常 ..." response = "[Local Message] ChatGLMFT响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -1,5 +1,5 @@
model_name = "ChatGLM-ONNX" model_name = "ChatGLM-ONNX"
cmd_to_install = "`pip install -r request_llm/requirements_chatglm_onnx.txt`" cmd_to_install = "`pip install -r request_llms/requirements_chatglm_onnx.txt`"
from transformers import AutoModel, AutoTokenizer from transformers import AutoModel, AutoTokenizer
@@ -8,7 +8,7 @@ import threading
import importlib import importlib
from toolbox import update_ui, get_conf from toolbox import update_ui, get_conf
from multiprocessing import Process, Pipe from multiprocessing import Process, Pipe
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns, SingletonLocalLLM from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
from .chatglmoonx import ChatGLMModel, chat_template from .chatglmoonx import ChatGLMModel, chat_template
@@ -17,7 +17,6 @@ from .chatglmoonx import ChatGLMModel, chat_template
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model # 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
@SingletonLocalLLM
class GetONNXGLMHandle(LocalLLMHandle): class GetONNXGLMHandle(LocalLLMHandle):
def load_model_info(self): def load_model_info(self):
@@ -28,13 +27,13 @@ class GetONNXGLMHandle(LocalLLMHandle):
def load_model_and_tokenizer(self): def load_model_and_tokenizer(self):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行 # 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
import os, glob import os, glob
if not len(glob.glob("./request_llm/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/*.bin")) >= 7: # 该模型有七个 bin 文件 if not len(glob.glob("./request_llms/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/*.bin")) >= 7: # 该模型有七个 bin 文件
from huggingface_hub import snapshot_download from huggingface_hub import snapshot_download
snapshot_download(repo_id="K024/ChatGLM-6b-onnx-u8s8", local_dir="./request_llm/ChatGLM-6b-onnx-u8s8") snapshot_download(repo_id="K024/ChatGLM-6b-onnx-u8s8", local_dir="./request_llms/ChatGLM-6b-onnx-u8s8")
def create_model(): def create_model():
return ChatGLMModel( return ChatGLMModel(
tokenizer_path = "./request_llm/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/sentencepiece.model", tokenizer_path = "./request_llms/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/sentencepiece.model",
onnx_model_path = "./request_llm/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/chatglm-6b-int8.onnx" onnx_model_path = "./request_llms/ChatGLM-6b-onnx-u8s8/chatglm-6b-int8-onnx-merged/chatglm-6b-int8.onnx"
) )
self._model = create_model() self._model = create_model()
return self._model, None return self._model, None

View File

@@ -7,8 +7,7 @@
1. predict: 正常对话时使用具备完备的交互功能不可多线程 1. predict: 正常对话时使用具备完备的交互功能不可多线程
具备多线程调用能力的函数 具备多线程调用能力的函数
2. predict_no_ui高级实验性功能模块调用不会实时显示在界面上参数简单可以多线程并行方便实现复杂的功能逻辑 2. predict_no_ui_long_connection支持多线程
3. predict_no_ui_long_connection在实验过程中发现调用predict_no_ui处理长文档时和openai的连接容易断掉这个函数用stream的方式解决这个问题同样支持多线程
""" """
import json import json
@@ -18,12 +17,13 @@ import logging
import traceback import traceback
import requests import requests
import importlib import importlib
import random
# config_private.py放自己的秘密如API和代理网址 # config_private.py放自己的秘密如API和代理网址
# 读取时首先看是否存在私密的config_private配置文件不受git管控如果有则覆盖原config文件 # 读取时首先看是否存在私密的config_private配置文件不受git管控如果有则覆盖原config文件
from toolbox import get_conf, update_ui, is_any_api_key, select_api_key, what_keys, clip_history, trimmed_format_exc, is_the_upload_folder from toolbox import get_conf, update_ui, is_any_api_key, select_api_key, what_keys, clip_history, trimmed_format_exc, is_the_upload_folder
proxies, TIMEOUT_SECONDS, MAX_RETRY, API_ORG = \ proxies, TIMEOUT_SECONDS, MAX_RETRY, API_ORG, AZURE_CFG_ARRAY = \
get_conf('proxies', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'API_ORG') get_conf('proxies', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'API_ORG', 'AZURE_CFG_ARRAY')
timeout_bot_msg = '[Local Message] Request timeout. Network error. Please check proxy settings in config.py.' + \ timeout_bot_msg = '[Local Message] Request timeout. Network error. Please check proxy settings in config.py.' + \
'网络错误,检查代理服务器是否可用,以及代理设置的格式是否正确,格式须是[协议]://[地址]:[端口],缺一不可。' '网络错误,检查代理服务器是否可用,以及代理设置的格式是否正确,格式须是[协议]://[地址]:[端口],缺一不可。'
@@ -39,6 +39,33 @@ def get_full_error(chunk, stream_response):
break break
return chunk return chunk
def decode_chunk(chunk):
# 提前读取一些信息 (用于判断异常)
chunk_decoded = chunk.decode()
chunkjson = None
has_choices = False
choice_valid = False
has_content = False
has_role = False
try:
chunkjson = json.loads(chunk_decoded[6:])
has_choices = 'choices' in chunkjson
if has_choices: choice_valid = (len(chunkjson['choices']) > 0)
if has_choices and choice_valid: has_content = "content" in chunkjson['choices'][0]["delta"]
if has_choices and choice_valid: has_role = "role" in chunkjson['choices'][0]["delta"]
except:
pass
return chunk_decoded, chunkjson, has_choices, choice_valid, has_content, has_role
from functools import lru_cache
@lru_cache(maxsize=32)
def verify_endpoint(endpoint):
"""
检查endpoint是否可用
"""
if "你亲手写的api名称" in endpoint:
raise ValueError("Endpoint不正确, 请检查AZURE_ENDPOINT的配置! 当前的Endpoint为:" + endpoint)
return endpoint
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False):
""" """
@@ -61,7 +88,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
try: try:
# make a POST request to the API endpoint, stream=False # make a POST request to the API endpoint, stream=False
from .bridge_all import model_info from .bridge_all import model_info
endpoint = model_info[llm_kwargs['llm_model']]['endpoint'] endpoint = verify_endpoint(model_info[llm_kwargs['llm_model']]['endpoint'])
response = requests.post(endpoint, headers=headers, proxies=proxies, response = requests.post(endpoint, headers=headers, proxies=proxies,
json=payload, stream=True, timeout=TIMEOUT_SECONDS); break json=payload, stream=True, timeout=TIMEOUT_SECONDS); break
except requests.exceptions.ReadTimeout as e: except requests.exceptions.ReadTimeout as e:
@@ -153,14 +180,22 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
yield from update_ui(chatbot=chatbot, history=history, msg="api-key不满足要求") # 刷新界面 yield from update_ui(chatbot=chatbot, history=history, msg="api-key不满足要求") # 刷新界面
return return
# 检查endpoint是否合法
try:
from .bridge_all import model_info
endpoint = verify_endpoint(model_info[llm_kwargs['llm_model']]['endpoint'])
except:
tb_str = '```\n' + trimmed_format_exc() + '```'
chatbot[-1] = (inputs, tb_str)
yield from update_ui(chatbot=chatbot, history=history, msg="Endpoint不满足要求") # 刷新界面
return
history.append(inputs); history.append("") history.append(inputs); history.append("")
retry = 0 retry = 0
while True: while True:
try: try:
# make a POST request to the API endpoint, stream=True # make a POST request to the API endpoint, stream=True
from .bridge_all import model_info
endpoint = model_info[llm_kwargs['llm_model']]['endpoint']
response = requests.post(endpoint, headers=headers, proxies=proxies, response = requests.post(endpoint, headers=headers, proxies=proxies,
json=payload, stream=True, timeout=TIMEOUT_SECONDS);break json=payload, stream=True, timeout=TIMEOUT_SECONDS);break
except: except:
@@ -191,23 +226,36 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
yield from update_ui(chatbot=chatbot, history=history, msg="非OpenAI官方接口返回了错误:" + chunk.decode()) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history, msg="非OpenAI官方接口返回了错误:" + chunk.decode()) # 刷新界面
return return
chunk_decoded = chunk.decode() # 提前读取一些信息 (用于判断异常)
chunk_decoded, chunkjson, has_choices, choice_valid, has_content, has_role = decode_chunk(chunk)
if is_head_of_the_stream and (r'"object":"error"' not in chunk_decoded) and (r"content" not in chunk_decoded): if is_head_of_the_stream and (r'"object":"error"' not in chunk_decoded) and (r"content" not in chunk_decoded):
# 数据流的第一帧不携带content # 数据流的第一帧不携带content
is_head_of_the_stream = False; continue is_head_of_the_stream = False; continue
if chunk: if chunk:
try: try:
if has_choices and not choice_valid:
# 一些垃圾第三方接口的出现这样的错误
continue
# 前者是API2D的结束条件后者是OPENAI的结束条件 # 前者是API2D的结束条件后者是OPENAI的结束条件
if ('data: [DONE]' in chunk_decoded) or (len(json.loads(chunk_decoded[6:])['choices'][0]["delta"]) == 0): if ('data: [DONE]' in chunk_decoded) or (len(chunkjson['choices'][0]["delta"]) == 0):
# 判定为数据流的结束gpt_replying_buffer也写完了 # 判定为数据流的结束gpt_replying_buffer也写完了
logging.info(f'[response] {gpt_replying_buffer}') logging.info(f'[response] {gpt_replying_buffer}')
break break
# 处理数据流的主体 # 处理数据流的主体
chunkjson = json.loads(chunk_decoded[6:])
status_text = f"finish_reason: {chunkjson['choices'][0].get('finish_reason', 'null')}" status_text = f"finish_reason: {chunkjson['choices'][0].get('finish_reason', 'null')}"
# 如果这里抛出异常一般是文本过长详情见get_full_error的输出 # 如果这里抛出异常一般是文本过长详情见get_full_error的输出
if has_content:
# 正常情况
gpt_replying_buffer = gpt_replying_buffer + chunkjson['choices'][0]["delta"]["content"] gpt_replying_buffer = gpt_replying_buffer + chunkjson['choices'][0]["delta"]["content"]
elif has_role:
# 一些第三方接口的出现这样的错误,兼容一下吧
continue
else:
# 一些垃圾第三方接口的出现这样的错误
gpt_replying_buffer = gpt_replying_buffer + chunkjson['choices'][0]["delta"]["content"]
history[-1] = gpt_replying_buffer history[-1] = gpt_replying_buffer
chatbot[-1] = (history[-2], history[-1]) chatbot[-1] = (history[-2], history[-1])
yield from update_ui(chatbot=chatbot, history=history, msg=status_text) # 刷新界面 yield from update_ui(chatbot=chatbot, history=history, msg=status_text) # 刷新界面
@@ -239,6 +287,8 @@ def handle_error(inputs, llm_kwargs, chatbot, history, chunk_decoded, error_msg)
chatbot[-1] = (chatbot[-1][0], "[Local Message] Your account is not active. OpenAI以账户失效为由, 拒绝服务." + openai_website) chatbot[-1] = (chatbot[-1][0], "[Local Message] Your account is not active. OpenAI以账户失效为由, 拒绝服务." + openai_website)
elif "associated with a deactivated account" in error_msg: elif "associated with a deactivated account" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] You are associated with a deactivated account. OpenAI以账户失效为由, 拒绝服务." + openai_website) chatbot[-1] = (chatbot[-1][0], "[Local Message] You are associated with a deactivated account. OpenAI以账户失效为由, 拒绝服务." + openai_website)
elif "API key has been deactivated" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] API key has been deactivated. OpenAI以账户失效为由, 拒绝服务." + openai_website)
elif "bad forward key" in error_msg: elif "bad forward key" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] Bad forward key. API2D账户额度不足.") chatbot[-1] = (chatbot[-1][0], "[Local Message] Bad forward key. API2D账户额度不足.")
elif "Not enough point" in error_msg: elif "Not enough point" in error_msg:
@@ -263,7 +313,11 @@ def generate_payload(inputs, llm_kwargs, history, system_prompt, stream):
"Authorization": f"Bearer {api_key}" "Authorization": f"Bearer {api_key}"
} }
if API_ORG.startswith('org-'): headers.update({"OpenAI-Organization": API_ORG}) if API_ORG.startswith('org-'): headers.update({"OpenAI-Organization": API_ORG})
if llm_kwargs['llm_model'].startswith('azure-'): headers.update({"api-key": api_key}) if llm_kwargs['llm_model'].startswith('azure-'):
headers.update({"api-key": api_key})
if llm_kwargs['llm_model'] in AZURE_CFG_ARRAY.keys():
azure_api_key_unshared = AZURE_CFG_ARRAY[llm_kwargs['llm_model']]["AZURE_API_KEY"]
headers.update({"api-key": azure_api_key_unshared})
conversation_cnt = len(history) // 2 conversation_cnt = len(history) // 2
@@ -288,9 +342,23 @@ def generate_payload(inputs, llm_kwargs, history, system_prompt, stream):
what_i_ask_now["role"] = "user" what_i_ask_now["role"] = "user"
what_i_ask_now["content"] = inputs what_i_ask_now["content"] = inputs
messages.append(what_i_ask_now) messages.append(what_i_ask_now)
model = llm_kwargs['llm_model']
if llm_kwargs['llm_model'].startswith('api2d-'):
model = llm_kwargs['llm_model'][len('api2d-'):]
if model == "gpt-3.5-random": # 随机选择, 绕过openai访问频率限制
model = random.choice([
"gpt-3.5-turbo",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-1106",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-0301",
])
logging.info("Random select model:" + model)
payload = { payload = {
"model": llm_kwargs['llm_model'].strip('api2d-'), "model": model,
"messages": messages, "messages": messages,
"temperature": llm_kwargs['temperature'], # 1.0, "temperature": llm_kwargs['temperature'], # 1.0,
"top_p": llm_kwargs['top_p'], # 1.0, "top_p": llm_kwargs['top_p'], # 1.0,

View File

@@ -7,8 +7,7 @@
1. predict: 正常对话时使用具备完备的交互功能不可多线程 1. predict: 正常对话时使用具备完备的交互功能不可多线程
具备多线程调用能力的函数 具备多线程调用能力的函数
2. predict_no_ui高级实验性功能模块调用不会实时显示在界面上参数简单可以多线程并行方便实现复杂的功能逻辑 2. predict_no_ui_long_connection支持多线程
3. predict_no_ui_long_connection在实验过程中发现调用predict_no_ui处理长文档时和openai的连接容易断掉这个函数用stream的方式解决这个问题同样支持多线程
""" """
import json import json

View File

@@ -7,7 +7,7 @@
1. predict: 正常对话时使用具备完备的交互功能不可多线程 1. predict: 正常对话时使用具备完备的交互功能不可多线程
具备多线程调用能力的函数 具备多线程调用能力的函数
2. predict_no_ui_long_connection在实验过程中发现调用predict_no_ui处理长文档时和openai的连接容易断掉这个函数用stream的方式解决这个问题同样支持多线程 2. predict_no_ui_long_connection支持多线程
""" """
import os import os

View File

@@ -1,13 +1,13 @@
model_name = "InternLM" model_name = "InternLM"
cmd_to_install = "`pip install -r request_llm/requirements_chatglm.txt`" cmd_to_install = "`pip install -r request_llms/requirements_chatglm.txt`"
from transformers import AutoModel, AutoTokenizer from transformers import AutoModel, AutoTokenizer
import time import time
import threading import threading
import importlib import importlib
from toolbox import update_ui, get_conf from toolbox import update_ui, get_conf, ProxyNetworkActivate
from multiprocessing import Process, Pipe from multiprocessing import Process, Pipe
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns, SingletonLocalLLM from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
@@ -34,7 +34,6 @@ def combine_history(prompt, hist):
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model # 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
@SingletonLocalLLM
class GetInternlmHandle(LocalLLMHandle): class GetInternlmHandle(LocalLLMHandle):
def load_model_info(self): def load_model_info(self):
@@ -52,7 +51,8 @@ class GetInternlmHandle(LocalLLMHandle):
# 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行 # 🏃‍♂️🏃‍♂️🏃‍♂️ 子进程执行
import torch import torch
from transformers import AutoModelForCausalLM, AutoTokenizer from transformers import AutoModelForCausalLM, AutoTokenizer
device, = get_conf('LOCAL_MODEL_DEVICE') device = get_conf('LOCAL_MODEL_DEVICE')
with ProxyNetworkActivate('Download_LLM'):
if self._model is None: if self._model is None:
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True) tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
if device=='cpu': if device=='cpu':
@@ -94,8 +94,9 @@ class GetInternlmHandle(LocalLLMHandle):
inputs = tokenizer([prompt], padding=True, return_tensors="pt") inputs = tokenizer([prompt], padding=True, return_tensors="pt")
input_length = len(inputs["input_ids"][0]) input_length = len(inputs["input_ids"][0])
device = get_conf('LOCAL_MODEL_DEVICE')
for k, v in inputs.items(): for k, v in inputs.items():
inputs[k] = v.cuda() inputs[k] = v.to(device)
input_ids = inputs["input_ids"] input_ids = inputs["input_ids"]
batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1] batch_size, input_ids_seq_length = input_ids.shape[0], input_ids.shape[-1]
if generation_config is None: if generation_config is None:

View File

@@ -28,8 +28,8 @@ class GetGLMHandle(Process):
self.success = True self.success = True
except: except:
from toolbox import trimmed_format_exc from toolbox import trimmed_format_exc
self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\ self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\
r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llm/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\ r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llms/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\
r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc() r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc()
self.success = False self.success = False
@@ -45,15 +45,15 @@ class GetGLMHandle(Process):
env = os.environ.get("PATH", "") env = os.environ.get("PATH", "")
os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin') os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin')
root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..') root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..')
os.chdir(root_dir_assume + '/request_llm/jittorllms') os.chdir(root_dir_assume + '/request_llms/jittorllms')
sys.path.append(root_dir_assume + '/request_llm/jittorllms') sys.path.append(root_dir_assume + '/request_llms/jittorllms')
validate_path() # validate path so you can run from base directory validate_path() # validate path so you can run from base directory
def load_model(): def load_model():
import types import types
try: try:
if self.jittorllms_model is None: if self.jittorllms_model is None:
device, = get_conf('LOCAL_MODEL_DEVICE') device = get_conf('LOCAL_MODEL_DEVICE')
from .jittorllms.models import get_model from .jittorllms.models import get_model
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"] # availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
args_dict = {'model': 'llama'} args_dict = {'model': 'llama'}
@@ -109,7 +109,7 @@ llama_glm_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global llama_glm_handle global llama_glm_handle
if llama_glm_handle is None: if llama_glm_handle is None:
@@ -140,7 +140,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -163,13 +163,13 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
history_feedin.append([history[2*i], history[2*i+1]] ) history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收jittorllms的回复 # 开始接收jittorllms的回复
response = "[Local Message]: 等待jittorllms响应中 ..." response = "[Local Message] 等待jittorllms响应中 ..."
for response in llama_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in llama_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response) chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == "[Local Message]: 等待jittorllms响应中 ...": if response == "[Local Message] 等待jittorllms响应中 ...":
response = "[Local Message]: jittorllms响应异常 ..." response = "[Local Message] jittorllms响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -28,8 +28,8 @@ class GetGLMHandle(Process):
self.success = True self.success = True
except: except:
from toolbox import trimmed_format_exc from toolbox import trimmed_format_exc
self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\ self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\
r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llm/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\ r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llms/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\
r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc() r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc()
self.success = False self.success = False
@@ -45,15 +45,15 @@ class GetGLMHandle(Process):
env = os.environ.get("PATH", "") env = os.environ.get("PATH", "")
os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin') os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin')
root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..') root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..')
os.chdir(root_dir_assume + '/request_llm/jittorllms') os.chdir(root_dir_assume + '/request_llms/jittorllms')
sys.path.append(root_dir_assume + '/request_llm/jittorllms') sys.path.append(root_dir_assume + '/request_llms/jittorllms')
validate_path() # validate path so you can run from base directory validate_path() # validate path so you can run from base directory
def load_model(): def load_model():
import types import types
try: try:
if self.jittorllms_model is None: if self.jittorllms_model is None:
device, = get_conf('LOCAL_MODEL_DEVICE') device = get_conf('LOCAL_MODEL_DEVICE')
from .jittorllms.models import get_model from .jittorllms.models import get_model
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"] # availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
args_dict = {'model': 'pangualpha'} args_dict = {'model': 'pangualpha'}
@@ -109,7 +109,7 @@ pangu_glm_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global pangu_glm_handle global pangu_glm_handle
if pangu_glm_handle is None: if pangu_glm_handle is None:
@@ -140,7 +140,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -163,13 +163,13 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
history_feedin.append([history[2*i], history[2*i+1]] ) history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收jittorllms的回复 # 开始接收jittorllms的回复
response = "[Local Message]: 等待jittorllms响应中 ..." response = "[Local Message] 等待jittorllms响应中 ..."
for response in pangu_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in pangu_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response) chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == "[Local Message]: 等待jittorllms响应中 ...": if response == "[Local Message] 等待jittorllms响应中 ...":
response = "[Local Message]: jittorllms响应异常 ..." response = "[Local Message] jittorllms响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -28,8 +28,8 @@ class GetGLMHandle(Process):
self.success = True self.success = True
except: except:
from toolbox import trimmed_format_exc from toolbox import trimmed_format_exc
self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\ self.info = r"缺少jittorllms的依赖如果要使用jittorllms除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_jittorllms.txt -i https://pypi.jittor.org/simple -I`"+\
r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llm/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\ r"和`git clone https://gitlink.org.cn/jittor/JittorLLMs.git --depth 1 request_llms/jittorllms`两个指令来安装jittorllms的依赖在项目根目录运行这两个指令" +\
r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc() r"警告安装jittorllms依赖后将完全破坏现有的pytorch环境建议使用docker环境" + trimmed_format_exc()
self.success = False self.success = False
@@ -45,15 +45,15 @@ class GetGLMHandle(Process):
env = os.environ.get("PATH", "") env = os.environ.get("PATH", "")
os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin') os.environ["PATH"] = env.replace('/cuda/bin', '/x/bin')
root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..') root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..')
os.chdir(root_dir_assume + '/request_llm/jittorllms') os.chdir(root_dir_assume + '/request_llms/jittorllms')
sys.path.append(root_dir_assume + '/request_llm/jittorllms') sys.path.append(root_dir_assume + '/request_llms/jittorllms')
validate_path() # validate path so you can run from base directory validate_path() # validate path so you can run from base directory
def load_model(): def load_model():
import types import types
try: try:
if self.jittorllms_model is None: if self.jittorllms_model is None:
device, = get_conf('LOCAL_MODEL_DEVICE') device = get_conf('LOCAL_MODEL_DEVICE')
from .jittorllms.models import get_model from .jittorllms.models import get_model
# availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"] # availabel_models = ["chatglm", "pangualpha", "llama", "chatrwkv"]
args_dict = {'model': 'chatrwkv'} args_dict = {'model': 'chatrwkv'}
@@ -109,7 +109,7 @@ rwkv_glm_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global rwkv_glm_handle global rwkv_glm_handle
if rwkv_glm_handle is None: if rwkv_glm_handle is None:
@@ -140,7 +140,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -163,13 +163,13 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
history_feedin.append([history[2*i], history[2*i+1]] ) history_feedin.append([history[2*i], history[2*i+1]] )
# 开始接收jittorllms的回复 # 开始接收jittorllms的回复
response = "[Local Message]: 等待jittorllms响应中 ..." response = "[Local Message] 等待jittorllms响应中 ..."
for response in rwkv_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in rwkv_glm_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, response) chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == "[Local Message]: 等待jittorllms响应中 ...": if response == "[Local Message] 等待jittorllms响应中 ...":
response = "[Local Message]: jittorllms响应异常 ..." response = "[Local Message] jittorllms响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -1,18 +1,17 @@
model_name = "LLaMA" model_name = "LLaMA"
cmd_to_install = "`pip install -r request_llm/requirements_chatglm.txt`" cmd_to_install = "`pip install -r request_llms/requirements_chatglm.txt`"
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
from toolbox import update_ui, get_conf, ProxyNetworkActivate from toolbox import update_ui, get_conf, ProxyNetworkActivate
from multiprocessing import Process, Pipe from multiprocessing import Process, Pipe
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns, SingletonLocalLLM from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
from threading import Thread from threading import Thread
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model # 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
@SingletonLocalLLM
class GetONNXGLMHandle(LocalLLMHandle): class GetONNXGLMHandle(LocalLLMHandle):
def load_model_info(self): def load_model_info(self):

View File

@@ -24,12 +24,12 @@ class GetGLMHandle(Process):
def check_dependency(self): # 主进程执行 def check_dependency(self): # 主进程执行
try: try:
import datasets, os import datasets, os
assert os.path.exists('request_llm/moss/models') assert os.path.exists('request_llms/moss/models')
self.info = "依赖检测通过" self.info = "依赖检测通过"
self.success = True self.success = True
except: except:
self.info = """ self.info = """
缺少MOSS的依赖如果要使用MOSS除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_moss.txt``git clone https://github.com/OpenLMLab/MOSS.git request_llm/moss`安装MOSS的依赖 缺少MOSS的依赖如果要使用MOSS除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_moss.txt``git clone https://github.com/OpenLMLab/MOSS.git request_llms/moss`安装MOSS的依赖
""" """
self.success = False self.success = False
return self.success return self.success
@@ -110,8 +110,8 @@ class GetGLMHandle(Process):
def validate_path(): def validate_path():
import os, sys import os, sys
root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..') root_dir_assume = os.path.abspath(os.path.dirname(__file__) + '/..')
os.chdir(root_dir_assume + '/request_llm/moss') os.chdir(root_dir_assume + '/request_llms/moss')
sys.path.append(root_dir_assume + '/request_llm/moss') sys.path.append(root_dir_assume + '/request_llms/moss')
validate_path() # validate path so you can run from base directory validate_path() # validate path so you can run from base directory
try: try:
@@ -176,7 +176,7 @@ moss_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global moss_handle global moss_handle
if moss_handle is None: if moss_handle is None:
@@ -206,7 +206,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -219,7 +219,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
moss_handle = None moss_handle = None
return return
else: else:
response = "[Local Message]: 等待MOSS响应中 ..." response = "[Local Message] 等待MOSS响应中 ..."
chatbot[-1] = (inputs, response) chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
@@ -238,7 +238,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == "[Local Message]: 等待MOSS响应中 ...": if response == "[Local Message] 等待MOSS响应中 ...":
response = "[Local Message]: MOSS响应异常 ..." response = "[Local Message] MOSS响应异常 ..."
history.extend([inputs, response.strip('<|MOSS|>: ')]) history.extend([inputs, response.strip('<|MOSS|>: ')])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -54,7 +54,7 @@ class NewBingHandle(Process):
self.info = "依赖检测通过等待NewBing响应。注意目前不能多人同时调用NewBing接口有线程锁否则将导致每个人的NewBing问询历史互相渗透。调用NewBing时会自动使用已配置的代理。" self.info = "依赖检测通过等待NewBing响应。注意目前不能多人同时调用NewBing接口有线程锁否则将导致每个人的NewBing问询历史互相渗透。调用NewBing时会自动使用已配置的代理。"
self.success = True self.success = True
except: except:
self.info = "缺少的依赖如果要使用Newbing除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_newbing.txt`安装Newbing的依赖。" self.info = "缺少的依赖如果要使用Newbing除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_newbing.txt`安装Newbing的依赖。"
self.success = False self.success = False
def ready(self): def ready(self):
@@ -62,8 +62,8 @@ class NewBingHandle(Process):
async def async_run(self): async def async_run(self):
# 读取配置 # 读取配置
NEWBING_STYLE, = get_conf('NEWBING_STYLE') NEWBING_STYLE = get_conf('NEWBING_STYLE')
from request_llm.bridge_all import model_info from request_llms.bridge_all import model_info
endpoint = model_info['newbing']['endpoint'] endpoint = model_info['newbing']['endpoint']
while True: while True:
# 等待 # 等待
@@ -141,10 +141,10 @@ class NewBingHandle(Process):
except: except:
self.success = False self.success = False
tb_str = '\n```\n' + trimmed_format_exc() + '\n```\n' tb_str = '\n```\n' + trimmed_format_exc() + '\n```\n'
self.child.send(f'[Local Message] 不能加载Newbing组件。{tb_str}') self.child.send(f'[Local Message] 不能加载Newbing组件请注意Newbing组件已不再维护{tb_str}')
self.child.send('[Fail]') self.child.send('[Fail]')
self.child.send('[Finish]') self.child.send('[Finish]')
raise RuntimeError(f"不能加载Newbing组件。") raise RuntimeError(f"不能加载Newbing组件请注意Newbing组件已不再维护")
self.success = True self.success = True
try: try:
@@ -181,7 +181,7 @@ newbingfree_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global newbingfree_handle global newbingfree_handle
if (newbingfree_handle is None) or (not newbingfree_handle.success): if (newbingfree_handle is None) or (not newbingfree_handle.success):
@@ -199,7 +199,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可 watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
response = "" response = ""
if len(observe_window) >= 1: observe_window[0] = "[Local Message]: 等待NewBing响应中 ..." if len(observe_window) >= 1: observe_window[0] = "[Local Message] 等待NewBing响应中 ..."
for response in newbingfree_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in newbingfree_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
if len(observe_window) >= 1: observe_window[0] = preprocess_newbing_out_simple(response) if len(observe_window) >= 1: observe_window[0] = preprocess_newbing_out_simple(response)
if len(observe_window) >= 2: if len(observe_window) >= 2:
@@ -210,9 +210,9 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "[Local Message]: 等待NewBing响应中 ...")) chatbot.append((inputs, "[Local Message] 等待NewBing响应中 ..."))
global newbingfree_handle global newbingfree_handle
if (newbingfree_handle is None) or (not newbingfree_handle.success): if (newbingfree_handle is None) or (not newbingfree_handle.success):
@@ -231,13 +231,13 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
for i in range(len(history)//2): for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]] ) history_feedin.append([history[2*i], history[2*i+1]] )
chatbot[-1] = (inputs, "[Local Message]: 等待NewBing响应中 ...") chatbot[-1] = (inputs, "[Local Message] 等待NewBing响应中 ...")
response = "[Local Message]: 等待NewBing响应中 ..." response = "[Local Message] 等待NewBing响应中 ..."
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢尚未完成全部响应请耐心完成后再提交新问题。") yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢尚未完成全部响应请耐心完成后再提交新问题。")
for response in newbingfree_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in newbingfree_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
chatbot[-1] = (inputs, preprocess_newbing_out(response)) chatbot[-1] = (inputs, preprocess_newbing_out(response))
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢尚未完成全部响应请耐心完成后再提交新问题。") yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢尚未完成全部响应请耐心完成后再提交新问题。")
if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常请刷新界面重试 ..." if response == "[Local Message] 等待NewBing响应中 ...": response = "[Local Message] NewBing响应异常请刷新界面重试 ..."
history.extend([inputs, response]) history.extend([inputs, response])
logging.info(f'[raw_input] {inputs}') logging.info(f'[raw_input] {inputs}')
logging.info(f'[response] {response}') logging.info(f'[response] {response}')

View File

@@ -75,11 +75,12 @@ def generate_message_payload(inputs, llm_kwargs, history, system_prompt):
def generate_from_baidu_qianfan(inputs, llm_kwargs, history, system_prompt): def generate_from_baidu_qianfan(inputs, llm_kwargs, history, system_prompt):
BAIDU_CLOUD_QIANFAN_MODEL, = get_conf('BAIDU_CLOUD_QIANFAN_MODEL') BAIDU_CLOUD_QIANFAN_MODEL = get_conf('BAIDU_CLOUD_QIANFAN_MODEL')
url_lib = { url_lib = {
"ERNIE-Bot": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions" , "ERNIE-Bot-4": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro",
"ERNIE-Bot-turbo": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant" , "ERNIE-Bot": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions",
"ERNIE-Bot-turbo": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant",
"BLOOMZ-7B": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/bloomz_7b1", "BLOOMZ-7B": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/bloomz_7b1",
"Llama-2-70B-Chat": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/llama_2_70b", "Llama-2-70B-Chat": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/llama_2_70b",
@@ -119,7 +120,7 @@ def generate_from_baidu_qianfan(inputs, llm_kwargs, history, system_prompt):
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
watch_dog_patience = 5 watch_dog_patience = 5
response = "" response = ""
@@ -134,7 +135,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
@@ -158,8 +159,8 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
return return
# 总结输出 # 总结输出
response = f"[Local Message]: {model_name}响应异常 ..." response = f"[Local Message] {model_name}响应异常 ..."
if response == f"[Local Message]: 等待{model_name}响应中 ...": if response == f"[Local Message] 等待{model_name}响应中 ...":
response = f"[Local Message]: {model_name}响应异常 ..." response = f"[Local Message] {model_name}响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -1,21 +1,20 @@
model_name = "Qwen" model_name = "Qwen"
cmd_to_install = "`pip install -r request_llm/requirements_qwen.txt`" cmd_to_install = "`pip install -r request_llms/requirements_qwen.txt`"
from transformers import AutoModel, AutoTokenizer from transformers import AutoModel, AutoTokenizer
import time import time
import threading import threading
import importlib import importlib
from toolbox import update_ui, get_conf from toolbox import update_ui, get_conf, ProxyNetworkActivate
from multiprocessing import Process, Pipe from multiprocessing import Process, Pipe
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns, SingletonLocalLLM from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
# 🔌💻 Local Model # 🔌💻 Local Model
# ------------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------------
@SingletonLocalLLM
class GetONNXGLMHandle(LocalLLMHandle): class GetONNXGLMHandle(LocalLLMHandle):
def load_model_info(self): def load_model_info(self):
@@ -30,11 +29,11 @@ class GetONNXGLMHandle(LocalLLMHandle):
import platform import platform
from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
with ProxyNetworkActivate('Download_LLM'):
model_id = 'qwen/Qwen-7B-Chat' model_id = 'qwen/Qwen-7B-Chat'
revision = 'v1.0.1' self._tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen-7B-Chat', trust_remote_code=True, resume_download=True)
self._tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision, trust_remote_code=True)
# use fp16 # use fp16
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", revision=revision, trust_remote_code=True, fp16=True).eval() model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True, fp16=True).eval()
model.generation_config = GenerationConfig.from_pretrained(model_id, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参 model.generation_config = GenerationConfig.from_pretrained(model_id, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
self._model = model self._model = model

View File

@@ -8,7 +8,7 @@ from multiprocessing import Process, Pipe
model_name = '星火认知大模型' model_name = '星火认知大模型'
def validate_key(): def validate_key():
XFYUN_APPID, = get_conf('XFYUN_APPID', ) XFYUN_APPID = get_conf('XFYUN_APPID')
if XFYUN_APPID == '00000000' or XFYUN_APPID == '': if XFYUN_APPID == '00000000' or XFYUN_APPID == '':
return False return False
return True return True
@@ -16,7 +16,7 @@ def validate_key():
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
watch_dog_patience = 5 watch_dog_patience = 5
response = "" response = ""
@@ -36,13 +36,13 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "")) chatbot.append((inputs, ""))
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
if validate_key() is False: if validate_key() is False:
yield from update_ui_lastest_msg(lastmsg="[Local Message]: 请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET", chatbot=chatbot, history=history, delay=0) yield from update_ui_lastest_msg(lastmsg="[Local Message] 请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET", chatbot=chatbot, history=history, delay=0)
return return
if additional_fn is not None: if additional_fn is not None:
@@ -57,7 +57,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)
# 总结输出 # 总结输出
if response == f"[Local Message]: 等待{model_name}响应中 ...": if response == f"[Local Message] 等待{model_name}响应中 ...":
response = f"[Local Message]: {model_name}响应异常 ..." response = f"[Local Message] {model_name}响应异常 ..."
history.extend([inputs, response]) history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history) yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -36,7 +36,7 @@ try:
CHANNEL_ID = None CHANNEL_ID = None
async def open_channel(self): async def open_channel(self):
response = await self.conversations_open(users=get_conf('SLACK_CLAUDE_BOT_ID')[0]) response = await self.conversations_open(users=get_conf('SLACK_CLAUDE_BOT_ID'))
self.CHANNEL_ID = response["channel"]["id"] self.CHANNEL_ID = response["channel"]["id"]
async def chat(self, text): async def chat(self, text):
@@ -51,7 +51,7 @@ try:
# TODO暂时不支持历史消息因为在同一个频道里存在多人使用时历史消息渗透问题 # TODO暂时不支持历史消息因为在同一个频道里存在多人使用时历史消息渗透问题
resp = await self.conversations_history(channel=self.CHANNEL_ID, oldest=self.LAST_TS, limit=1) resp = await self.conversations_history(channel=self.CHANNEL_ID, oldest=self.LAST_TS, limit=1)
msg = [msg for msg in resp["messages"] msg = [msg for msg in resp["messages"]
if msg.get("user") == get_conf('SLACK_CLAUDE_BOT_ID')[0]] if msg.get("user") == get_conf('SLACK_CLAUDE_BOT_ID')]
return msg return msg
except (SlackApiError, KeyError) as e: except (SlackApiError, KeyError) as e:
raise RuntimeError(f"获取Slack消息失败。") raise RuntimeError(f"获取Slack消息失败。")
@@ -99,7 +99,7 @@ class ClaudeHandle(Process):
self.info = "依赖检测通过等待Claude响应。注意目前不能多人同时调用Claude接口有线程锁否则将导致每个人的Claude问询历史互相渗透。调用Claude时会自动使用已配置的代理。" self.info = "依赖检测通过等待Claude响应。注意目前不能多人同时调用Claude接口有线程锁否则将导致每个人的Claude问询历史互相渗透。调用Claude时会自动使用已配置的代理。"
self.success = True self.success = True
except: except:
self.info = "缺少的依赖如果要使用Claude除了基础的pip依赖以外您还需要运行`pip install -r request_llm/requirements_slackclaude.txt`安装Claude的依赖然后重启程序。" self.info = "缺少的依赖如果要使用Claude除了基础的pip依赖以外您还需要运行`pip install -r request_llms/requirements_slackclaude.txt`安装Claude的依赖然后重启程序。"
self.success = False self.success = False
def ready(self): def ready(self):
@@ -146,14 +146,14 @@ class ClaudeHandle(Process):
self.local_history = [] self.local_history = []
if (self.claude_model is None) or (not self.success): if (self.claude_model is None) or (not self.success):
# 代理设置 # 代理设置
proxies, = get_conf('proxies') proxies = get_conf('proxies')
if proxies is None: if proxies is None:
self.proxies_https = None self.proxies_https = None
else: else:
self.proxies_https = proxies['https'] self.proxies_https = proxies['https']
try: try:
SLACK_CLAUDE_USER_TOKEN, = get_conf('SLACK_CLAUDE_USER_TOKEN') SLACK_CLAUDE_USER_TOKEN = get_conf('SLACK_CLAUDE_USER_TOKEN')
self.claude_model = SlackClient(token=SLACK_CLAUDE_USER_TOKEN, proxy=self.proxies_https) self.claude_model = SlackClient(token=SLACK_CLAUDE_USER_TOKEN, proxy=self.proxies_https)
print('Claude组件初始化成功。') print('Claude组件初始化成功。')
except: except:
@@ -204,7 +204,7 @@ claude_handle = None
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False): def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=None, console_slience=False):
""" """
多线程方法 多线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
global claude_handle global claude_handle
if (claude_handle is None) or (not claude_handle.success): if (claude_handle is None) or (not claude_handle.success):
@@ -222,7 +222,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可 watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
response = "" response = ""
observe_window[0] = "[Local Message]: 等待Claude响应中 ..." observe_window[0] = "[Local Message] 等待Claude响应中 ..."
for response in claude_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']): for response in claude_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=sys_prompt, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
observe_window[0] = preprocess_newbing_out_simple(response) observe_window[0] = preprocess_newbing_out_simple(response)
if len(observe_window) >= 2: if len(observe_window) >= 2:
@@ -234,9 +234,9 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream=True, additional_fn=None): def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream=True, additional_fn=None):
""" """
单线程方法 单线程方法
函数的说明请见 request_llm/bridge_all.py 函数的说明请见 request_llms/bridge_all.py
""" """
chatbot.append((inputs, "[Local Message]: 等待Claude响应中 ...")) chatbot.append((inputs, "[Local Message] 等待Claude响应中 ..."))
global claude_handle global claude_handle
if (claude_handle is None) or (not claude_handle.success): if (claude_handle is None) or (not claude_handle.success):
@@ -255,14 +255,14 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
for i in range(len(history)//2): for i in range(len(history)//2):
history_feedin.append([history[2*i], history[2*i+1]]) history_feedin.append([history[2*i], history[2*i+1]])
chatbot[-1] = (inputs, "[Local Message]: 等待Claude响应中 ...") chatbot[-1] = (inputs, "[Local Message] 等待Claude响应中 ...")
response = "[Local Message]: 等待Claude响应中 ..." response = "[Local Message] 等待Claude响应中 ..."
yield from update_ui(chatbot=chatbot, history=history, msg="Claude响应缓慢尚未完成全部响应请耐心完成后再提交新问题。") yield from update_ui(chatbot=chatbot, history=history, msg="Claude响应缓慢尚未完成全部响应请耐心完成后再提交新问题。")
for response in claude_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt): for response in claude_handle.stream_chat(query=inputs, history=history_feedin, system_prompt=system_prompt):
chatbot[-1] = (inputs, preprocess_newbing_out(response)) chatbot[-1] = (inputs, preprocess_newbing_out(response))
yield from update_ui(chatbot=chatbot, history=history, msg="Claude响应缓慢尚未完成全部响应请耐心完成后再提交新问题。") yield from update_ui(chatbot=chatbot, history=history, msg="Claude响应缓慢尚未完成全部响应请耐心完成后再提交新问题。")
if response == "[Local Message]: 等待Claude响应中 ...": if response == "[Local Message] 等待Claude响应中 ...":
response = "[Local Message]: Claude响应异常请刷新界面重试 ..." response = "[Local Message] Claude响应异常请刷新界面重试 ..."
history.extend([inputs, response]) history.extend([inputs, response])
logging.info(f'[raw_input] {inputs}') logging.info(f'[raw_input] {inputs}')
logging.info(f'[response] {response}') logging.info(f'[response] {response}')

View File

@@ -0,0 +1,59 @@
import time
from toolbox import update_ui, get_conf, update_ui_lastest_msg
model_name = '智谱AI大模型'
def validate_key():
ZHIPUAI_API_KEY = get_conf("ZHIPUAI_API_KEY")
if ZHIPUAI_API_KEY == '': return False
return True
def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False):
"""
⭐多线程方法
函数的说明请见 request_llms/bridge_all.py
"""
watch_dog_patience = 5
response = ""
if validate_key() is False:
raise RuntimeError('请配置ZHIPUAI_API_KEY')
from .com_zhipuapi import ZhipuRequestInstance
sri = ZhipuRequestInstance()
for response in sri.generate(inputs, llm_kwargs, history, sys_prompt):
if len(observe_window) >= 1:
observe_window[0] = response
if len(observe_window) >= 2:
if (time.time()-observe_window[1]) > watch_dog_patience: raise RuntimeError("程序终止。")
return response
def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
"""
⭐单线程方法
函数的说明请见 request_llms/bridge_all.py
"""
chatbot.append((inputs, ""))
yield from update_ui(chatbot=chatbot, history=history)
if validate_key() is False:
yield from update_ui_lastest_msg(lastmsg="[Local Message] 请配置ZHIPUAI_API_KEY", chatbot=chatbot, history=history, delay=0)
return
if additional_fn is not None:
from core_functional import handle_core_functionality
inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot)
# 开始接收回复
from .com_zhipuapi import ZhipuRequestInstance
sri = ZhipuRequestInstance()
for response in sri.generate(inputs, llm_kwargs, history, system_prompt):
chatbot[-1] = (inputs, response)
yield from update_ui(chatbot=chatbot, history=history)
# 总结输出
if response == f"[Local Message] 等待{model_name}响应中 ...":
response = f"[Local Message] {model_name}响应异常 ..."
history.extend([inputs, response])
yield from update_ui(chatbot=chatbot, history=history)

View File

@@ -64,6 +64,7 @@ class SparkRequestInstance():
self.api_key = XFYUN_API_KEY self.api_key = XFYUN_API_KEY
self.gpt_url = "ws://spark-api.xf-yun.com/v1.1/chat" self.gpt_url = "ws://spark-api.xf-yun.com/v1.1/chat"
self.gpt_url_v2 = "ws://spark-api.xf-yun.com/v2.1/chat" self.gpt_url_v2 = "ws://spark-api.xf-yun.com/v2.1/chat"
self.gpt_url_v3 = "ws://spark-api.xf-yun.com/v3.1/chat"
self.time_to_yield_event = threading.Event() self.time_to_yield_event = threading.Event()
self.time_to_exit_event = threading.Event() self.time_to_exit_event = threading.Event()
@@ -87,6 +88,8 @@ class SparkRequestInstance():
def create_blocking_request(self, inputs, llm_kwargs, history, system_prompt): def create_blocking_request(self, inputs, llm_kwargs, history, system_prompt):
if llm_kwargs['llm_model'] == 'sparkv2': if llm_kwargs['llm_model'] == 'sparkv2':
gpt_url = self.gpt_url_v2 gpt_url = self.gpt_url_v2
elif llm_kwargs['llm_model'] == 'sparkv3':
gpt_url = self.gpt_url_v3
else: else:
gpt_url = self.gpt_url gpt_url = self.gpt_url
@@ -168,6 +171,11 @@ def gen_params(appid, inputs, llm_kwargs, history, system_prompt):
""" """
通过appid和用户的提问来生成请参数 通过appid和用户的提问来生成请参数
""" """
domains = {
"spark": "general",
"sparkv2": "generalv2",
"sparkv3": "generalv3",
}
data = { data = {
"header": { "header": {
"app_id": appid, "app_id": appid,
@@ -175,7 +183,7 @@ def gen_params(appid, inputs, llm_kwargs, history, system_prompt):
}, },
"parameter": { "parameter": {
"chat": { "chat": {
"domain": "generalv2" if llm_kwargs['llm_model'] == 'sparkv2' else "general", "domain": domains[llm_kwargs['llm_model']],
"temperature": llm_kwargs["temperature"], "temperature": llm_kwargs["temperature"],
"random_threshold": 0.5, "random_threshold": 0.5,
"max_tokens": 4096, "max_tokens": 4096,

View File

@@ -0,0 +1,67 @@
from toolbox import get_conf
import threading
import logging
timeout_bot_msg = '[Local Message] Request timeout. Network error.'
class ZhipuRequestInstance():
def __init__(self):
self.time_to_yield_event = threading.Event()
self.time_to_exit_event = threading.Event()
self.result_buf = ""
def generate(self, inputs, llm_kwargs, history, system_prompt):
# import _thread as thread
import zhipuai
ZHIPUAI_API_KEY, ZHIPUAI_MODEL = get_conf("ZHIPUAI_API_KEY", "ZHIPUAI_MODEL")
zhipuai.api_key = ZHIPUAI_API_KEY
self.result_buf = ""
response = zhipuai.model_api.sse_invoke(
model=ZHIPUAI_MODEL,
prompt=generate_message_payload(inputs, llm_kwargs, history, system_prompt),
top_p=llm_kwargs['top_p'],
temperature=llm_kwargs['temperature'],
)
for event in response.events():
if event.event == "add":
self.result_buf += event.data
yield self.result_buf
elif event.event == "error" or event.event == "interrupted":
raise RuntimeError("Unknown error:" + event.data)
elif event.event == "finish":
yield self.result_buf
break
else:
raise RuntimeError("Unknown error:" + str(event))
logging.info(f'[raw_input] {inputs}')
logging.info(f'[response] {self.result_buf}')
return self.result_buf
def generate_message_payload(inputs, llm_kwargs, history, system_prompt):
conversation_cnt = len(history) // 2
messages = [{"role": "user", "content": system_prompt}, {"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_gpt_answer = {}
what_gpt_answer["role"] = "assistant"
what_gpt_answer["content"] = history[index+1]
if what_i_have_asked["content"] != "":
if what_gpt_answer["content"] == "":
continue
if what_gpt_answer["content"] == timeout_bot_msg:
continue
messages.append(what_i_have_asked)
messages.append(what_gpt_answer)
else:
messages[-1]['content'] = what_gpt_answer['content']
what_i_ask_now = {}
what_i_ask_now["role"] = "user"
what_i_ask_now["content"] = inputs
messages.append(what_i_ask_now)
return messages

View File

@@ -0,0 +1,29 @@
import random
def Singleton(cls):
_instance = {}
def _singleton(*args, **kargs):
if cls not in _instance:
_instance[cls] = cls(*args, **kargs)
return _instance[cls]
return _singleton
@Singleton
class OpenAI_ApiKeyManager():
def __init__(self, mode='blacklist') -> None:
# self.key_avail_list = []
self.key_black_list = []
def add_key_to_blacklist(self, key):
self.key_black_list.append(key)
def select_avail_key(self, key_list):
# select key from key_list, but avoid keys also in self.key_black_list, raise error if no key can be found
available_keys = [key for key in key_list if key not in self.key_black_list]
if not available_keys:
raise KeyError("No available key found.")
selected_key = random.choice(available_keys)
return selected_key

Some files were not shown because too many files have changed in this diff Show More