Compare commits

...

670 Commits

Author SHA1 Message Date
imClumsyPanda
8f4e62ad5b
Update README.md 2024-06-12 16:17:25 +08:00
imClumsyPanda
2123569598
Add files via upload 2024-06-12 16:16:48 +08:00
zR
3ecff4bce7
Merge pull request #3966 from yhfgyyf/glm-4-stream
修复glm-4 无法流式输出的bug
2024-06-08 16:34:58 +08:00
ChillWay
4cd8d0e97c
Update test_different_splitter.py (#3887)
fix path error
2024-05-29 22:11:28 +08:00
Selfuppen
200f9fb481
Update 大模型应用技术原理.md (#3873)
Fixed a spelling error:
juava -> java
2024-05-29 22:10:39 +08:00
imClumsyPanda
1ab62ad339
Update README.md 2024-05-29 17:46:06 +08:00
imClumsyPanda
7cb8b96ed5
Add files via upload 2024-05-29 17:45:45 +08:00
af su
b9827529aa
fix: incorrect variable usage in update_doc_by_ids method (#4048)
Co-authored-by: saf <saf@zjuici.com>
2024-05-20 14:44:02 +08:00
liunux4odoo
8ca9e8ff28
replace Path.is_relative_to to make py38 compatible (#4029) 2024-05-16 11:06:22 +08:00
liunux4odoo
ede538bfe2
update "path traversal bug in api /knowledge_base/download_doc(#4008)… (#4017)
* Revert "path traversal bug in api /knowledge_base/download_doc(#4008) (#4009)"

This reverts commit 2c146aff74bac427f0a4921971d8472097410bdf.

* Update utils.py
2024-05-14 18:48:55 +08:00
liunux4odoo
2c146aff74
path traversal bug in api /knowledge_base/download_doc(#4008) (#4009)
close #4008
2024-05-14 09:46:19 +08:00
imClumsyPanda
703d0f6aa7
Update README.md 2024-05-09 17:19:13 +08:00
imClumsyPanda
8e2515f768
Add files via upload 2024-05-09 17:18:50 +08:00
yhfgyyf
d9323ea3f6 修复glm-4 无法流式输出的bug 2024-05-08 15:05:00 +08:00
zR
24faba561b
Merge pull request #3203 from qqlww1987/master
百川调用示例
2024-05-01 16:49:50 +08:00
zR
cbc28d7296
Merge pull request #3912 from pearjelly/master
修复zhipu-api向量化失败问题
2024-05-01 16:49:24 +08:00
imClumsyPanda
f9beb142c8
Update README.md 2024-04-30 14:57:54 +08:00
imClumsyPanda
781b782f73
Add files via upload 2024-04-30 14:57:37 +08:00
hxb
160f0b8af4
Merge branch 'chatchat-space:master' into master 2024-04-28 16:15:31 +08:00
hxb
26672ffeda feature:长文档循环处理texts时,增加重试极致,降低单片文档失败导致整个文档向量化失败的概率 2024-04-28 16:14:31 +08:00
hxb
0078cdc724 bugfix: 使用向量计算方式METRIC_INNER_PRODUCT时启用normalize_L2会导致向量化失败 2024-04-28 16:12:23 +08:00
An0nymous
9c0820c94a
更新火山方舟调用 (#3564)
* 更新火山方舟调用
2024-04-25 14:33:28 +08:00
imClumsyPanda
cf049511cf
Update README.md 2024-04-25 13:56:39 +08:00
imClumsyPanda
c52e89d92a
Add files via upload 2024-04-25 13:56:17 +08:00
做梦好啊
2c7feae7bb
Update README.md (#3804) 2024-04-18 20:51:40 +08:00
imClumsyPanda
52f2a2a046
Update requirements.txt 2024-04-18 11:36:48 +08:00
yuehua-s
9bf0612e3d
Feat/action update readme (#3779) 2024-04-17 09:59:54 +08:00
yuehua-s
7da7636abc
feat:support action update Readme (#3773) 2024-04-16 23:19:56 +08:00
imClumsyPanda
326a9652aa
Update README.md 2024-04-16 14:23:02 +08:00
imClumsyPanda
b6e1f208e9
Add files via upload 2024-04-16 14:22:41 +08:00
yuehua-s
4815a6c92e
fix:fix model_config claude-api (#3760)
Co-authored-by: yuehuazhang <yuehuazhang@tencent.com>
2024-04-16 09:56:11 +08:00
Art Jiang
448e79576c
Adding Claude 3 API support (#3340)
---------

Co-authored-by: Jiang, Fengyi <art.jiang@gatech.edu>
2024-04-16 08:32:48 +08:00
liunux4odoo
3902f6d235
Merge pull request #3574 from dengpeng777/master
support zhipu-api embedding
2024-04-16 07:10:24 +08:00
yuehua-s
72a6878287
Feat/update actions (#3758) 2024-04-16 06:35:20 +08:00
yuehua-s
5eb37ea2e3
Feat/git action (#3745) 2024-04-15 23:29:30 +08:00
saliven1970
f29ab1e67f
修复获取reranker_model_path出错的问题 (#3458) 2024-04-15 21:53:06 +08:00
Qinyu Luo
341ee9db44
Generate repository-level Chinese code documentation by RepoAgent. (#3108) 2024-04-15 21:51:13 +08:00
你的代码TT
2f2221ca47
Add document normalization in Chroma. (#3640) 2024-04-15 21:37:32 +08:00
allseeeeeee
6d128f24f0
fix: 以lite模式启动时仅加载了在线嵌入模型,未加载配置的默认嵌入模型,导致创建知识库时报错 'bge-large-zh-v1.5' is not in list. (#3670)
修复方式: 如果lite模式启动, 配置的默认嵌入模型也添加到列表

Co-authored-by: LuoJingtian <luojingtian@siiture.com>
2024-04-15 21:29:40 +08:00
imClumsyPanda
8721aad18d
Update README.md 2024-04-11 15:16:07 +08:00
imClumsyPanda
13377191e7
Add files via upload 2024-04-11 15:15:43 +08:00
yuehua-s
110b5694da
Feat/docker v0.2.10 (#3664)
* feat:update docker image to v0.2.10.

* feat:update docker image to v0.2.10.

---------

Co-authored-by: yuehuazhang <yuehuazhang@tencent.com>
2024-04-08 10:29:16 +08:00
jinke
da1c1a225c add docker registries 2024-04-08 01:15:10 +08:00
jinke
5eb025d9dc update docker aliyun mirror to 0.2.10
update docker aliyun mirror to 0.2.10
2024-04-08 00:30:40 +08:00
imClumsyPanda
6003d8dd83
Update README.md 2024-04-07 13:07:26 +08:00
imClumsyPanda
b0f5fb2d3e
Add files via upload 2024-04-07 13:07:00 +08:00
imClumsyPanda
6dd066ca72
Update README.md 2024-04-02 15:50:11 +08:00
imClumsyPanda
c0dafb95cc
Add files via upload 2024-04-02 15:49:55 +08:00
RoceoRobin
487235259e
Update README.md (#3585)
错别字
2024-04-01 13:17:02 +08:00
dengpeng777
a592b1cd3f
fix add default embed model 2024-03-30 10:00:55 +08:00
dengpeng777
6011bac07f
support zhipu-api embedding 2024-03-30 09:58:18 +08:00
imClumsyPanda
ae9f4d208e
Add files via upload 2024-03-29 21:53:01 +08:00
imClumsyPanda
78290d360f
Update README.md 2024-03-29 21:44:54 +08:00
imClumsyPanda
966c582a2a
Update README.md 2024-03-26 12:48:14 +08:00
imClumsyPanda
bfb76faadb
Add files via upload 2024-03-26 12:46:59 +08:00
imClumsyPanda
40263dd403
Update README.md 2024-03-22 14:38:30 +08:00
imClumsyPanda
825e4976ae
Add files via upload 2024-03-22 14:37:40 +08:00
iimm
253d4b9b9a
修复使用pgvector时get_doc_by_ids方法报错的bug及知识库文件删除后向量仍然存在的bug (#3407)
* 修复使用pgvector无法查询到document

* 修复使用pg/es向量库无法知识库删除文档后向量库并未删除对应记录的bug
2024-03-20 08:41:41 +08:00
BlizBearer
07b7c966ed
Dev fix csv loader (#3404)
* fix: csv loader only load one column

* csv data merge with col name
2024-03-20 08:40:22 +08:00
imClumsyPanda
d78b14721c
Update README.md 2024-03-19 13:04:40 +08:00
imClumsyPanda
5ad4d520dd
Add files via upload 2024-03-19 13:04:18 +08:00
imClumsyPanda
d879e86cab
Update README.md 2024-03-12 09:21:42 +08:00
imClumsyPanda
cd54eeb137
Add files via upload 2024-03-12 09:21:13 +08:00
imClumsyPanda
021d635af0
Update README.md 2024-03-06 20:20:51 +08:00
imClumsyPanda
f40d415f07
Add files via upload 2024-03-06 20:20:30 +08:00
qqlww1987
7198654611 Merge branch 'master' of https://github.com/qqlww1987/Langchain-Chatchat 2024-03-06 15:30:57 +08:00
qqlww1987
818f87b5e4 更新百川API示例
百川大模型API调用示例修改
2024-03-06 14:59:16 +08:00
qqlww1987
c6d91c3e3d
百川API示例处理
百川API调用示例
2024-03-06 14:14:06 +08:00
qqlww1987
5c74a28de9
Merge branch 'chatchat-space:master' into master 2024-03-06 14:11:57 +08:00
hollowdjj
e48f4a24c9
修复使用Milvus数据库时上传知识库文件报错的问题 (#3155)
milvus 返回的 Document.metadata 携带了 vector 信息,导致 API 接口序列化失败。

---------

Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
2024-03-06 08:46:46 +08:00
qqlww1987
279fe9c659
Merge pull request #1 from chatchat-space/master
百川API调用事例调整
2024-03-03 20:15:53 +08:00
imClumsyPanda
bab93690fc
Update README.md 2024-03-02 14:50:17 +08:00
imClumsyPanda
54bed50713
Add files via upload 2024-03-02 14:49:45 +08:00
imClumsyPanda
caf502d141
Update README.md 2024-02-28 09:57:20 +08:00
imClumsyPanda
76e82a9b8f
Add files via upload 2024-02-28 09:56:58 +08:00
imClumsyPanda
574ea4f4d5
Update README.md 2024-02-24 23:49:34 +08:00
imClumsyPanda
cf1c853b19
Add files via upload 2024-02-24 23:49:09 +08:00
imClumsyPanda
fb8fbe96e4
Update README.md 2024-02-21 11:51:52 +08:00
imClumsyPanda
7c89f88513
Add files via upload 2024-02-21 11:51:24 +08:00
imClumsyPanda
1fa714ee71
Update README.md 2024-02-19 14:56:49 +08:00
imClumsyPanda
b2fabe211b
Update README.md 2024-02-19 12:10:44 +08:00
imClumsyPanda
d5edb08b24
Add files via upload 2024-02-19 12:10:24 +08:00
ai松柏君
051c599bb5
requirements_webui.txt (#2960) 2024-02-07 10:21:42 +08:00
zR
cd13aee97d
Merge pull request #2958 from chatchat-space/dev
更新readme
2024-02-07 00:28:04 +08:00
zR
8146279bbe
Merge pull request #2957 from zRzRzRzRzRzRzR/dev
更新readme
2024-02-07 00:27:30 +08:00
zR
c49c6923a1 更新readme 2024-02-07 00:26:58 +08:00
zR
041e964b30
Merge pull request #2949 from criwits/dev
增加对 `.htm` 扩展名的显式支持,以解决 `.htm` 格式网页可被上传但不被入库的问题
2024-02-07 00:22:53 +08:00
imClumsyPanda
f75ae3ea5f
Update README.md 2024-02-06 19:51:54 +08:00
imClumsyPanda
0522a42ab7
Add files via upload 2024-02-06 19:51:33 +08:00
Hans WAN
5460b93ba2
增加对 .htm 扩展名的显式支持 2024-02-06 16:28:41 +08:00
zR
ab650253d1
Merge pull request #2946 from chatchat-space/dev
Dev
2024-02-06 13:52:55 +08:00
zR
670131c886
Merge pull request #2945 from zRzRzRzRzRzRzR/dev
更新zhipuai请求方式
2024-02-06 13:51:43 +08:00
zR
2756996125 更新zhipuai请求方式 2024-02-06 13:50:57 +08:00
zR
f04a2bfcc7
Merge pull request #2919 from fengyaojieTTT/bugfix/es-document-query
修复es 知识库查询bug (#2848)
2024-02-06 12:25:56 +08:00
fengyaojie
9c5aa5bf2f 修复es 知识库查询bug (#2848) 2024-02-05 16:28:23 +08:00
fengyaojie
36956520ea 修复es 知识库查询bug (#2848) 2024-02-03 18:01:54 +08:00
imClumsyPanda
4f67f4a841
Update README.md 2024-02-01 10:00:14 +08:00
imClumsyPanda
e042a76f11
Add files via upload 2024-02-01 09:59:44 +08:00
zR
13628c5f9a
Merge pull request #2871 from chatchat-space/master
merege
2024-01-30 21:39:30 +08:00
zR
5afbae56fc
Merge pull request #2870 from chatchat-space/dev
更新星火大模型
2024-01-30 21:38:49 +08:00
zR
2504ea3393
Merge pull request #2869 from zRzRzRzRzRzRzR/dev
支持星火3.5模型
2024-01-30 21:37:55 +08:00
zR
07906751c1 支持星火3.5模型 2024-01-30 21:37:29 +08:00
zqt996
b7a249f46a
Merge pull request #2868 from zqt996/master
修复milvus相关bug
2024-01-30 21:33:18 +08:00
zqt
cbfbbe5e6b 修复milvus相关bug 2024-01-30 21:28:42 +08:00
imClumsyPanda
845adfbc0b
Update README.md 2024-01-30 16:51:03 +08:00
imClumsyPanda
53ff5040e2
Update README.md 2024-01-30 16:50:35 +08:00
imClumsyPanda
77914386b0
Update README.md 2024-01-30 16:50:07 +08:00
zR
03edc3e501
Merge pull request #2858 from chatchat-space/dev
修复部分0.2.10的问题
2024-01-30 14:28:55 +08:00
zR
3f70a0d18c
Merge pull request #2857 from zRzRzRzRzRzRzR/dev
autodl代号错误修复
2024-01-30 14:28:05 +08:00
zR
b0708c7a8d
Merge branch 'chatchat-space:dev' into dev 2024-01-30 14:27:36 +08:00
zR
887cf95db7 autodl代号错误 2024-01-30 14:27:09 +08:00
zR
b39b585867
Merge pull request #2856 from zRzRzRzRzRzRzR/dev
更新掉部分错误的依赖
2024-01-30 14:19:14 +08:00
zR
042a70c09a 更新了chromadb的打印的符号 2024-01-30 14:18:14 +08:00
zR
ffbfcd41f2 API前端丢失问题解决 2024-01-30 13:43:16 +08:00
zR
22ee1a0c97
Merge pull request #2816 from songpb/master
修复PDF旋转的BUG (Issues #2792)
2024-01-30 13:01:24 +08:00
songpb
4157201c2c
Merge branch 'dev' into master 2024-01-30 12:42:28 +08:00
zR
6eab501baf
Merge pull request #2843 from zRzRzRzRzRzRzR/dev
更新文件
2024-01-29 21:18:06 +08:00
zR
268bb68122 更新文件 2024-01-29 21:17:10 +08:00
zR
4f5824e964
Merge pull request #2820 from showmecodett/feat-chromadb
支持Chroma向量数据库
2024-01-29 20:59:15 +08:00
tonysong
25f5f103c1 忽略测试代码 2024-01-29 10:03:28 +08:00
showmecodett
0c465faf8b perf delete unused import 2024-01-29 06:09:59 +08:00
showmecodett
c94938bc83 Support Chroma 2024-01-29 05:52:52 +08:00
songpb
147b4c0688
Merge branch 'master' into master 2024-01-28 16:28:28 +08:00
tonysong
e1e8b0f056 修复PDF旋转的BUG 2024-01-28 16:22:57 +08:00
imClumsyPanda
38bc4050ac
Update README.md 2024-01-26 21:11:54 +08:00
imClumsyPanda
ae31e6dd8b
Add files via upload 2024-01-26 21:11:31 +08:00
glide-the
e1f125be4e
Merge pull request #2809 from chatchat-space/glide-the-patch-1
Update README.md
2024-01-26 19:50:15 +08:00
glide-the
597ca146d0
Update README.md 2024-01-26 19:50:06 +08:00
liunux4odoo
9c525b7fa5
publish 0.2.10 (#2797)
新功能:
- 优化 PDF 文件的 OCR,过滤无意义的小图片 by @liunux4odoo #2525
- 支持 Gemini 在线模型 by @yhfgyyf #2630
- 支持 GLM4 在线模型 by @zRzRzRzRzRzRzR
- elasticsearch更新https连接 by @xldistance #2390
- 增强对PPT、DOC知识库文件的OCR识别 by @596192804 #2013
- 更新 Agent 对话功能 by @zRzRzRzRzRzRzR
- 每次创建对象时从连接池获取连接,避免每次执行方法时都新建连接 by @Lijia0 #2480
- 实现 ChatOpenAI 判断token有没有超过模型的context上下文长度 by @glide-the
- 更新运行数据库报错和项目里程碑 by @zRzRzRzRzRzRzR #2659
- 更新配置文件/文档/依赖 by @imClumsyPanda @zRzRzRzRzRzRzR
- 添加日文版 readme by @eltociear #2787

修复:
- langchain 更新后,PGVector 向量库连接错误 by @HALIndex #2591
- Minimax's model worker 错误 by @xyhshen 
- ES库无法向量检索.添加mappings创建向量索引 by MSZheng20 #2688
2024-01-26 06:58:49 +08:00
liunux4odoo
a5e758bf82 fix: set default score_threshold to 1; add weather api key to kb_config 2024-01-25 22:50:22 +08:00
Ikko Eltociear Ashimine
370dbfef37 Add README_ja.md (#2787) 2024-01-25 22:50:21 +08:00
imClumsyPanda
1c3b928223 Update README.md 2024-01-25 22:50:16 +08:00
imClumsyPanda
454d82b2e4 Add files via upload 2024-01-25 22:49:16 +08:00
Ikko Eltociear Ashimine
ee6a28b565
Add README_ja.md (#2787) 2024-01-25 22:17:07 +08:00
zR
f50400a204
Merge pull request #2782 from zRzRzRzRzRzRzR/dev
Dev
2024-01-24 17:04:10 +08:00
zR
852ca5f849 更新两行注释 2024-01-24 15:57:04 +08:00
zR
f9a5ae99ee 更新了部分依赖 2024-01-24 15:28:34 +08:00
liunux4odoo
7248163b07 调整依赖;优化webui模型列表;更新wiki版本 2024-01-23 13:11:15 +08:00
imClumsyPanda
60d5f7d439 update req 2024-01-22 23:29:06 +08:00
zR
088a27df27
Merge pull request #2759 from zRzRzRzRzRzRzR/dev
更新依赖错误
2024-01-22 20:47:10 +08:00
zR
481d1c4b3a
Merge branch 'chatchat-space:dev' into dev 2024-01-22 20:46:47 +08:00
zR
6df6ed2920 修复错误依赖 2024-01-22 20:46:34 +08:00
zR
57c73b1424 更新错误的依赖 2024-01-22 20:46:04 +08:00
imClumsyPanda
c9c867664e
Update README.md 2024-01-22 15:09:34 +08:00
imClumsyPanda
65a2ccdc64
Add files via upload 2024-01-22 15:09:13 +08:00
zR
31631e56ca
Merge pull request #2753 from zRzRzRzRzRzRzR/dev
细节更新和补充
2024-01-22 13:43:56 +08:00
zR
56d32a9908 删除掉一些没用的注释,已经不需要todo了 2024-01-22 13:42:52 +08:00
zR
1adff316e5 更新了最新的整理好的依赖 2024-01-22 13:37:48 +08:00
zR
c50e988f5a readme更新 2024-01-22 13:24:11 +08:00
zR
85771825ba 更新readme 2024-01-22 13:18:46 +08:00
zR
54e5b41647
Merge pull request #2752 from zRzRzRzRzRzRzR/dev
gemini API 修复
2024-01-22 13:15:06 +08:00
zR
17803cb7c1 gemini api 修复调用 2024-01-22 13:14:13 +08:00
zR
64378837ef
Merge pull request #2751 from zRzRzRzRzRzRzR/dev
恢复 删除知识库选项
2024-01-22 12:47:05 +08:00
zR
b6d2bc71ce 恢复 删除知识库选项 2024-01-22 12:46:15 +08:00
zR
fb6c84bc57
Merge pull request #2749 from zRzRzRzRzRzRzR/dev
配置文件修改
2024-01-22 12:17:07 +08:00
zR
80c26e4a24 Merge branch 'dev' of https://github.com/zRzRzRzRzRzRzR/Langchain-Chatchat into dev 2024-01-22 12:16:13 +08:00
zR
eeba2e2665 配置文件修改 2024-01-22 12:15:47 +08:00
zR
c0968fb581
Merge pull request #2746 from zRzRzRzRzRzRzR/dev
支持GLM4
2024-01-22 11:48:43 +08:00
zR
8483c0bc96 Merge branch 'dev' of https://github.com/zRzRzRzRzRzRzR/Langchain-Chatchat into dev 2024-01-22 11:48:16 +08:00
zR
6b61d917a1 支持GLM4 2024-01-22 11:48:13 +08:00
zR
8ac255fc55
Merge branch 'chatchat-space:dev' into dev 2024-01-22 11:46:46 +08:00
zR
56c2a70a74
Merge pull request #2740 from showmecodett/perf-typing
perf typing
2024-01-22 10:46:46 +08:00
showmecodett
71deed93df perf typing 2024-01-21 21:00:12 +08:00
showmecodett
3057c29e47 perf typing 2024-01-21 20:56:26 +08:00
zR
554d6b4820 依赖文件删除,智谱AI 0.2.x 不兼容 2024-01-21 11:50:30 +08:00
zR
e5b4bb41d8 更新GLM 临时解决方案,支持GLM4,版本不兼容,会有bug 2024-01-21 11:48:44 +08:00
zR
0cf65d5933 更新模型配置文件和支持列表 2024-01-20 22:40:31 +08:00
zR
8c2019f8b9 pr 2775 maybe need? 2024-01-20 22:20:02 +08:00
zR
4a77880ee1 Merge branch 'dev' of https://github.com/zRzRzRzRzRzRzR/Langchain-Chatchat into dev 2024-01-20 22:18:25 +08:00
zR
dc07cba1d4 更新依赖 2024-01-20 22:18:22 +08:00
zR
b058e1906f
Merge pull request #2704 from MSZheng20/dev
1、ES库index_name获取兼容windows和linux系统 2、补充mappings,创建向量索引结构保持一致 3、添加ES测试方法
2024-01-18 13:11:56 +08:00
zhengmingsheng
2ab944996e fix:1、index_name获取兼容windows和linux系统 2、补充mappings,创建向量索引结构保持一致 3、添加ES向量库的测试方法 2024-01-18 11:25:27 +08:00
zR
e5acf3d2e6
Merge pull request #2688 from MSZheng20/dev
fix:修复ES库无法向量检索.添加mappings创建向量索引
2024-01-17 13:22:13 +08:00
zR
1b5efecc89
Merge pull request #2681 from Lijia0/adapter_pgvector
修复bug-langchain新版本PGVector传入connection,插入、删除操作会回滚
2024-01-17 13:22:01 +08:00
zhengmingsheng
b2ea386f60 fix:修复ES库无法使用向量检索.添加mappings创建向量索引 2024-01-17 11:24:13 +08:00
imClumsyPanda
d83de508cc
Update README.md 2024-01-17 10:27:18 +08:00
imClumsyPanda
0a4dfe58a4
Add files via upload 2024-01-17 10:26:58 +08:00
lijia
2c92cd00ae langchain新版本PGVector传入connection,插入、删除操作会回滚 2024-01-16 16:58:19 +08:00
lijia
67ae61d567 langchain新版本PGVector传入connection,插入、删除操作会回滚 2024-01-16 16:38:06 +08:00
zR
cb3822651b
Merge pull request #2659 from zRzRzRzRzRzRzR/dev
更新运行数据库报错和项目里程碑
2024-01-14 10:47:40 +08:00
zR
241690d593 更新运行数据库报错和项目里程碑 2024-01-14 10:46:41 +08:00
zR
f28cd59557
Merge pull request #2648 from xyhshen/patch-1
Fix two bugs in Minimax's model worker that affect usage
2024-01-13 16:37:05 +08:00
glide-the
991e824bcd
Merge pull request #2649 from glide-the/dev
ChatOpenAI为了判断token有没有超过模型的context上下文长度,
2024-01-13 16:12:43 +08:00
glide-the
f031ebc19e ChatOpenAI为了判断token有没有超过模型的context上下文长度,每个模型的token算法不一样 ,所以这里应该自己实现token长度计算
第一次初始化的时候,openai的类会强制使用3.5,
2024-01-13 16:11:30 +08:00
xieyh
ebda1056e5
Fix two bugs in Minimax's model worker that affect usage, namely do_ Embeddings should return result for multiple documents, and the other option is validate_ Messages, 'role': 'user' should be the uppercase letter 'USER' 2024-01-13 15:44:26 +08:00
zR
0a37fe93b8
Merge pull request #2647 from zRzRzRzRzRzRzR/dev
更新即将废弃的启动内容
2024-01-13 13:00:58 +08:00
zR
6df4554c8b 更新即将废弃的启动内容 2024-01-13 13:00:01 +08:00
Zhi-guo Huang
3e959e5b0f
Merge pull request #2640 from chatchat-space/hzg0601-patch-1
Update milvus_kb_service.py
2024-01-12 16:58:44 +08:00
Zhi-guo Huang
e55f8cf7a9
Update milvus_kb_service.py
修复typo
2024-01-12 16:58:32 +08:00
zR
c5985ae5be
Merge pull request #2638 from zRzRzRzRzRzRzR/dev
0.2.10 Agent更新
2024-01-12 12:50:12 +08:00
zR
3333007e13
Merge branch 'chatchat-space:dev' into dev 2024-01-12 12:45:37 +08:00
Lijia0
ff91508d8b
每次创建对象时从连接池获取连接,避免每次执行方法时都新建连接 (#2480) 2024-01-12 12:34:40 +08:00
zR
4ac510ff4a 版本更新 2024-01-12 12:02:34 +08:00
zR
269090ea66 更新0.2.x Agent,之后的Agent在0.3.x更新 2024-01-12 12:01:22 +08:00
Creation
75ff268e88
【功能新增】增强对PPT、DOC知识库文件的OCR识别 (#2013)
* 【功能新增】增强对PPT、DOC文件的OCR识别

* 【功能新增】增强对PPT、DOC文件的OCR识别

* Update mydocloader.py

---------

Co-authored-by: zR <2448370773@qq.com>
2024-01-12 11:04:50 +08:00
zR
e615932e7e Merge branch 'master' into dev 2024-01-12 10:27:15 +08:00
xldistance
a5b52e1bd1
elasticsearch更新https连接 (#2390) 2024-01-12 10:17:28 +08:00
HALIndex
29ef5dda64
Update pgvector connection method following updates in langchain_community, to resolve the 'PGVector' object has no attribute 'connect' error. (#2591) 2024-01-12 10:17:04 +08:00
yhfgyyf
03eb5e9d2e
Gemini api (#2630)
* Gemini-pro api

* Update gemini.py

* Update gemini.py
2024-01-12 10:16:31 +08:00
zR
4f07384c66
0.2.x稳定依赖更新 (#2627)
0.2.x不会支持langchain 0.1.x以上的内容
2024-01-11 19:58:25 +08:00
天地
3da68b5ce3
删除重复的引入和纠正拼写错误 (#2599)
* 1.删除重复的引入
2.拼写错误

* 1.参数或者文档拼写错误纠正
2.doc下的faq、install已经删除,更新为ES部署指南,考虑到doc下的文档经常更新,即使扫描doc文件夹,也可能为空的情况,readme.md大概率不会删除。
2024-01-11 18:45:09 +08:00
chatgpt-bot
b653c25fbc
Fix device detection and fallback logic and add 'xpu' (#2570)
Co-authored-by: zR <2448370773@qq.com>
2024-01-11 18:36:38 +08:00
高厉害
e7bba6bd0a
fix: automatically replace unsupported torch device (#2514) 2024-01-11 18:16:31 +08:00
imClumsyPanda
b5064813af
Update README.md 2024-01-11 15:06:59 +08:00
imClumsyPanda
01bac077bc
Add files via upload 2024-01-11 15:06:35 +08:00
liunux4odoo
448c99f969
fix: 过滤 sse_starlette 返回的 ping 包,避免 JSON Decoder error : ping -... (#2585) 2024-01-09 09:14:29 +08:00
imClumsyPanda
6f85119f03
Update README.md 2024-01-07 21:59:06 +08:00
imClumsyPanda
440307fa94
Add files via upload 2024-01-07 21:58:35 +08:00
liunux4odoo
17e8bc072b
fix: make_text_splitter use wrong chunk_* parameters when exception. (close #2561) (#2564) 2024-01-05 15:06:59 +08:00
liunux4odoo
67034669a9 Merge branch 'panda-master' into panda-dev 2024-01-05 15:05:38 +08:00
Zhi-guo Huang
3d66899b0f
Merge pull request #2540 from chatchat-space/hzg0601-patch-1
修复milvus_kwargs问题
2024-01-03 17:14:48 +08:00
Zhi-guo Huang
ce29d14f46
修复milvus_kwargs问题 2024-01-03 17:14:38 +08:00
imClumsyPanda
50aeb24582
Update README.md 2024-01-03 15:30:24 +08:00
imClumsyPanda
fc75c4513a
Add files via upload 2024-01-03 15:30:02 +08:00
liunux4odoo
aeb7a7e93f
增加 PDF_OCR_THRESHOLD 配置项,只对宽高超过页面一定比例(图片宽/页面宽,图片高/页面高)的图片进行 OCR。 (#2525)
这样可以避免 PDF 中一些小图片的干扰,提高非扫描版 PDF 处理速度
2024-01-02 16:28:36 +08:00
liunux4odoo
61bc815540
fix: Chinese comma in requirements (#2523) 2024-01-02 11:26:03 +08:00
liunux4odoo
7d4a6b5edf
fix: ApiRequest.agent_chat 应当返回 dict 而非 str (#2520) 2024-01-02 09:54:23 +08:00
imClumsyPanda
3c33ca7b89 Release v0.2.9 2023-12-31 20:15:35 +08:00
imClumsyPanda
f1ae95c8ca fix typos 2023-12-31 20:14:01 +08:00
imClumsyPanda
719e2713ed fix typos 2023-12-31 20:13:14 +08:00
imClumsyPanda
349de9b955 Merge branch 'master' into dev 2023-12-31 19:25:01 +08:00
imClumsyPanda
e6c376fba0 update pics 2023-12-31 19:24:42 +08:00
liunux4odoo
c179230ce0
remove /chat/fastchat API endpoint (#2506) 2023-12-29 09:44:37 +08:00
liunux4odoo
3b28f40c6a update requirements: 统一各文件依赖顺序,便于比对;移出streamlit-antd-components; jq默认安装; numexpr 限定 2.8.6 以兼容 py38 2023-12-29 09:35:02 +08:00
liunux4odoo
5cccd5e7aa merge from master 2023-12-29 09:10:01 +08:00
imClumsyPanda
af38f75b29
Update README.md 2023-12-28 15:50:30 +08:00
imClumsyPanda
a8f94dd595
Add files via upload 2023-12-28 15:49:59 +08:00
liunux4odoo
1f3a32ebaf
fix Yi-34b model config error(close #2491) (#2492) 2023-12-28 07:57:25 +08:00
liunux4odoo
9ff7bef2c2
新功能:知识库管理界面支持查看、编辑、删除向量库文档 (#2471)
* 新功能:
- 知识库管理界面支持查看、编辑、删除向量库文档。暂不支持增加(aggrid添加新行比较麻烦,需要另外实现)
- 去除知识库管理界面中重建知识库和删除知识库按钮,建议用户到终端命令操作

修复:
- 所有与知识库名称、文件名称有关的数据库操作函数都改成大小写不敏感,所有路径统一为 posix 风格,避免因路径文本不一致导致数据重复和操作失效 (close #2232)

开发者:
- 添加 update_docs_by_id 函数与 API 接口。当前仅支持 FAISS,暂时未用到,未将来对知识库做更细致的修改做准备
- 统一 DocumentWithScore 与 DocumentWithVsId
- FAISS 返回的 Document.metadata 中包含 ID, 方便后续查找比对
- /knowledge_base/search_docs 接口支持 file_name, metadata 参数,可以据此检索文档

* fix bug
2023-12-26 13:44:36 +08:00
zR
2e1442a5c1 修复 Langchain 更新之后OpenAI在线embed无法正常使用问题 2023-12-23 11:36:11 +08:00
liunux4odoo
4e5bc8b399 修复: zhipu-api 请求出错时返回准确的错误信息 2023-12-22 10:17:00 +08:00
imClumsyPanda
4e69033d33
Update README.md 2023-12-21 22:19:41 +08:00
imClumsyPanda
778d2d906a
Add files via upload 2023-12-21 22:19:12 +08:00
Zhi-guo Huang
d77f778e0d
Merge pull request #2435 from chatchat-space/reranker
新增特性:使用Reranker模型对召回语句进行重排
2023-12-21 19:06:59 +08:00
hzg0601
129c765a74 新增特性:reranker对向量召回文本进行重排 2023-12-21 19:05:11 +08:00
hzg0601
5891f94c88 temporarily add reranker 2023-12-21 16:05:16 +08:00
Zhi-guo Huang
60510ff2f0
Update model_config.py.example 2023-12-20 13:33:00 +08:00
Funkeke
c1a32d9f1a
fix:使用在线embedding模型时 报错 There is no current event loop in thread 'Any… (#2393)
* fix:使用在线embedding模型时 报错 There is no current event loop in thread 'AnyIO worker thread'

* 动态配置在线embbding模型

---------

Co-authored-by: fangkeke <3339698829@qq.com>
2023-12-20 08:40:53 +08:00
liunux4odoo
fdea406101 update requirements: 统一各文件依赖顺序,便于比对;移出streamlit-antd-components; jq默认安装 2023-12-19 15:59:41 +08:00
imClumsyPanda
bba4754994
Update README.md 2023-12-18 15:21:27 +08:00
imClumsyPanda
9fdeb475e9
Add files via upload 2023-12-18 15:20:58 +08:00
huangzhiguo
a870076051 在model_config.py.example中增加qwen量化模型启动的说明 2023-12-15 14:23:34 +08:00
Astlvk
7e01e82470
fixed 迭代器参数传递错误,知识库问答报错TypeError: unhashable type: 'list' (#2383)
Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
2023-12-15 07:54:36 +08:00
xldistance
7e8391eb55
修复knowledge_base_chat_iterator传参错误 (#2386) 2023-12-15 07:53:36 +08:00
xldistance
332e1ccfaa
更新self.dims_length赋值错误 (#2380) 2023-12-14 19:56:39 +08:00
jaluik
e7410e40df
fix: 文档错误 (#2384) 2023-12-14 16:32:05 +08:00
imClumsyPanda
1cbad32b6e
Update README.md 2023-12-13 18:56:43 +08:00
imClumsyPanda
f45d6ab49c
Add files via upload 2023-12-13 18:56:20 +08:00
lookou
9c5b81cb2b
优化EventSource回包 (#1200)
通过 sse_startllete 支持 JS 前端 SSE 协议 (Close #2333) 

Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
2023-12-13 17:02:27 +08:00
liunux4odoo
472a97a616 所有 chat 接口都改为 EventSourceResponse;ApiRequest 作对应修改 2023-12-13 16:53:24 +08:00
liunux4odoo
c8fef3380c merge from dev 2023-12-13 16:52:40 +08:00
hzg0601
db008c1af8 为milvus增加额外索引与搜索配置 2023-12-13 15:52:11 +08:00
liunux4odoo
2604c9e761
fix: prompt template name error in file_chat (#2366) 2023-12-12 21:12:33 +08:00
hzg0601
95c09981a6 给出chatglm3-6b输出角色标签<|user|>等及自问自答的解决方案 2023-12-11 11:22:39 +08:00
hzg0601
db1c1e2ee4 解决多次调用es创建索引失败的问题 2023-12-11 10:39:59 +08:00
liunux4odoo
2e9319846e support .xls files 2023-12-08 15:04:08 +08:00
liunux4odoo
7b70776810 fix: doc ext name error in LOADER_DICT 2023-12-08 13:59:55 +08:00
imClumsyPanda
fdd6eb5f6d
Update README.md 2023-12-07 16:07:24 +08:00
imClumsyPanda
bcbeb9d8ac
Add files via upload 2023-12-07 16:07:00 +08:00
hzg0601
ad0b133ac8 解决faiss相似度阈值不在0-1之间的问题 2023-12-06 21:57:59 +08:00
hzg0601
4c2fda7200 Merge branch 'dev' of https://github.com/chatchat-space/Langchain-Chatchat into dev 2023-12-06 20:42:32 +08:00
hzg0601
d1f94c2846 temporarily add reranker 2023-12-06 20:42:27 +08:00
hzg0601
1fac51fe35 temporarily save faiss_cache 2023-12-06 09:45:56 +00:00
imClumsyPanda
6547005073
Update README.md 2023-12-04 22:43:20 +08:00
imClumsyPanda
5fe933fa44
Add files via upload 2023-12-04 22:42:49 +08:00
liunux4odoo
67b7c99d03
ocr 支持 GPU 加速(需要手动安装 rapidocr_paddle[gpu]);知识库支持 MHTML 和 Evernote 文件。 (#2265)
在 requirements 和 Wiki 中增加对可选文档加载器 SDK 的说明 ( close #2264 )
2023-12-04 09:39:56 +08:00
Ean Yang
cf65f44eb6
更新默认模型下载链接 (#2259) 2023-12-03 11:59:48 +08:00
liunux4odoo
7d2de47bcf
文件对话和知识库对话 API 接口实现全异步操作,防止阻塞 (#2256)
* EmbeddingFunAdapter 支持异步操作;文件对话和知识库对话 API 接口实现全异步操作,防止阻塞

* 修复: 使 list_files_from_folder 返回相对路径
2023-12-02 19:22:44 +08:00
zR
dcb76984bc
修复Azure 不设置Max token的bug (#2254) 2023-12-02 16:50:56 +08:00
zR
023cb22da7
修改 duckduckgo 依赖错误 (#2252) 2023-12-02 12:30:07 +08:00
Zhi-guo Huang
2d0615aede
Merge pull request #2251 from chatchat-space/hzg0601-patch-1
Update duckduckgo version
2023-12-02 12:25:24 +08:00
Zhi-guo Huang
643cc6c5be
Update duckduckgo version 2023-12-02 12:25:12 +08:00
liunux4odoo
12113be6ec 在startup中自动执行 create_tables, 确保数据库表被创建 2023-12-02 10:52:29 +08:00
imClumsyPanda
6558647b65 update version 2023-12-01 21:55:35 +08:00
imClumsyPanda
f9348326f5 update config template 2023-12-01 21:54:11 +08:00
liunux4odoo
4fa28c71b1
修复:chat 接口默认使用 memory获取10条历史消息,导致最终拼接的prompt出错 (#2247)
修改后默认使用用户传入的history,只有同时传入conversation_id和history_len时才从数据库读取历史消息
使用memory还有一个问题,对话角色是固定的,不能适配不同的模型。

其它:注释一些无用的 print
2023-12-01 11:35:43 +08:00
zR
0cc1be224d
依赖升级 (#2246)
大量依赖升级到最新版
测试环境:Ubuntu 22.04 LTS kernel 6.6.3 Python 3.10.12,Cuda12.3 update1
2023-12-01 11:34:41 +08:00
imClumsyPanda
60f8e1d55e update aggrid pagination 2023-11-30 23:40:03 +08:00
imClumsyPanda
c34b4136c0 update file format 2023-11-30 23:33:48 +08:00
imClumsyPanda
f2d917d1e4 update config templates 2023-11-30 23:26:15 +08:00
imClumsyPanda
89b07ba55d update config templates 2023-11-30 23:20:39 +08:00
imClumsyPanda
072e0a2a32 update reqs and server/utils 2023-11-30 22:23:15 +08:00
imClumsyPanda
7e99cc12b3 update reqs 2023-11-30 21:54:09 +08:00
imClumsyPanda
d55f53d8c0 update README.md 2023-11-30 21:50:50 +08:00
imClumsyPanda
120dc50004 update README.md 2023-11-30 21:44:51 +08:00
zty
5ac77e5089
修复: MiniMax和千帆在线embedding模型分批请求的bug (#2208)
* 修复: MiniMax和千帆在线embedding模型分批请求的bug

* 修改了一处typo
2023-11-30 17:28:22 +08:00
zR
8b70b1db7e
一些细节更新 (#2235)
* 更新Langchain依赖到0.0.342以上版本

* 更改了一些提示词和依赖,修改了openai异常的问题

* 注释data的打印日志

* 增加Qwen新模型的支持
2023-11-30 17:25:48 +08:00
zR
40918c21de
bug修复和提示词修改 (#2230)
* 更新Langchain依赖到0.0.343以上版本

* 更改了一些提示词和依赖,修改了openai异常的问题

* 注释data的打印日志
2023-11-30 12:09:53 +08:00
imClumsyPanda
0ca6f40c45
Update README.md 2023-11-30 11:58:04 +08:00
liunux4odoo
c4fe3393b3
添加自定义命令: (#2229)
/new [conv_name] 新建会话
/del [conv_name] 删除会话
/clear [conv_name] 清空会话
/help 命令帮助

新增依赖:streamlit-modal
2023-11-30 11:39:41 +08:00
imClumsyPanda
7487af3bad
Add files via upload 2023-11-30 11:04:14 +08:00
zR
c4bf8c48ec
0.2.7版本依赖更新,Langchain在0.0.340下才能使用 (#2213) 2023-11-29 15:15:03 +08:00
zR
b7a50daa0f
更新Langchain依赖到0.0.342以上版本 (#2212) 2023-11-29 15:08:13 +08:00
liunux4odoo
509dee0425 fix: empty docs error in KnowledgeFile 2023-11-29 11:33:43 +08:00
liunux4odoo
7d580d9a47 修复:*_chat 接口中重设 max_tokens 时导致 local variable 'max_tokens' referenced before assignment 错误 2023-11-28 21:00:00 +08:00
imClumsyPanda
6076ab1198
Update README.md 2023-11-27 11:59:35 +08:00
imClumsyPanda
02c33e6ce9
Add files via upload 2023-11-27 11:58:57 +08:00
liunux4odoo
8b695dba03 *_chat 接口中,当 max_tokens=0时,将其设为 None,避免 swagger ui 中默认值为0时访问出错 2023-11-26 16:47:58 +08:00
glide-the
75a2cba078
Merge pull request #2176 from glide-the/dev_command_summary
单个知识库根据doc_ids摘要
2023-11-25 23:32:19 +08:00
glide-the
279ffdf117 单个知识库根据doc_ids摘要 2023-11-25 23:31:13 +08:00
glide-the
33374bd9f2
Merge pull request #2175 from glide-the/dev_command_summary
提供文档summary_chunk ,支持单文件总结业务实现 使用 MapReduceDocumentsChain 生成摘要
2023-11-25 22:32:13 +08:00
glide-the
248db46187 Merge branch 'dev_summary' into dev_command_summary
实现summary_chunk 文档分段总结业务实现
使用 MapReduceDocumentsChain 生成摘要
# Conflicts:
#	server/api.py
#	server/knowledge_base/kb_doc_api.py
#	server/knowledge_base/kb_service/base.py
#	server/knowledge_base/migrate.py
2023-11-25 22:30:41 +08:00
glide-the
f57837c07a Merge branch 'dev_summary' into dev_tmp
# Conflicts:
#	server/api.py
#	server/knowledge_base/kb_doc_api.py
#	server/knowledge_base/kb_service/base.py
#	server/knowledge_base/migrate.py
2023-11-25 21:02:46 +08:00
hzg0601
08530edb3d add some comment 2023-11-25 19:56:36 +08:00
Zhi-guo Huang
92dcb11b26
Merge pull request #2173 from chatchat-space/hzg0601-patch-4
Update startup.py
2023-11-25 19:45:13 +08:00
Zhi-guo Huang
abb32722fe
Update startup.py
修复vllm=0.2.2版本中vllm_worker启动失败的bug
2023-11-25 19:44:33 +08:00
Zhi-guo Huang
717355bf1e
Merge pull request #2171 from chatchat-space/hzg0601-patch-3
Update server_config.py.example
2023-11-25 19:41:37 +08:00
Zhi-guo Huang
a83e03011d
Update server_config.py.example
针对fschat=0.2.33关于vllm启动的bug给出修补方案
2023-11-25 19:41:21 +08:00
Zhi-guo Huang
f9f16edd13
Update startup.py
解决vllm在0.2.2版本启动的bug
2023-11-25 19:38:18 +08:00
Zhi-guo Huang
63bdca1343
Merge pull request #2170 from chatchat-space/hzg0601-patch-2
Update requirements.txt
2023-11-25 19:35:11 +08:00
Zhi-guo Huang
3c4d4a5345
Update requirements.txt
针对win上的reqirements某些包的安装安装增说明
2023-11-25 19:34:57 +08:00
liunux4odoo
1de4258aa0
给 ApiModelWorker 添加 logger 成员变量,API请求出错时输出有意义的错误信息。 (#2169)
* 给 ApiModelWorker 添加 logger 成员变量,API请求出错时输出有意义的错误信息。
/chat/chat 接口 conversation_id参数改为默认 "",避免 swagger 页面默认值错误导致历史消息失效

* 修复在线模型一些bug
2023-11-25 13:51:07 +08:00
zR
1b0cf67a57
支持软连接的知识库 (#2167)
* GLM3支持传入提示词

支持传入提示词的Agent ChatGLM3-6B

* 软连接处理

1. 有效的软连接处理,参考了 #2125
2. 更新了依赖,现在fschat原生支持GLM3的全功能

* 更新了支持的模型列表和依赖
1. 推荐用户使用GLM3-6B取代2代GLM模型
2. 推荐用户使用性能更强的bge模型
3 推荐使用vllm和torch的最新稳定版本
2023-11-24 22:47:55 +08:00
Eden
dfcebf7bc3
支持昆仑万维天工大模型 (#2166)
---------

Co-authored-by: Eden <chuangqi.huang@ubtrobot.com>
Co-authored-by: liunux4odoo <liunux@qq.com>
2023-11-24 22:25:35 +08:00
Zhi-guo Huang
3839c212db
Merge pull request #2162 from chatchat-space/hzg0601-patch-1
Update startup.py
2023-11-24 17:03:19 +08:00
Zhi-guo Huang
1d3a69ff86
Update startup.py
解决vllm启动worker_id used before assigned的问题
2023-11-24 17:03:02 +08:00
liunux4odoo
824c29a6d2
将 MiniMax 和 千帆 在线 Embedding 改为 10 个文本一批,防止接口数量限制 (#2161) 2023-11-24 16:42:20 +08:00
qiankunli
76151e884a
feat: add with-history prompt (#2156)
Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>
2023-11-24 10:05:50 +08:00
liunux4odoo
1b9b777eaf 使 MessageModel 中 conversation_id 为非必填项,避免前端请求错误 2023-11-23 21:42:27 +08:00
liunux4odoo
aae4144476
数据库和向量库中文档 metadata["source"] 改为相对路径,便于向量库迁移 (#2153)
修复:
- 上传知识库文件名称包括子目录时,自动创建子目录
2023-11-23 19:54:00 +08:00
hzg0601
7a85fe74e9 add llm article to kb/smaples 2023-11-23 14:18:00 +08:00
qiankunli
1c97673d41
feat: add db memory (#2046)
* feat: add db memory
* WEBUI 添加多会话功能

---------

Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>
Co-authored-by: liunux4odoo <liunux@qq.com>
2023-11-22 18:38:26 +08:00
imClumsyPanda
274e7a9c0a
Update README.md 2023-11-22 15:27:14 +08:00
imClumsyPanda
7eee9212e0
Add files via upload 2023-11-22 15:26:45 +08:00
glide-the
569209289b
Merge pull request #2130 from glide-the/dev
统一在线模型异常报文、增加详细日志
2023-11-21 21:48:39 +08:00
glide-the
17c9632942 统一在线模型异常报文、增加详细日志 2023-11-21 21:47:02 +08:00
liunux4odoo
3cf7422c21
修复:知识库json文件的中文被转为unicode码,导致无法匹配 (#2128) 2023-11-21 21:00:46 +08:00
Zhi-guo Huang
ce7255dce1
Update model_config.py.example (#2110) 2023-11-20 16:45:55 +08:00
liunux4odoo
a9cf191532 update webui: 默认对话模式改为 LLM对话;lite 模式下可选模型列表不显示本地模型 2023-11-20 16:37:20 +08:00
Zhi-guo Huang
700c4ad170
Update requirements.txt
删除中文以防止win上的安装错误
2023-11-20 15:57:26 +08:00
Zhi-guo Huang
262c1fc8c3
Update requirements_api.txt
删除中文以防止win安装错误
2023-11-20 15:56:51 +08:00
Zhi-guo Huang
33f43f7a96
Update requirements_lite.txt
删除中文,以防止win设备安装错误
2023-11-20 15:56:16 +08:00
liunux4odoo
1a291d9db9 add .pdf & .pptx as knowledge test files; update wiki 2023-11-17 14:32:30 +08:00
liunux4odoo
ad7a6fd438
开发者: (#2091)
- 修复列出知识库磁盘文件时跳过临时文件的bug:只有目录被排除了,文件未排除
- 优化知识库文档加载器:
  - 将 elements 模式改为 single 模式,避免文档被切分得太碎
  - 给 get_loader 和 KnowledgeFile 增加 loader_kwargs 参数,可以自定义文档加载器参数
2023-11-17 11:39:32 +08:00
liunux4odoo
68a544ea33 开发者:XXKBService.get_doc_by_id 改为批量处理,提高访问向量库效率。 2023-11-16 11:09:40 +08:00
imClumsyPanda
4ed8f049ab
Update README.md 2023-11-16 10:20:39 +08:00
imClumsyPanda
51c43122cb
Add files via upload 2023-11-16 10:20:18 +08:00
liunux4odoo
fbe214471b
知识库支持 .jsonl, .epub, .xlsx, .xlsd, .ipynb, .odt, .py, .srt, .toml, .doc, .ppt 文件 (#2079)
* 知识库支持行式 json 文件
如果要使用 json 文件, 需要 `conda install jq`(windows 下 pip install jq 会失败)

开发者:
删除 CustomJsonLoader,使用 langchain 自带的 JsonLoader 处理 json 文件,添加 JsonLinesLoader 处理 jsonl 文件。

* 知识库支持 .epub, .xlsx, .xlsd, .ipynb, .odt, .py, .srt, .toml, .doc, .ppt 文件
为 .eml, .msg, .rst, .rtf, .tsv, .docx, .xml, .pptx 指定专用加载器
2023-11-16 09:37:09 +08:00
liunux4odoo
3b3d948d27
添加文件对话模式 (#2071)
开发者:
- 添加 /chat/file_chat, /knowledge_base/upload_temp_docs API 接口
- 添加 CACHED_MEMO_VS_NUM, BASE_TEMP_DIR 配置项
2023-11-16 07:39:27 +08:00
liunux4odoo
2adfa4277c
在webui模型列表中包括:非model worker启动的在线模型(如openai-api);已经下载的本地模型 (#2060) 2023-11-14 21:17:32 +08:00
zR
21b079d751
GLM3支持传入提示词 (#2058)
支持传入提示词的Agent ChatGLM3-6B
2023-11-14 17:45:22 +08:00
Hans
c094b5f91c
删除多余文字 (#2049) 2023-11-14 10:30:12 +08:00
liunux4odoo
e78a804ec6 close #2044: duplicated mount_knowledge_base_routes in server/api.py 2023-11-13 20:30:32 +08:00
zR
94d4304638
更新了chatglm3 6b agent的文档,提示词 (#2041)
更新了chatglm3 6b agent的文档,提示词
修复代理no_proxy格式问题 #1838 的问题,感谢多次复现和验证
修改了pg清理知识库后还会引用之前知识库的问题
2023-11-13 16:30:09 +08:00
Jack
4e8e6de7ff
Update README.md (#2034) 2023-11-13 14:27:27 +08:00
liunux4odoo
861510a92b
Update requirements: change comments to english (#2033)
* Update requirements: change comments to english
2023-11-13 14:03:41 +08:00
imClumsyPanda
e4ffa2f93b update README.md 2023-11-13 07:33:02 +08:00
imClumsyPanda
f06a819ba6 Merge remote-tracking branch 'origin/master' 2023-11-13 07:13:43 +08:00
imClumsyPanda
b6e366d93a update README.md 2023-11-13 07:13:28 +08:00
zR
91ff0574df
支持ChatGLM3-6B (#2021)
* 更新依赖和配置文件中的Agent模型

* 支持基础的glm3_agent
2023-11-12 16:45:50 +08:00
imClumsyPanda
068cb5df9c
Update README.md 2023-11-12 13:21:46 +08:00
imClumsyPanda
33c462a281
Add files via upload 2023-11-12 13:20:39 +08:00
imClumsyPanda
72a1f5dcb3 update README.md 2023-11-10 19:59:31 +08:00
imClumsyPanda
4fca531d97 update README.md 2023-11-10 19:58:24 +08:00
imClumsyPanda
89be31c66c update version 2023-11-10 19:45:32 +08:00
imClumsyPanda
3462d06759 update model_config.py.example 2023-11-10 19:40:55 +08:00
imClumsyPanda
5e9acfd633 update model_config.py.example 2023-11-10 16:35:42 +08:00
imClumsyPanda
9a741fd14d update model_config.py.example 2023-11-10 16:34:13 +08:00
imClumsyPanda
3e20e47328 Merge branch 'dev' of https://github.com/chatchat-space/Langchain-Chatchat into dev 2023-11-10 16:32:21 +08:00
Zhi-guo Huang
a8f4e7603e
Merge pull request #2011 from hzg0601/dev
1. 增加ES支持;2. 修复了若干typo bug
2023-11-10 16:30:18 +08:00
hzg0601
c1440c2609 增加ElasticSearch支持 2023-11-10 16:04:41 +08:00
liunux4odoo
63111a5c87 supdate model_config 2023-11-10 11:46:41 +08:00
liunux4odoo
261b4899c1 supdate model_config 2023-11-10 11:44:40 +08:00
liunux4odoo
b51ba11f45
支持通过配置项同时启动多个模型,将Wiki纳入samples知识库 (#2002)
新功能:
- 将 LLM_MODEL 配置项改为 LLM_MODELS 列表,同时启动多个模型
- 将 wiki 纳入 samples 知识库

依赖变化:
- 指定 streamlit~=1.27.0。1.26.0会报rerun错误,1.28.0会有无限刷新错误

修复优化:
- 优化 get_default_llm_model 逻辑
- 适配 Qwen 在线 API 做 Embeddings 时最大 25 行的限制
- 列出知识库磁盘文件时跳过 . 开头的文件
2023-11-09 22:15:52 +08:00
WilliamChen-luckbob
ce1001a043
bugfix:dev分支创建知识库必然失败的bug修复 (#1980)
* bugfix:dev分支创建知识库必然失败的bug修复

* 统一 KBServiceFactory.get_service_by_name 的逻辑,数据库中不存在知识库时返回 None

---------

Co-authored-by: liunux4odoo <liunux@qq.com>
2023-11-09 17:45:21 +08:00
imClumsyPanda
9588bcfa94 Merge branch 'master' into dev 2023-11-09 09:41:26 +08:00
imClumsyPanda
35164b5196 delete outdated qrcode 2023-11-09 09:41:06 +08:00
liunux4odoo
d0d688d4b0 修复:重建知识库时自动创建库表 2023-11-07 21:00:45 +08:00
imClumsyPanda
ccf277c96f delete outdated qrcode 2023-11-07 16:32:44 +08:00
imClumsyPanda
0e8700edb9 Merge branch 'master' into dev 2023-11-07 16:31:45 +08:00
imClumsyPanda
349adbdfa7
Add files via upload 2023-11-07 16:05:26 +08:00
imClumsyPanda
da1dbf9763
Update README.md 2023-11-07 16:05:03 +08:00
zR
3952fbd464
更新依赖和配置文件中的Agent模型 (#1984) 2023-11-07 13:52:47 +08:00
imClumsyPanda
e233e4f220 reformat server/knowledge_base/migrate.py 2023-11-06 22:49:35 +08:00
imClumsyPanda
fb32c31a70 reformat kb_doc_api.py 2023-11-06 22:44:50 +08:00
imClumsyPanda
fe73ceab15 Merge branch 'master' into dev 2023-11-06 22:38:52 +08:00
imClumsyPanda
051a2e97dc add support for Zhipu-api "chatglm-turbo" 2023-11-06 22:38:05 +08:00
imClumsyPanda
f4f7845f93 reformat startup.py 2023-11-06 22:31:09 +08:00
imClumsyPanda
ce9160fbfa update requirements.txt 2023-11-06 22:11:55 +08:00
imClumsyPanda
ed2122a8f6 fix bug in basic_config.py.example 2023-11-06 21:49:05 +08:00
imClumsyPanda
a938b67163 reformat config files 2023-11-05 11:17:09 +08:00
imClumsyPanda
5e0476925b reformat copy_config_example.py 2023-11-05 11:08:55 +08:00
zR
57612d5232
修复一些bug (#1965)
* 修改一些bug

* 更新掉了一部分之前的bug
2023-11-03 18:56:27 +08:00
qiankunli
fa906b33a8
添加对话评分与历史消息保存功能 (#1940)
* 新功能:
- WEBUI 添加对话评分功能
- 增加 /chat/feedback 接口,用于接收对话评分
- /chat/chat 接口返回值由 str 改为 {"text":str, "chat_history_id": str}
- init_database.py 添加 --create-tables --clear-tables 参数

依赖:
- streamlit-chatbox==1.1.11

开发者:
- ChatHistoryModel 的 id 字段支持自动生成
- SAVE_CHAT_HISTORY 改到 basic_config.py

* 修复:点击反馈后页面未刷新

---------

Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>
Co-authored-by: liunux4odoo <liunux@qq.com>
Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
2023-11-03 11:31:45 +08:00
liunux4odoo
554122f60e
Feat (#1951)
* 知识库支持子目录(不包括temp和tmp开头的目录),文件相对路径总长度不可超过255

* init_database.py 增加 --import-db 参数,在版本升级时,如果 info.db
表结构发生变化,但向量库无需重建,可以在重建数据库后,使用本参数从旧的数据库中导入信息
2023-11-02 14:46:39 +08:00
imClumsyPanda
d4b0b4d83d
Update README.md 2023-11-02 13:32:38 +08:00
imClumsyPanda
36584428d5
Add files via upload 2023-11-02 13:31:52 +08:00
liunux4odoo
d8e15b57ba
知识库支持子目录(不包括temp和tmp开头的目录),文件相对路径总长度不可超过255 (#1928) 2023-10-31 16:59:40 +08:00
liunux4odoo
65592a45c3
支持在线 Embeddings, Lite 模式支持所有知识库相关功能 (#1924)
新功能:
- 支持在线 Embeddings:zhipu-api, qwen-api, minimax-api, qianfan-api
- API 增加 /other/embed_texts 接口
- init_database.py 增加 --embed-model 参数,可以指定使用的嵌入模型(本地或在线均可)
- 对于 FAISS 知识库,支持多向量库,默认位置:{KB_PATH}/vector_store/{embed_model}
- Lite 模式支持所有知识库相关功能。此模式下最主要的限制是:
  - 不能使用本地 LLM 和 Embeddings 模型
  - 知识库不支持 PDF 文件
- init_database.py 重建知识库时不再默认情况数据库表,增加 clear-tables 参数手动控制。
- API 和 WEBUI 中 score_threshold 参数范围改为 [0, 2],以更好的适应在线嵌入模型

问题修复:
- API 中 list_config_models 会删除 ONLINE_LLM_MODEL 中的敏感信息,导致第二轮API请求错误

开发者:
- 统一向量库的识别:以(kb_name,embed_model)为判断向量库唯一性的依据,避免 FAISS 知识库缓存加载逻辑错误
- KBServiceFactory.get_service_by_name 中添加 default_embed_model 参数,用于在构建新知识库时设置 embed_model
- 优化 kb_service 中 Embeddings 操作:
  - 统一加载接口: server.utils.load_embeddings,利用全局缓存避免各处 Embeddings 传参
  - 统一文本嵌入接口:server.knowledge_base.kb_service.base.[embed_texts, embed_documents]
- 重写 normalize 函数,去除对 scikit-learn/scipy 的依赖
2023-10-31 14:26:50 +08:00
imClumsyPanda
7f9592773b
Update README.md 2023-10-29 14:54:40 +08:00
imClumsyPanda
1eddb2c321
Add files via upload 2023-10-29 14:54:13 +08:00
imClumsyPanda
ff22d5f98f
Update README.md 2023-10-29 14:53:01 +08:00
imClumsyPanda
b1100ddefb
Add files via upload 2023-10-29 14:52:31 +08:00
liunux4odoo
deed92169f
支持在线 Embeddings:zhipu-api, qwen-api, minimax-api, qianfan-api (#1907)
* 新功能:
- 支持在线 Embeddings:zhipu-api, qwen-api, minimax-api, qianfan-api
- API 增加 /other/embed_texts 接口
- init_database.py 增加 --embed-model 参数,可以指定使用的嵌入模型(本地或在线均可)

问题修复:
- API 中 list_config_models 会删除 ONLINE_LLM_MODEL 中的敏感信息,导致第二轮API请求错误

开发者:
- 优化 kb_service 中 Embeddings 操作:
  - 统一加载接口: server.utils.load_embeddings,利用全局缓存避免各处 Embeddings 传参
  - 统一文本嵌入接口:server.embedding_api.[embed_texts, embed_documents]
2023-10-28 23:37:30 +08:00
zR
aa7c580974
Dev (#1902)
修改Agent的内容
2023-10-27 22:53:43 +08:00
zR
bb72d9ac26
支持GLM (#1896)
* 支持glm3
2023-10-27 17:56:27 +08:00
zR
d054244e55
Dev (#1895)
* 修复科大讯飞token问题和Azure的token问题

* 合并PR并改变位置

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-27 14:38:24 +08:00
charlesyju
f19211b1f5
support adding keywords to model tokenizer (#1622)
* support adding keywords to model tokenizer

* add keyword_preprocess.py usage doc

* init new token with good weights

---------

Co-authored-by: Charles Ju <charlesyju@gmail.com>
2023-10-27 13:57:14 +08:00
zR
6ed87954b2
修复科大讯飞token问题和Azure的token问题 (#1894)
Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-27 13:51:59 +08:00
liunux4odoo
b68f7fcdea 修改qianfan-api使用原始post访问,qianfan sdk无法访问 2023-10-27 13:42:16 +08:00
zR
dea468ab0f
Dev (#1892)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

* 增加一些Langchain的自带工具

* 修复一些兼容性的bug

* 恢复知识库

* 恢复知识库

* 1

* 修复Azure问题

* 修复zilliz的问题

* 修复Agent历史记录问题,优化知识库问答搜索的uoji

* 修复讯飞大模型token问题

* 修复讯飞大模型token问题和配置文件

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-27 13:14:48 +08:00
zR
24d1e28a07
一些细节优化 (#1891)
Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-27 11:52:44 +08:00
liunux4odoo
ce8e341b9f update server_config.py.example: qianfan-api 默认模型改为 ERNIE-Bot。qianfan sdk 对模型名称大小写敏感 2023-10-26 22:48:56 +08:00
liunux4odoo
b4c68ddd05
优化在线 API ,支持 completion 和 embedding,简化在线 API 开发方式 (#1886)
* 优化在线 API ,支持 completion 和 embedding,简化在线 API 开发方式

新功能
- 智谱AI、Minimax、千帆、千问 4 个在线模型支持 embeddings(不通过Fastchat,后续会单独提供相关api接口)
- 在线模型自动检测传入参数,在传入非 messages 格式的 prompt 时,自动转换为 completion 形式,以支持 completion 接口

开发者:
- 重构ApiModelWorker:
  - 所有在线 API 请求封装到 do_chat 方法:自动传入参数 ApiChatParams,简化参数与配置项的获取;自动处理与fastchat的接口
  - 加强 API 请求错误处理,返回更有意义的信息
  - 改用 qianfan sdk 重写 qianfan-api
  - 将所有在线模型的测试用例统一在一起,简化测试用例编写

* Delete requirements_langflow.txt
2023-10-26 22:44:48 +08:00
zR
e74fe2d950
Zilliz修复 (#1874)
* 修复zilliz的问题
2023-10-25 21:59:26 +08:00
zR
35a7ca74c0
Azure 的fschat支持,弃用Langchain-MODEL (#1873)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

* 增加一些Langchain的自带工具

* 修复一些兼容性的bug

* 恢复知识库

* 恢复知识库

* 修复Azure问题
2023-10-25 21:32:40 +08:00
liunux4odoo
27418ba9fa fix bug, add dependencies: strsimpy, markdownify 2023-10-25 08:58:31 +08:00
liunux4odoo
03e55e11c4
支持lite模式:无需安装torch等重依赖,通过在线API实现LLM对话和搜索引擎对话 (#1860)
* move get_default_llm_model from webui to ApiRequest

增加API接口及其测试用例:
- /server/get_prompt_template: 获取服务器配置的 prompt 模板
- 增加知识库多线程访问测试用例

支持lite模式:无需安装torch等重依赖,通过在线API实现LLM对话和搜索引擎对话

* fix bug in server.api

---------

Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
2023-10-25 08:30:23 +08:00
Zhi-guo Huang
be67ea43d8
Merge pull request #1828 from qiankunli/feat/add-completion-api
增加completion功能的API接口,注意暂不支持online_api模型
2023-10-24 22:10:54 +08:00
liunux4odoo
19f5f07d57 fix: unused imported faiss in milvus_kb_server (close #1849) 2023-10-24 15:01:19 +08:00
jinke
2f67e1d0cc update docker image to 0.2.6
43.4G, chatglm6b+text2vec-bge-large-chinese.
2023-10-24 12:32:26 +08:00
imClumsyPanda
b166457897
Update README.md 2023-10-24 10:43:04 +08:00
imClumsyPanda
e904bc2ade
Add files via upload 2023-10-24 10:42:34 +08:00
imClumsyPanda
68498bd93b
Update README.md 2023-10-23 22:40:14 +08:00
zR
a036e3ccda
修改了部分Agent Prompt 修改了一些适配问题 (#1839)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

* 增加一些Langchain的自带工具

* 修复一些兼容性的bug
2023-10-23 14:53:14 +08:00
zR
e6382cacb1
修复了migrate兼容性错误,python3.8正常使用 (#1837)
Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-23 14:41:56 +08:00
zR
c983e9f559
增加一些Langchain的Agent工具 (#1836)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

* 增加一些Langchain的自带工具

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-23 13:22:10 +08:00
liqiankun.1111
b002a2879b feat: add completion api 2023-10-22 17:07:26 +08:00
zR
303c9d94df
修改,格式了部分Agent工具 (#1823)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

* 修改了部分Agent的工具

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-22 00:07:32 +08:00
zR
1b50547e60
Dev (#1822)
* 支持了agentlm

* 支持了agentlm和相关提示词

* 修改了Agent的一些功能,加入了Embed方面的一个优化

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-22 00:00:15 +08:00
zR
1c5382d96b
支持AgentLM模型 (#1821)
* 支持了agentlm

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-21 22:09:53 +08:00
zR
fcbd97203a
Dev (#1817)
* 更新了最新的readme

* 更新readme,加上目录

* 删掉所有没用的材料,之后都转wiki

* 更新readme和新版本图
2023-10-21 11:35:51 +08:00
liunux4odoo
4aa16d1c7b merge dev from master hotfix: no temperature in webui 2023-10-21 07:17:18 +08:00
zR
38a48bc831
紧急修复 温度 参数代码消失问题 (#1816) 2023-10-21 01:28:34 +08:00
imClumsyPanda
115a123442
Update README.md 2023-10-20 23:34:05 +08:00
imClumsyPanda
9186532fcb
Update README.md 2023-10-20 23:33:04 +08:00
liunux4odoo
9b5f64788c update dev version: v0.2.7-preview 2023-10-20 23:32:30 +08:00
liunux4odoo
d316efe8d3
release 0.2.6 (#1815)
## 🛠 新增功能

- 支持百川在线模型 (@hzg0601 @liunux4odoo in #1623)
- 支持 Azure OpenAI 与 claude 等 Langchain 自带模型 (@zRzRzRzRzRzRzR in #1808)
- Agent 功能大量更新,支持更多的工具、更换提示词、检索知识库 (@zRzRzRzRzRzRzR in #1626 #1666 #1785)
- 加长 32k 模型的历史记录 (@zRzRzRzRzRzRzR in #1629 #1630)
- *_chat 接口支持 max_tokens 参数 (@liunux4odoo in #1744)
- 实现 API 和 WebUI 的前后端分离 (@liunux4odoo in #1772)
- 支持 zlilliz 向量库 (@zRzRzRzRzRzRzR in #1785)
- 支持 metaphor 搜索引擎 (@liunux4odoo in #1792)
- 支持 p-tuning 模型 (@hzg0601 in #1810)
- 更新完善文档和 Wiki (@imClumsyPanda @zRzRzRzRzRzRzR @glide-the in #1680 #1811)

## 🐞 问题修复

- 修复 bge-* 模型匹配超过 1 的问题 (@zRzRzRzRzRzRzR in #1652)
- 修复系统代理为空的问题 (@glide-the in #1654)
- 修复重建知识库时 `d == self.d assert error` (@liunux4odoo in #1766)
- 修复对话历史消息错误 (@liunux4odoo in #1801)
- 修复 OpenAI 无法调用的 bug (@zRzRzRzRzRzRzR in #1808)
- 修复 windows下 BIND_HOST=0.0.0.0 时对话出错的问题 (@hzg0601 in #1810)
2023-10-20 23:16:06 +08:00
liunux4odoo
0e7f0e1452 update readme: remove milestone 2023-10-20 23:12:36 +08:00
zR
c41d7add7d
Dev (#1814)
* 更新了最新的readme

* 更新readme,加上目录

* 删掉所有没用的材料,之后都转wiki
2023-10-20 23:02:21 +08:00
liunux4odoo
df0ee992f3 update readme: remove milestone 2023-10-20 22:00:33 +08:00
liunux4odoo
ce54414b4f update readme: remove partners 2023-10-20 21:53:36 +08:00
liunux4odoo
dd7223b3a9 merge master to dev 2023-10-20 21:48:24 +08:00
zR
86ee6fe08c
更新readme (#1813)
* 更新了最新的readme

* 更新readme,加上目录
2023-10-20 21:37:43 +08:00
zR
46225ad784
Dev (#1811)
* 北京黑客松更新

知识库支持:
支持zilliz数据库
Agent支持:
支持以下工具调用
1. 支持互联网Agent调用
2. 支持知识库Agent调用
3. 支持旅游助手工具(未上传)

知识库更新
1. 支持知识库简介,用于Agent选择
2. UI对应知识库简介

提示词选择
1. UI 和模板支持提示词模板更换选择

* 数据库更新介绍问题解决

* 关于Langchain自己支持的模型

1. 修复了Openai无法调用的bug
2. 支持了Azure Openai Claude模型
(在模型切换界面由于优先级问题,显示的会是其他联网模型)
3. 422问题被修复,用了另一种替代方案。
4. 更新了部分依赖

* 换一些图
2023-10-20 20:07:59 +08:00
Zhi-guo Huang
109bb7f6c5
Merge pull request #1810 from hzg0601/dev
1. 支持加载p-tuning,详细步骤见docs/chatchat加载ptuing.md;2. 根据系统自动指定binding_host
2023-10-20 19:34:02 +08:00
hzg0601
a81bd827dd 根据系统指定binding_host 2023-10-20 19:32:06 +08:00
hzg0601
6e9acfc1af Merge branch 'dev' of https://github.com/chatchat-space/Langchain-Chatchat into dev 2023-10-20 19:22:36 +08:00
hzg0601
195929b518 支持加载p-tuning,详细步骤见docs/chatchat加载ptuing.md 2023-10-20 19:22:24 +08:00
liunux4odoo
1d9d9df9e9 update baichuan-api: 修正messages参数;支持流式;添加测试用例 2023-10-20 19:09:05 +08:00
zR
e920cd0064
合并分支,支持 (#1808)
* 北京黑客松更新

知识库支持:
支持zilliz数据库
Agent支持:
支持以下工具调用
1. 支持互联网Agent调用
2. 支持知识库Agent调用
3. 支持旅游助手工具(未上传)

知识库更新
1. 支持知识库简介,用于Agent选择
2. UI对应知识库简介

提示词选择
1. UI 和模板支持提示词模板更换选择

* 数据库更新介绍问题解决

* 关于Langchain自己支持的模型

1. 修复了Openai无法调用的bug
2. 支持了Azure Openai Claude模型
(在模型切换界面由于优先级问题,显示的会是其他联网模型)
3. 422问题被修复,用了另一种替代方案。
4. 更新了部分依赖
2023-10-20 18:13:55 +08:00
liunux4odoo
83e25f8011 remove xformers from requirements*.txt; check llm_model before change model in webui 2023-10-20 15:01:39 +08:00
liunux4odoo
0b25d7b079 fix: correct model_worker's logger and semaphor 2023-10-20 11:50:50 +08:00
liunux4odoo
1b3bd4442c update model_config.py.example (#1784) 2023-10-19 22:37:08 +08:00
liunux4odoo
d053950aee
新功能: (#1801)
- 更新langchain/fastchat依赖,添加xformers依赖
- 默认max_tokens=None, 生成tokens自动为模型支持的最大值

修复:
- history_len=0 时会带入1条不完整的历史消息,导致LLM错误
- 当对话轮数 达到history_len时,传入的历史消息为空
2023-10-19 22:09:15 +08:00
liunux4odoo
7e28291e9f
Merge pull request #1792 from liunux4odoo/fix
支持metaphor搜索引擎(无需代理,key申请简单,目前不支持中文)
2023-10-18 23:05:57 +08:00
liunux4odoo
b9b42991f6 - 支持metaphor搜索引擎(无需代理,key申请简单,目前不支持中文)
- 增加默认知识库和默认搜索引擎的配置项
- 修复WEBUI弹出当前模型错误
2023-10-18 23:02:20 +08:00
imClumsyPanda
b8aad555a1
Update README.md 2023-10-18 22:49:00 +08:00
imClumsyPanda
4d48d5f2ab
Add files via upload 2023-10-18 22:48:37 +08:00
zR
69e5da4e7a
北京黑客松更新 (#1785)
* 北京黑客松更新

知识库支持:
支持zilliz数据库
Agent支持:
支持以下工具调用
1. 支持互联网Agent调用
2. 支持知识库Agent调用
3. 支持旅游助手工具(未上传)

知识库更新
1. 支持知识库简介,用于Agent选择
2. UI对应知识库简介

提示词选择
1. UI 和模板支持提示词模板更换选择
2023-10-18 15:19:02 +08:00
liunux4odoo
9ce328fea9
实现Api和WEBUI的前后端分离 (#1772)
* update ApiRequest: 删除no_remote_api本地调用模式;支持同步/异步调用
* 实现API和WEBUI的分离:
- API运行服务器上的配置通过/llm_model/get_model_config、/server/configs接口提供,WEBUI运行机器上的配置项仅作为代码内部默认值使用
- 服务器可用的搜索引擎通过/server/list_search_engines提供
- WEBUI可选LLM列表中只列出在FSCHAT_MODEL_WORKERS中配置的模型
- 修改WEBUI中默认LLM_MODEL获取方式,改为从api端读取
- 删除knowledge_base_chat中`local_doc_url`参数

其它修改:
- 删除多余的kb_config.py.exmaple(名称错误)
- server_config中默认关闭vllm
- server_config中默认注释除智谱AI之外的在线模型
- 修改requests从系统获取的代理,避免model worker注册错误

* 修正:
- api.list_config_models返回模型原始配置
- api.list_config_models和api.get_model_config中过滤online api模型的敏感信息
- 将GPT等直接访问的模型列入WEBUI可选模型列表

其它:
- 指定langchain==0.3.313, fschat==0.2.30, langchain-experimental==0.0.30
2023-10-17 16:52:07 +08:00
liunux4odoo
94977c7ab1
修复:切换embed_model时,FAISS向量库未正确释放,导致`d == self.d assert (#1766)
修复:
- 切换embed_model时,FAISS向量库未正确释放,导致d == self.d assert error (close [求助] 初始化知识库发生错误 #1657 )
- ApiRequest中chat接口增加max_tokens参数
- FileDocModel模型字段错误(字段错误 #1691)
2023-10-16 21:02:07 +08:00
imClumsyPanda
9163dda5df
Update README.md 2023-10-15 22:20:22 +08:00
imClumsyPanda
70dd7c1f64
Add files via upload 2023-10-15 22:19:57 +08:00
liunux4odoo
cd748128c3
add paramter max_tokens to 4 chat api with default value 1024 (#1744) 2023-10-12 16:18:56 +08:00
liunux4odoo
1ac173958d fix #1737: MakeFastAPIOffline函数内代码编写错误 2023-10-12 10:56:49 +08:00
liunux4odoo
01577d6264 只启动在server_config中配置的在线API模型 2023-10-12 10:55:53 +08:00
imClumsyPanda
f4153beccf
Update README.md 2023-10-12 09:30:26 +08:00
imClumsyPanda
d35dbc730a
Update README.md 2023-10-11 22:22:23 +08:00
imClumsyPanda
68eb72e94f
Update README.md 2023-10-11 09:21:48 +08:00
imClumsyPanda
dfb36562ca
Add files via upload 2023-10-11 09:21:18 +08:00
imClumsyPanda
c313f99b40 update README.md 2023-10-11 06:13:48 +08:00
imClumsyPanda
76e21c87da update README.md 2023-10-11 06:10:02 +08:00
imClumsyPanda
bc5f846c6a update README.md 2023-10-10 21:33:38 +08:00
imClumsyPanda
4578bc4780 update README.md 2023-10-10 21:24:48 +08:00
glide-the
21cf43567a
Merge pull request #1707 from chatchat-space/glide-the-patch-3
Update README.md
2023-10-09 14:00:58 +08:00
glide-the
ff652f1f6b
Update README.md 2023-10-09 14:00:49 +08:00
glide-the
e9381f74af
Merge pull request #1705 from chatchat-space/glide-the-patch-1
微信二维码
2023-10-09 13:59:37 +08:00
glide-the
97c2126e80
Merge pull request #1706 from chatchat-space/glide-the-patch-2
Update README.md
2023-10-09 13:59:24 +08:00
glide-the
15fab6e10f
Update README.md 2023-10-09 13:59:09 +08:00
glide-the
27f5e7d967
微信二维码 2023-10-09 13:58:20 +08:00
zR
111bc45d04
Wiki完善和Agent完善计划 (#1680)
* 更新上agent提示词代码

* 更新部分文档,修复了issue中提到的bge匹配超过1 的bug

* 按需修改

* 解决了部分最新用户用依赖的bug,加了两个工具,移除google工具

* Agent大幅度优化

1. 修改了UI界面
(1)高亮所有没有进行agent对齐的模型,
(2)优化输出体验和逻辑,使用markdown

2. 降低天气工具使用门槛
3. 依赖更新
(1) vllm 更新到0.2.0,增加了一些参数
(2) torch 建议更新到2.1
(3)pydantic不要更新到1.10.12

* 更新了一些注释

* 修改部分依赖,修改了部分wiki用图

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-10-07 22:00:56 +08:00
zR
7475205eca
Agent提示词更改,增加图片 (#1667)
* 更新上agent提示词代码

* 更新部分文档,修复了issue中提到的bge匹配超过1 的bug

* 按需修改

* 解决了部分最新用户用依赖的bug,加了两个工具,移除google工具

* Agent大幅度优化

1. 修改了UI界面
(1)高亮所有没有进行agent对齐的模型,
(2)优化输出体验和逻辑,使用markdown

2. 降低天气工具使用门槛
3. 依赖更新
(1) vllm 更新到0.2.0,增加了一些参数
(2) torch 建议更新到2.1
(3)pydantic不要更新到1.10.12

* 更新了一些注释
2023-10-07 11:52:54 +08:00
zR
2c8fc95f7a
Agent大更新合并 (#1666)
* 更新上agent提示词代码

* 更新部分文档,修复了issue中提到的bge匹配超过1 的bug

* 按需修改

* 解决了部分最新用户用依赖的bug,加了两个工具,移除google工具

* Agent大幅度优化

1. 修改了UI界面
(1)高亮所有没有进行agent对齐的模型,
(2)优化输出体验和逻辑,使用markdown

2. 降低天气工具使用门槛
3. 依赖更新
(1) vllm 更新到0.2.0,增加了一些参数
(2) torch 建议更新到2.1
(3)pydantic不要更新到1.10.12
2023-10-07 11:26:11 +08:00
liunux4odoo
387b4cb967 fix #1638: baichuan-api未正确配置 2023-10-05 22:46:31 +08:00
liunux4odoo
0304279545 fix #1656: rename kb_config.py.exmaple to kb_config.py.example 2023-10-05 22:35:13 +08:00
glide-the
038f2eb1ec 修复代理为空的问题
(cherry picked from commit 84a4141dec1b8c5da5b62d3ad885927791f6d3ee)
2023-10-04 14:05:00 +08:00
glide-the
37500b878e 指定transformers==4.33.3版本
(cherry picked from commit f30b4d5d575308e6ec3794d43c9e7696e399e7fe)
2023-10-04 14:05:00 +08:00
glide-the
48338207bd 修复代理为空的问题
(cherry picked from commit a655608d01a1ff44c8f6a3e0ab6ed07cb4e217c4)
2023-10-04 14:05:00 +08:00
glide-the
295783b549
Merge pull request #1654 from glide-the/master
修复代理为空的问题
2023-10-04 14:04:11 +08:00
glide-the
84a4141dec 修复代理为空的问题 2023-10-04 14:02:57 +08:00
glide-the
db3efb306a
Merge pull request #1653 from glide-the/master
修复代理和transformers版本问题
2023-10-04 13:38:21 +08:00
glide-the
f30b4d5d57 指定transformers==4.33.3版本 2023-10-04 13:35:11 +08:00
glide-the
a655608d01 修复代理为空的问题 2023-10-04 13:33:42 +08:00
zR
fc6a3b07ed
Dev (#1652)
* 更新上agent提示词代码

* 更新部分文档,修复了issue中提到的bge匹配超过1 的bug

* 按需修改

* 解决了部分最新用户用依赖的bug,加了两个工具,移除google工具
2023-10-04 12:05:46 +08:00
liunux4odoo
332f8be401
fix: windows下bind_host设为0.0.0.0时,将fschat_xx_address指向127.0.0.1,避免请求错误 (#1651) 2023-10-03 23:40:05 +08:00
zR
e88d926bbb
修改部分错误的文档,加长了历史记录(for 32k Models) (#1630)
* 更新上agent提示词代码 (#1626)

* 修改部分错误的文档,加长了历史记录(for 32k Models) (#1629)

* 更新上agent提示词代码

* 按需修改
2023-09-29 20:19:31 +08:00
zR
77d38db00e
修改部分错误的文档,加长了历史记录(for 32k Models) (#1629)
* 更新上agent提示词代码

* 更新部分文档,修复了issue中提到的bge匹配超过1 的bug

* 按需修改
2023-09-29 20:17:29 +08:00
liunux4odoo
eb6f5cf84b
fix: embedding_model_dict used for bge-* models (#1628)
change to use `get_model_path`
2023-09-29 18:57:15 +08:00
zR
b11d6ab5bb
更新上agent提示词代码 (#1626) (#1627) 2023-09-29 18:47:11 +08:00
zR
61c4000859
更新上agent提示词代码 (#1626) 2023-09-29 18:45:50 +08:00
zR
b077085fbe Merge branch 'dev' 2023-09-29 16:44:10 +08:00
zR
d9056a8df6
python3.8用户需要加上__future__ (#1624)
* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* 增加了部分Agent支持和修改了启动文件的部分bug

* 修改了GPU数量配置文件

* 1

1

* 修复配置文件错误

* 更新readme,稳定测试

* 更新readme

* python3.8用户需要加这两行
2023-09-29 16:04:44 +08:00
Zhi-guo Huang
6b1e13a4e2
Merge pull request #1623 from hzg0601/dev
1. 增加baichuan-api支持;2.增加批量复制configs下.example文件为.py文件的脚本copy_config_example.py
2023-09-29 13:19:44 +08:00
hzg0601
00745c99e2 update baichuan.py 2023-09-29 13:19:17 +08:00
hzg0601
0e20552083 1. 增加baichuan-api支持;2.增加批量复制configs下.example文件为.py文件的脚本copy_config_example.py;3. 更新model_config.py.example 2023-09-29 13:16:14 +08:00
liunux4odoo
ba8d0f8e17
发版:v0.2.5 (#1620)
* 优化configs (#1474)

* remove llm_model_dict

* optimize configs

* fix get_model_path

* 更改一些默认参数,添加千帆的默认配置

* Update server_config.py.example

* fix merge conflict for #1474 (#1494)

* 修复ChatGPT api_base_url错误;用户可以在model_config在线模型配置中覆盖默认的api_base_url (#1496)

* 优化LLM模型列表获取、切换的逻辑: (#1497)

1、更准确的获取未运行的可用模型
2、优化WEBUI模型列表显示与切换的控制逻辑

* 更新migrate.py和init_database.py,加强知识库迁移工具: (#1498)

1. 添加--update-in-db参数,按照数据库信息,从本地文件更新向量库
2. 添加--increament参数,根据本地文件增量更新向量库
3. 添加--prune-db参数,删除本地文件后,自动清理相关的向量库
4. 添加--prune-folder参数,根据数据库信息,清理无用的本地文件
5. 取消--update-info-only参数。数据库中存储了向量库信息,该操作意义不大
6. 添加--kb-name参数,所有操作支持指定操作的知识库,不指定则为所有本地知识库
7. 添加知识库迁移的测试用例
8. 删除milvus_kb_service的save_vector_store方法

* feat: support volc fangzhou

* 使火山方舟正常工作,添加错误处理和测试用例

* feat: support volc fangzhou (#1501)

* feat: support volc fangzhou

---------

Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>

* 第一版初步agent实现 (#1503)

* 第一版初步agent实现

* 增加steaming参数

* 修改了weather.py

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>

* 添加configs/prompt_config.py,允许用户自定义prompt模板: (#1504)

1、 默认包含2个模板,分别用于LLM对话,知识库和搜索引擎对话
2、 server/utils.py提供函数get_prompt_template,获取指定的prompt模板内容(支持热加载)
3、 api.py中chat/knowledge_base_chat/search_engine_chat接口支持prompt_name参数

* 增加其它模型的参数适配

* 增加传入矢量名称加载

* 1. 搜索引擎问答支持历史记录;
2. 修复知识库问答历史记录传参错误:用户输入被传入history,问题出在webui中重复获取历史消息,api知识库对话接口并无问题。

* langchain日志开关

* move wrap_done & get_ChatOpenAI from server.chat.utils to server.utils (#1506)

* 修复faiss_pool知识库缓存key错误 (#1507)

* fix ReadMe anchor link (#1500)

* fix : Duplicate variable and function name (#1509)

Co-authored-by: Jim <zhangpengyi@taijihuabao.com>

* Update README.md

* fix #1519: streamlit-chatbox旧版BUG,但新版有兼容问题,先在webui中作处理,并限定chatbox版本 (#1525)

close #1519

* 【功能新增】在线 LLM 模型支持阿里云通义千问 (#1534)

* feat: add qwen-api

* 使Qwen API支持temperature参数;添加测试用例

* 将online-api的sdk列为可选依赖

---------

Co-authored-by: liunux4odoo <liunux@qq.com>

* 处理序列化至磁盘的逻辑

* remove depends on volcengine

* update kb_doc_api: use Form instead of Body when upload file

* 将所有httpx请求改为使用Client,提高效率,方便以后设置代理等。 (#1554)

将所有httpx请求改为使用Client,提高效率,方便以后设置代理等。

将本项目相关服务加入无代理列表,避免fastchat的服务器请求错误。(windows下无效)

* update QR code

* update readme_en,readme,requirements_api,requirements,model_config.py.example:测试baichuan2-7b;更新相关文档

* 新增特性:1.支持vllm推理加速框架;2. 更新支持模型列表

* 更新文件:1. startup,model_config.py.example,serve_config.py.example,FAQ

* 1. debug vllm加速框架完毕;2. 修改requirements,requirements_api对vllm的依赖;3.注释掉serve_config中baichuan-7b的device为cpu的配置

* 1. 更新congif中关于vllm后端相关说明;2. 更新requirements,requirements_api;

* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写 (#1611)

* Dev (#1613)

* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* fix: set vllm based on platform to avoid error on windows

* fix: langchain warnings for import from root

* 修复webui中重建知识库以及对话界面UI错误 (#1615)

* 修复bug:webui点重建知识库时,如果存在不支持的文件会导致整个接口错误;migrate中没有导入CHUNK_SIZE

* 修复:webui对话界面的expander一直为running状态;简化历史消息获取方法

* 根据官方文档,添加对英文版的bge embedding的指示模板 (#1585)

Co-authored-by: zR <2448370773@qq.com>

* Dev (#1618)

* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* 增加了部分Agent支持和修改了启动文件的部分bug

* 修改了GPU数量配置文件

* 1

1

* 修复配置文件错误

* 更新readme,稳定测试

* 更改readme 0928 (#1619)

* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* 增加了部分Agent支持和修改了启动文件的部分bug

* 修改了GPU数量配置文件

* 1

1

* 修复配置文件错误

* 更新readme,稳定测试

* 更新readme

* fix readme

* 处理序列化至磁盘的逻辑

* update version number to v0.2.5

---------

Co-authored-by: qiankunli <qiankun.li@qq.com>
Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>
Co-authored-by: zR <2448370773@qq.com>
Co-authored-by: glide-the <2533736852@qq.com>
Co-authored-by: Water Zheng <1499383852@qq.com>
Co-authored-by: Jim Zhang <dividi_z@163.com>
Co-authored-by: Jim <zhangpengyi@taijihuabao.com>
Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
Co-authored-by: Leego <leegodev@hotmail.com>
Co-authored-by: hzg0601 <hzg0601@163.com>
Co-authored-by: WilliamChen-luckbob <58684828+WilliamChen-luckbob@users.noreply.github.com>
2023-09-28 23:30:21 +08:00
liunux4odoo
30b8daecb3 fix readme 2023-09-28 23:21:35 +08:00
zR
1b312d5715
更改readme 0928 (#1619)
* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* 增加了部分Agent支持和修改了启动文件的部分bug

* 修改了GPU数量配置文件

* 1

1

* 修复配置文件错误

* 更新readme,稳定测试

* 更新readme
2023-09-28 23:09:21 +08:00
zR
efd8edda16
Dev (#1618)
* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度

* 增加了部分Agent支持和修改了启动文件的部分bug

* 修改了GPU数量配置文件

* 1

1

* 修复配置文件错误

* 更新readme,稳定测试
2023-09-28 20:19:26 +08:00
WilliamChen-luckbob
8fa99026c8
根据官方文档,添加对英文版的bge embedding的指示模板 (#1585)
Co-authored-by: zR <2448370773@qq.com>
2023-09-28 19:18:31 +08:00
imClumsyPanda
db169f628c
Update README.md 2023-09-28 16:00:01 +08:00
imClumsyPanda
0641ce5db4
Add files via upload 2023-09-28 15:59:25 +08:00
liunux4odoo
b3c7f8b072
修复webui中重建知识库以及对话界面UI错误 (#1615)
* 修复bug:webui点重建知识库时,如果存在不支持的文件会导致整个接口错误;migrate中没有导入CHUNK_SIZE

* 修复:webui对话界面的expander一直为running状态;简化历史消息获取方法
2023-09-28 15:12:03 +08:00
liunux4odoo
8d0f8a5d67 fix: langchain warnings for import from root 2023-09-27 21:55:02 +08:00
liunux4odoo
523764e284 fix: set vllm based on platform to avoid error on windows 2023-09-27 21:43:54 +08:00
zR
d39878ff35
Dev (#1613)
* 增加了仅限GPT4的agent功能,陆续补充,中文版readme已写

* issue提到的一个bug

* 温度最小改成0,但是不应该支持负数

* 修改了最小的温度
2023-09-27 21:17:50 +08:00
zR
5702554171
增加了仅限GPT4的agent功能,陆续补充,中文版readme已写 (#1611) 2023-09-27 19:19:25 +08:00
Zhi-guo Huang
c546b4271e
Merge pull request #1603 from hzg0601/dev
1. 更新congif中关于vllm后端相关说明;2. 更新requirements,requirements_api;
2023-09-26 21:57:03 +08:00
hzg0601
2716ff739d 1. 更新congif中关于vllm后端相关说明;2. 更新requirements,requirements_api; 2023-09-26 21:55:57 +08:00
Zhi-guo Huang
56d75af824
Merge pull request #1582 from chatchat-space/fschat_vllm
支持vllm推理后端
2023-09-24 13:28:32 +08:00
Zhi-guo Huang
9cbd9f6711
Merge pull request #1581 from hzg0601/dev
测试vllm推理框架成功
2023-09-24 02:08:44 +08:00
hzg0601
2d823aa4b1 1. debug vllm加速框架完毕;2. 修改requirements,requirements_api对vllm的依赖;3.注释掉serve_config中baichuan-7b的device为cpu的配置 2023-09-24 02:05:40 +08:00
imClumsyPanda
af46ed9539
Update README.md 2023-09-23 08:35:13 +08:00
imClumsyPanda
39337a6603
Add files via upload 2023-09-23 08:34:50 +08:00
Zhi-guo Huang
3309b5c0c1
Merge pull request #1574 from hzg0601/dev
支持vllm模型;根据vllm模型更新支持模型列表
2023-09-23 01:49:04 +08:00
hzg0601
3a6d166e17 Merge branch 'dev' of github.com:chatchat-space/Langchain-Chatchat into dev 2023-09-23 01:46:52 +08:00
hzg0601
f4da0845b9 更新文件:1. startup,model_config.py.example,serve_config.py.example,FAQ 2023-09-23 01:38:54 +08:00
hzg0601
810145c5fb 新增特性:1.支持vllm推理加速框架;2. 更新支持模型列表 2023-09-23 01:37:37 +08:00
Zhi-guo Huang
192fbee1fb
Merge pull request #1568 from hzg0601/dev
update readme_en,readme,requirements_api,requirements,model_config.py…
2023-09-22 14:35:06 +08:00
hzg0601
89aed8e675 update readme_en,readme,requirements_api,requirements,model_config.py.example:测试baichuan2-7b;更新相关文档 2023-09-22 14:30:28 +08:00
imClumsyPanda
f3042a6a29 merge master 2023-09-22 12:36:45 +08:00
imClumsyPanda
171300c513 update QR code 2023-09-22 12:24:31 +08:00
liunux4odoo
e4a927c5d1
将所有httpx请求改为使用Client,提高效率,方便以后设置代理等。 (#1554)
将所有httpx请求改为使用Client,提高效率,方便以后设置代理等。

将本项目相关服务加入无代理列表,避免fastchat的服务器请求错误。(windows下无效)
2023-09-21 15:19:51 +08:00
peterz3g
3ff130ecc2
修复csv文件解析编码报错的问题。 (#1508) 2023-09-21 14:41:49 +08:00
liunux4odoo
818cb1a491 update kb_doc_api: use Form instead of Body when upload file 2023-09-21 09:57:36 +08:00
glide-the
0586f94c5a summary_chunk 文档分段总结业务实现
使用 MapReduceDocumentsChain 生成摘要
2023-09-20 23:55:56 +08:00
liunux4odoo
92359fb6b9 remove depends on volcengine 2023-09-20 23:02:43 +08:00
imClumsyPanda
6a0a791c80
Update README.md 2023-09-20 22:42:46 +08:00
glide-the
bd0164ea62 处理序列化至磁盘的逻辑 2023-09-20 21:35:23 +08:00
Leego
9bcce0a572
【功能新增】在线 LLM 模型支持阿里云通义千问 (#1534)
* feat: add qwen-api

* 使Qwen API支持temperature参数;添加测试用例

* 将online-api的sdk列为可选依赖

---------

Co-authored-by: liunux4odoo <liunux@qq.com>
2023-09-20 21:34:12 +08:00
liunux4odoo
b161985d79 fix #1519: streamlit-chatbox旧版BUG,但新版有兼容问题,先在webui中作处理,并限定chatbox版本 (#1525)
close #1519
2023-09-20 16:47:07 +08:00
imClumsyPanda
be22869c5e Update README.md 2023-09-20 16:46:32 +08:00
Jim Zhang
cb2b560a5b fix : Duplicate variable and function name (#1509)
Co-authored-by: Jim <zhangpengyi@taijihuabao.com>
2023-09-20 16:46:31 +08:00
Water Zheng
a580cbddab fix ReadMe anchor link (#1500) 2023-09-20 16:46:31 +08:00
lehug
b6c390777a
fix argument name in help text (#1532) 2023-09-20 10:38:50 +08:00
imClumsyPanda
30e72ebc3f
Update README.md 2023-09-20 08:26:48 +08:00
imClumsyPanda
3cd73ef11e
Add files via upload 2023-09-20 08:26:26 +08:00
Orion
e07bbf6efb
Add: standard python ignore files (#1530) 2023-09-19 18:04:34 +08:00
liunux4odoo
6c4598b356
fix #1519: streamlit-chatbox旧版BUG,但新版有兼容问题,先在webui中作处理,并限定chatbox版本 (#1525)
close #1519
2023-09-19 10:09:40 +08:00
liunux4odoo
46af5b7571
fix: llm_model_dict with xxx/xxx local_model_path was parsed as online-api (#1513) 2023-09-18 12:10:03 +08:00
imClumsyPanda
1ec63de968
Update README.md 2023-09-18 12:02:42 +08:00
Jim Zhang
59fb309ba4
fix : Duplicate variable and function name (#1509)
Co-authored-by: Jim <zhangpengyi@taijihuabao.com>
2023-09-18 11:00:04 +08:00
liunux4odoo
1bae930691
修复faiss_pool知识库缓存key错误 (#1507) 2023-09-17 16:31:44 +08:00
liunux4odoo
ec85cd1954
move wrap_done & get_ChatOpenAI from server.chat.utils to server.utils (#1506) 2023-09-17 16:19:50 +08:00
glide-the
7d31e84cc7 langchain日志开关 2023-09-17 14:18:22 +08:00
liunux4odoo
bb7ce601fc 1. 搜索引擎问答支持历史记录;
2. 修复知识库问答历史记录传参错误:用户输入被传入history,问题出在webui中重复获取历史消息,api知识库对话接口并无问题。
2023-09-17 13:58:57 +08:00
glide-the
902ba0c321 增加传入矢量名称加载 2023-09-17 13:56:18 +08:00
glide-the
175c90c362 增加其它模型的参数适配 2023-09-17 13:56:08 +08:00
liunux4odoo
a65bc4a63c
添加configs/prompt_config.py,允许用户自定义prompt模板: (#1504)
1、 默认包含2个模板,分别用于LLM对话,知识库和搜索引擎对话
2、 server/utils.py提供函数get_prompt_template,获取指定的prompt模板内容(支持热加载)
3、 api.py中chat/knowledge_base_chat/search_engine_chat接口支持prompt_name参数
2023-09-17 13:27:11 +08:00
zR
598eb298df
第一版初步agent实现 (#1503)
* 第一版初步agent实现

* 增加steaming参数

* 修改了weather.py

---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-09-17 11:19:16 +08:00
qiankunli
13cca9cf81
feat: support volc fangzhou (#1501)
* feat: support volc fangzhou

---------

Co-authored-by: liunux4odoo <41217877+liunux4odoo@users.noreply.github.com>
Co-authored-by: liqiankun.1111 <liqiankun.1111@bytedance.com>
2023-09-17 00:53:12 +08:00
liunux4odoo
7577bd52ce Merge branch 'pr1501' into dev 2023-09-17 00:30:24 +08:00
liunux4odoo
9a7beef270 使火山方舟正常工作,添加错误处理和测试用例 2023-09-17 00:21:13 +08:00
liunux4odoo
745a105bae feat: support volc fangzhou 2023-09-16 22:21:16 +08:00
Water Zheng
7eed50337d
fix ReadMe anchor link (#1500) 2023-09-16 19:26:29 +08:00
liunux4odoo
42d76aabdf
Update model_config.py.example: wrong provider for qianfan-api (#1499) 2023-09-16 11:19:22 +08:00
liunux4odoo
c8d8727783
更新migrate.py和init_database.py,加强知识库迁移工具: (#1498)
1. 添加--update-in-db参数,按照数据库信息,从本地文件更新向量库
2. 添加--increament参数,根据本地文件增量更新向量库
3. 添加--prune-db参数,删除本地文件后,自动清理相关的向量库
4. 添加--prune-folder参数,根据数据库信息,清理无用的本地文件
5. 取消--update-info-only参数。数据库中存储了向量库信息,该操作意义不大
6. 添加--kb-name参数,所有操作支持指定操作的知识库,不指定则为所有本地知识库
7. 添加知识库迁移的测试用例
8. 删除milvus_kb_service的save_vector_store方法
2023-09-16 09:09:27 +08:00
liunux4odoo
3dde02be28
优化LLM模型列表获取、切换的逻辑: (#1497)
1、更准确的获取未运行的可用模型
2、优化WEBUI模型列表显示与切换的控制逻辑
2023-09-16 07:15:08 +08:00
liunux4odoo
955b0bc211
修复ChatGPT api_base_url错误;用户可以在model_config在线模型配置中覆盖默认的api_base_url (#1496) 2023-09-15 22:56:13 +08:00
liunux4odoo
80375e1ff3
fix merge conflict for #1474 (#1494) 2023-09-15 18:11:15 +08:00
liunux4odoo
f7c73b842a
优化configs (#1474)
* remove llm_model_dict

* optimize configs

* fix get_model_path

* 更改一些默认参数,添加千帆的默认配置

* Update server_config.py.example
2023-09-15 17:52:22 +08:00
imClumsyPanda
456229c13f update README.md and README_en.md 2023-09-15 14:18:35 +08:00
imClumsyPanda
b2d86bf3f8 Merge branch 'master' into pre-release 2023-09-15 13:53:34 +08:00
imClumsyPanda
fc78004ab3 update qr code 2023-09-15 13:53:07 +08:00
imClumsyPanda
42fba7ef90 Merge branch 'dev' into pre-release 2023-09-15 13:47:25 +08:00
imClumsyPanda
a87a2815da update knowledge_base and dialogue page of webui 2023-09-15 13:45:47 +08:00
imClumsyPanda
eb49a91190 update webui_pages/knowledge_base.py 2023-09-15 11:04:23 +08:00
imClumsyPanda
f066e427ce update webui_pages/knowledge_base.py 2023-09-15 10:58:52 +08:00
liunux4odoo
63f0d27167
在readme中添加支持的在线API模型 (#1485) 2023-09-15 10:16:15 +08:00
imClumsyPanda
20eef45a58 update README.md 2023-09-15 09:53:58 +08:00
liunux4odoo
30aeec1c45
修改智谱API默认名称,给WEBUI设置主题 (#1484)
* 給WEBUI设置主题

* chatglm-api更名为zhipu-api
2023-09-15 01:48:02 +08:00
liunux4odoo
f0f1dc2537 补充更多千帆平台支持的模型;除了指定模型名称,支持直接指定模型APIURL,便于填写单独申请的模型地址 2023-09-15 00:30:18 +08:00
liunux4odoo
4cf2e5ea5e 修复文心一言,添加测试用例 2023-09-14 23:37:34 +08:00
imClumsyPanda
fbaca1009e update requirements.txt, requirements_api.txt, test_different_splitter.py and chinese_recursive_text_splitter.py 2023-09-14 22:59:05 +08:00
imClumsyPanda
1813814a65 update model_config.py.example 2023-09-14 22:29:49 +08:00
imClumsyPanda
4c61a642cf update model_config.py.example 2023-09-14 22:29:26 +08:00
imClumsyPanda
bda1b01a2d update model_config.py.example 2023-09-14 22:27:57 +08:00
imClumsyPanda
17985c7f8e update splitter.md 2023-09-14 22:24:58 +08:00
Zhi-guo Huang
3745b1d1bb
Merge pull request #1479 from hzg0601/dev
update readme,readme_en:更新fastchat信息;删除订阅号二维码
2023-09-14 17:01:35 +08:00
hzg0601
6b734ced56 update readme,readme_en:更新fastchat信息;删除订阅号二维码 2023-09-14 17:00:20 +08:00
imClumsyPanda
883445e5b2
增加 百度文心一言 API 接入支持 (#1477)
* add RapidOCRPDFLoader

* update mypdfloader.py and requirements.txt

* add myimgloader.py

* add test samples

* add TODO to mypdfloader

* add loaders to KnowledgeFile class

* add loaders to KnowledgeFile class

* add ChineseRecursiveTextSplitter

* add ChineseRecursiveTextSplitter

* add baidu ernie api
2023-09-14 15:30:06 +08:00
唐国梁
4c5fc6ab01 edit model_config.py.example 2023-09-14 12:38:37 +08:00
唐国梁
6ad8aee88c add ES function 2023-09-14 07:54:42 +08:00
zR
769d75d784
修复测试文件 (#1467)
Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-09-13 17:12:05 +08:00
imClumsyPanda
dc413120e2 update text splitter unit test name 2023-09-13 15:53:07 +08:00
imClumsyPanda
f75812afcb update text splitter unit test name 2023-09-13 15:47:34 +08:00
zR
bfdbe69fa1
增加了自定义分词器适配 (#1462)
* 添加了自定义分词器适配和测试文件
---------

Co-authored-by: zR <zRzRzRzRzRzRzR>
2023-09-13 15:42:12 +08:00
liunux4odoo
c4cb4e19e5
清理不必要的依赖,增加星火API需要的websockets (#1463) 2023-09-13 15:35:04 +08:00
liunux4odoo
99b862dfc8 fix SparkApi import error 2023-09-13 14:03:09 +08:00
liunux4odoo
512638a3b1
支持讯飞星火大模型在线API (#1460)
* 支持讯飞星火大模型在线API
2023-09-13 13:51:05 +08:00
liunux4odoo
16d8809c9a
api和webui知识库操作支持chunk_size/overlap_size/zh_title_enhance参数 (#1459) 2023-09-13 11:19:47 +08:00
liunux4odoo
9defa4332e fix minimax api history error 2023-09-13 10:12:31 +08:00
liunux4odoo
f1f8ab80e4
Update close-issue.yml:提示改成中文,改到凌晨05:30运行 (#1456) 2023-09-13 10:06:54 +08:00
liunux4odoo
8b040620de
对话接口支持temperature参数 (#1455) 2023-09-13 10:00:54 +08:00
liunux4odoo
a03b8d330d
升级到langchain==0.0.287,fschat==0.0.28;处理langchain.Milvus bug(#10492) (#1454)
* 修复milvus_kb_service中一些bug,添加文档后将数据同步到数据库
* 升级到langchain==0.0.287,fschat==0.0.28;处理langchain.Milvus bug(#10492)
* 修复切换模型BUG: 从在线API切换模型时出错
2023-09-13 08:43:11 +08:00
liunux4odoo
efd6d4a251
修复milvus_kb_service中一些bug,添加文档后将数据同步到数据库 (#1452) 2023-09-12 22:34:03 +08:00
imClumsyPanda
4aa14b859e
增加 ChineseRecursiveTextSplitter (#1447)
* add RapidOCRPDFLoader

* update mypdfloader.py and requirements.txt

* add myimgloader.py

* add test samples

* add TODO to mypdfloader

* add loaders to KnowledgeFile class

* add loaders to KnowledgeFile class

* add ChineseRecursiveTextSplitter

* add ChineseRecursiveTextSplitter
2023-09-12 17:38:52 +08:00
imClumsyPanda
1d0c6a9184 Merge branch 'master' into pre-release 2023-09-12 15:51:53 +08:00
imClumsyPanda
2020f5bb88 merge master 2023-09-12 15:51:28 +08:00
liunux4odoo
03c021d50f
添加MiniMax在线API支持 (#1445) 2023-09-12 15:24:47 +08:00
imClumsyPanda
8064586374 delete .doc from supported formats 2023-09-12 15:22:18 +08:00
liunux4odoo
8a12b9c658
添加自动关闭issue的action (#1437) 2023-09-12 10:16:19 +08:00
liunux4odoo
60f88ae92e
fix: 由于server.utils导入model_workers时,导入fastchat model_worker,导致startup启动延迟明显 (#1436) 2023-09-12 08:52:00 +08:00
liunux4odoo
6a03611750
fix api and webui: (#1435)
1. fix #1431: 优化知识库问答与搜索引擎问答的API接口,避免docs重复返回
2. startup.py根据configs.log_verbose控制log级别
3. 修复/llm_model/list_models的bug:
   只有一个参数时,fastapi未返回json导致视图函数出错
2023-09-12 08:31:17 +08:00
liunux4odoo
22ff073309
修改Embeddings和FAISS缓存加载方式,知识库相关API接口支持多线程并发 (#1434)
* 修改Embeddings和FAISS缓存加载方式,支持多线程,支持内存FAISS

* 知识库相关API接口支持多线程并发

* 根据新的API接口调整ApiRequest和测试用例

* 删除webui.py失效的启动说明
2023-09-11 20:41:41 +08:00
imClumsyPanda
518d3c4951
Update README.md 2023-09-11 15:18:03 +08:00
imClumsyPanda
be621772ab
Add files via upload 2023-09-11 15:17:38 +08:00
Zhi-guo Huang
d0e654d847
Merge pull request #1422 from hzg0601/dev
update readme.md,readme_cn.md:更新订阅号QRcode
2023-09-09 17:36:10 +08:00
hzg0601
ed6df7cd24 update readme.md,readme_cn.md:更新订阅号QRcode 2023-09-09 17:34:56 +08:00
glide-the
b0a9d8f30e 增加显示ocr识别进度 2023-09-08 21:32:41 +08:00
glide-the
60e6887e94
Merge pull request #1419 from glide-the/dev
增加显示详细日志开关
2023-09-08 20:50:31 +08:00
glide-the
5550e3c1a9 增加显示详细日志开关 2023-09-08 20:48:31 +08:00
liunux4odoo
228fc5bd93 fix startup.py: correct processes count 2023-09-08 15:24:43 +08:00
liunux4odoo
f082edbaad fix startup.py: correct processes count 2023-09-08 15:23:54 +08:00
liunux4odoo
f94f2793f8
update startup.py: (#1416)
1. 恢复模型切换功能
2. --model-name支持多个名称(空格分开),同时启动多个模型
3. 优化服务启动顺序。严格按照顺序启动:controller -> [openai-api,
   model_worker, api_worker]并行 -> api.py -> webui.py
4. 修复:从在线API模型切换到本地模型时失败
2023-09-08 15:18:13 +08:00
Kyle Zhang
6e9a7e0c89
chore: update .gitignore (#1364)
Added '/' before knowledge_base/ and configs/*.py to make them match
directories at root folder only.

Signed-off-by: Kyle Zhang <zhangk1985@gmail.com>
Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
2023-09-08 13:29:40 +08:00
liunux4odoo
775870a516
改变api视图函数的sync/async,提高api并发能力: (#1414)
1. 4个chat类接口改为async
2. 知识库操作,涉及向量库修改的使用async,避免FAISS写入错误;涉及向量库读取的改为sync,提高并发
2023-09-08 12:25:02 +08:00
roki1031
196bde3ead
提醒fitz包是来自pyMuPDF (#1407) 2023-09-08 12:20:20 +08:00
liunux4odoo
1195eb75eb merge pr1413 2023-09-08 10:30:07 +08:00
Zhi-guo Huang
f2aed727c2
Merge pull request #1412 from hzg0601/dev
update reamd_en.md:删除中文对照
2023-09-08 10:22:24 +08:00
liunux4odoo
4cfee9c17c 根据新的接口修改ApiRequest和webui,以及测试用例。修改后预期webui中批量知识文件相关操作减少时间 2023-09-08 10:22:04 +08:00
hzg0601
136b667683 update reamd_en.md:删除中文对照 2023-09-08 10:19:49 +08:00
Zhi-guo Huang
71a1ae0627
Merge pull request #1411 from hzg0601/dev
增加中英对照的reame_en.md, 更新readme.md
2023-09-08 10:01:57 +08:00
hzg0601
607831496b update readme.md 2023-09-08 09:54:11 +08:00
hzg0601
bf748eb732 add README_en.md: 增加中英对照的readme 2023-09-08 09:46:23 +08:00
hzg0601
10237d24ca update readme_cn.md 2023-09-08 09:32:33 +08:00
liunux4odoo
661a0e9d72 新功能:
- 知识库管理中的add_docs/delete_docs/update_docs均支持批量操作,并利用多线程提高效率
- API的重建知识库接口支持多线程
- add_docs可提供参数控制上传文件后是否继续进行向量化
- add_docs/update_docs支持传入自定义docs(以json形式)。后续考虑区分完整或补充式自定义docs
- download_doc接口添加`preview`参数,支持下载或预览
- kb_service增加`save_vector_store`方法,便于保存向量库(仅FAISS,其它无操作)
- 将document_loader & text_splitter逻辑从KnowledgeFile中抽离出来,为后续对内存文件进行向量化做准备
- KowledgeFile支持docs & splitted_docs的缓存,方便在中间过程做一些自定义

其它:
- 将部分错误输出由print改为logger.error
2023-09-08 08:55:12 +08:00
Light
f422575a17
修复chat接口报错时信息显示KeyError: 'answer'的Bug (#1399)
Co-authored-by: Light <>
2023-09-07 20:44:21 +08:00
hzg0601
80f00e27f9 update readme.md, add reame_en.md: 1. update supported models list;2. add readme_en.md 2023-09-07 16:27:12 +08:00
imClumsyPanda
6ea4fc7a30 Merge branch 'master' into dev 2023-09-06 21:19:59 +08:00
imClumsyPanda
9ed43ab2ab Merge branch 'master' into pre-release 2023-09-06 21:19:38 +08:00
imClumsyPanda
54cf79f521 add support for new embedding models sensenova/piccolo-base-zh and sensenova/piccolo-large-zh 2023-09-06 21:17:32 +08:00
imClumsyPanda
eeb152e22c Merge branch 'master' into dev 2023-09-06 20:09:53 +08:00
imClumsyPanda
59bdfd85ea Merge branch 'master' into pre-release 2023-09-06 20:09:36 +08:00
imClumsyPanda
f607424c11 fix pdf ocr bug 2023-09-06 20:09:18 +08:00
imClumsyPanda
673410ecd5 fix pdf ocr bug 2023-09-06 20:08:56 +08:00
imClumsyPanda
8ec3db94f7
Update README.md 2023-09-06 20:04:03 +08:00
imClumsyPanda
e9b25e3f14
Add files via upload 2023-09-06 20:03:41 +08:00
hzg0601
76c2c61bb2 update server.model_worker.zhipu.py:更新prompt,遵守zhipu的格式要求 2023-09-06 17:33:00 +08:00
hzg0601
5e4bd5c3d3 update server.model_worker.zhipu.py/base.py:增加流式响应 2023-09-06 11:16:16 +08:00
jinke
bc0a39ab82 update docker desc
更新0.2.3 docker
2023-09-06 10:23:34 +08:00
hzg0601
6f039cfdeb update server.model_workers.base.py/zhipu.py: 支持zhipuapi的stream 流式输出 2023-09-05 23:13:42 +08:00
imClumsyPanda
0ea18314f2 fix unit test name 2023-09-05 21:08:02 +08:00
glide-the
082f429809
Merge pull request #1382 from glide-the/dev
增加构建文档metadata检索的开关,移动到dev_metadata_search
2023-09-05 21:02:18 +08:00
imClumsyPanda
5f533570a1 Merge branch 'pre-release' into dev 2023-09-05 21:01:45 +08:00
imClumsyPanda
6702f39db1 update knowledge_base page 2023-09-05 21:01:40 +08:00
imClumsyPanda
afd02317bd Merge branch 'master' into pre-release 2023-09-05 21:00:58 +08:00
imClumsyPanda
629e0278d5 update knowledge_base page 2023-09-05 21:00:35 +08:00
glide-the
1027ab6c06 增加构建文档metadata检索的开关,移动到dev_metadata_search 2023-09-05 20:59:57 +08:00
glide-the
b9ce09cbab
Merge pull request #1380 from glide-the/dev
增加构建文档metadata检索的开关
2023-09-05 18:36:42 +08:00
glide-the
491c9605d9 增加构建文档metadata检索的开关 2023-09-05 18:35:11 +08:00
imClumsyPanda
c26d66772a Merge branch 'pre-release' into dev 2023-09-05 18:19:21 +08:00
imClumsyPanda
e23e27a9f2 update autodl version 2023-09-05 18:19:13 +08:00
imClumsyPanda
74cca5eb0e add support for shibing624/text2vec-bge-large-chinese 2023-09-05 18:19:13 +08:00
imClumsyPanda
fdfbf31318 fix streamlit-aggrid showing "For Trial Use Only" 2023-09-05 18:19:13 +08:00
imClumsyPanda
33cbfb72b4 Merge branch 'master' into pre-release 2023-09-05 18:17:31 +08:00
imClumsyPanda
75f1e84b1f update autodl version 2023-09-05 18:15:43 +08:00
imClumsyPanda
780c1457d0 add support for shibing624/text2vec-bge-large-chinese 2023-09-05 18:04:21 +08:00
imClumsyPanda
c24e00a386 fix streamlit-aggrid showing "For Trial Use Only" 2023-09-05 17:30:58 +08:00
glide-the
0b60a25f2a 知识库默认存储路径 默认自动创建 2023-09-05 17:27:43 +08:00
imClumsyPanda
3a706907ff Merge branch 'pre-release' into dev 2023-09-05 14:50:06 +08:00
imClumsyPanda
30c00ffac6 Merge branch 'master' into pre-release 2023-09-05 14:47:28 +08:00
imClumsyPanda
9da7313e7e update requirements.txt 2023-09-05 14:46:26 +08:00
liunux4odoo
3e87530478 使zhipuai变为非必要依赖(close #1369) 2023-09-05 12:43:51 +08:00
liunux4odoo
464ccc6d53 Update migrate.py (#1371)
fix bug at line 85 : for kb_file in kb_file
2023-09-05 11:52:22 +08:00
TongTie
98e4fbaaa3 docs: Correcting a spelling mistake in README (#1367)
Co-authored-by: tongtie <tongtie@gmail.com>
2023-09-05 11:52:22 +08:00
imClumsyPanda
8ea75417ec update VERSION 2023-09-05 10:20:59 +08:00
liunux4odoo
93b133f9ac 将KnowledgeFile的file2text拆分成file2docs、docs2texts和file2text三个部分,在保持接口不变的情况下,实现:
1、支持chunk_size和chunk_overlap参数
2、支持自定义text_splitter
3、支持自定义docs
修复:csv文件不使用text_splitter
2023-09-04 21:00:16 +08:00
liunux4odoo
8475a5dfd3
Merge branch 'chatchat-space:dev' into dev 2023-09-04 14:44:55 +08:00
332 changed files with 34746 additions and 3760 deletions

19
.dockerignore Normal file
View File

@ -0,0 +1,19 @@
.idea
# Langchain-Chatchat
docs
.github
tests
Dockerfile
.dockerignore
.gitignore
.gitmodules
README.md
README_en.md
README_ja.md
LICENSE
requirements_api.txt
requirements_lite.txt
requirements_webui.txt
# bge-large-zh-v1.5
bge-large-zh-v1.5/README.md
# chatglm3-6b

22
.github/workflows/close-issue.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "30 21 * * *"
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "这个问题已经被标记为 `stale` ,因为它已经超过 30 天没有任何活动。"
close-issue-message: "这个问题已经被自动关闭,因为它被标为 `stale` 后超过 14 天没有任何活动。"
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}

155
.github/workflows/docker-build.yaml vendored Normal file
View File

@ -0,0 +1,155 @@
name: docker-build
on:
push:
branches:
- master
paths-ignore:
- 'README.md'
- 'README_en.md'
- 'README_ja.md'
env:
TZ: Asia/Shanghai
jobs:
docker-build:
runs-on: ubuntu-latest
# if: github.event.pull_request.merged == true
steps:
- name: Optimize Disk Space
uses: hugoalh/disk-space-optimizer-ghaction@v0.8.0
with:
operate_sudo: "True"
general_include: ".+"
general_exclude: |-
^GCC$
^G\+\+$
Clang
LLVM
docker_include: ".+"
docker_prune: "True"
docker_clean: "True"
apt_prune: "True"
apt_clean: "True"
homebrew_prune: "True"
homebrew_clean: "True"
npm_prune: "True"
npm_clean: "True"
os_swap: "True"
- name: Remove Unnecessary Tools And Files
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' azure-cli google-chrome-stable firefox powershell mono-devel
sudo apt-get autoremove --purge -y
sudo find /var/log -name "*.gz" -type f -delete
sudo rm -rf /var/cache/apt/archives
sudo rm -rf /tmp/*
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /opt/ghc /usr/share/dotnet /usr/local/graalvm /usr/local/.ghcup \
/usr/local/share/powershell /usr/local/share/chromium /usr/local/lib/node_modules
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /etc/mysql /etc/php
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true
sudo -E apt-get -qq update
sudo -E apt-get -qq install libfuse-dev $(curl -fsSL git.io/depends-ubuntu-2204)
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo apt-get clean
rm -rf /opt/hostedtoolcache
sudo timedatectl set-timezone "$TZ"
- name: Free Up Disk Space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 62464 # 给 / 预留 61GiB 空间( docker 预留)
swap-size-mb: 1
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Latest Release
id: get_version
run: |
VERSION=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r .tag_name)
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set Image Tag
id: imageTag
run: echo "::set-output name=image_tag::$RELEASE_VERSION-$(date +%Y%m%d)-$(git rev-parse --short HEAD)"
- name: Set Up QEMU
uses: docker/setup-qemu-action@v2
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Clone Model
run: |
sudo mkdir -p $GITHUB_WORKSPACE/bge-large-zh-v1.5
cd $GITHUB_WORKSPACE/bge-large-zh-v1.5
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/.gitattributes &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/config.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/config_sentence_transformers.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/modules.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/pytorch_model.bin &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/sentence_bert_config.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/special_tokens_map.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/tokenizer.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/tokenizer_config.json &> /dev/null
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/vocab.txt &> /dev/null
sudo mkdir -p $GITHUB_WORKSPACE/bge-large-zh-v1.5/1_Pooling
cd $GITHUB_WORKSPACE/bge-large-zh-v1.5/1_Pooling
sudo wget https://huggingface.co/BAAI/bge-large-zh-v1.5/resolve/main/1_Pooling/config.json &> /dev/null
sudo mkdir -p $GITHUB_WORKSPACE/chatglm3-6b
cd $GITHUB_WORKSPACE/chatglm3-6b
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/config.json &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/configuration_chatglm.py &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00001-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00002-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00003-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00004-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00005-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00006-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model-00007-of-00007.safetensors &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/model.safetensors.index.json &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/modeling_chatglm.py &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/pytorch_model.bin.index.json &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/quantization.py &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/special_tokens_map.json &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/tokenization_chatglm.py &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/tokenizer.model &> /dev/null
sudo wget https://huggingface.co/THUDM/chatglm3-6b/resolve/main/tokenizer_config.json &> /dev/null
du -sh $GITHUB_WORKSPACE
du -sh $GITHUB_WORKSPACE/*
du -sh $GITHUB_WORKSPACE/bge-large-zh-v1.5/*
du -sh $GITHUB_WORKSPACE/chatglm3-6b/*
- name: Show Runner Disk
run: df -hT
- name: Docker Build
run: |
docker build -t uswccr.ccs.tencentyun.com/chatchat/chatchat:${{ steps.imageTag.outputs.image_tag }} -f Dockerfile .
- name: Show Images Size
run: docker images
- name: Login To Tencent CCR
uses: docker/login-action@v2
with:
registry: uswccr.ccs.tencentyun.com
username: ${{ secrets.CCR_REGISTRY_USERNAME }}
password: ${{ secrets.CCR_REGISTRY_PASSWORD }}
- name: Docker Push
run: docker push uswccr.ccs.tencentyun.com/chatchat/chatchat:${{ steps.imageTag.outputs.image_tag }}
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Update README.md
run: |
sed -i "s|uswccr.ccs.tencentyun.com/chatchat/chatchat:[^ ]*|uswccr.ccs.tencentyun.com/chatchat/chatchat:${{ steps.imageTag.outputs.image_tag }}|g" README.md
sed -i "s|uswccr.ccs.tencentyun.com/chatchat/chatchat:[^ ]*|uswccr.ccs.tencentyun.com/chatchat/chatchat:${{ steps.imageTag.outputs.image_tag }}|g" README_en.md
sed -i "s|uswccr.ccs.tencentyun.com/chatchat/chatchat:[^ ]*|uswccr.ccs.tencentyun.com/chatchat/chatchat:${{ steps.imageTag.outputs.image_tag }}|g" README_ja.md
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "feat:update docker image:tag"
- name: Push README.md
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: ${{ github.ref }}

179
.gitignore vendored
View File

@ -1,9 +1,180 @@
*.log
*.log.*
*.bak
logs
.idea/
__pycache__/
/knowledge_base/
configs/*.py
/knowledge_base/*
!/knowledge_base/samples
/knowledge_base/samples/vector_store
/configs/*.py
.vscode/
# below are standard python ignore files
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
.pytest_cache
.DS_Store
# Test File
test.py
configs/*.py

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "knowledge_base/samples/content/wiki"]
path = knowledge_base/samples/content/wiki
url = https://github.com/chatchat-space/Langchain-Chatchat.wiki.git

View File

@ -1,22 +0,0 @@
# 贡献指南
欢迎!我们是一个非常友好的社区,非常高兴您想要帮助我们让这个应用程序变得更好。但是,请您遵循一些通用准则以保持组织有序。
1. 确保为您要修复的错误或要添加的功能创建了一个[问题](https://github.com/imClumsyPanda/langchain-ChatGLM/issues),尽可能保持它们小。
2. 请使用 `git pull --rebase` 来拉取和衍合上游的更新。
3. 将提交合并为格式良好的提交。在提交说明中单独一行提到要解决的问题,如`Fix #<bug>`(有关更多可以使用的关键字,请参见[将拉取请求链接到问题](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue))。
4. 推送到`dev`。在说明中提到正在解决的问题。
---
# Contribution Guide
Welcome! We're a pretty friendly community, and we're thrilled that you want to help make this app even better. However, we ask that you follow some general guidelines to keep things organized around here.
1. Make sure an [issue](https://github.com/imClumsyPanda/langchain-ChatGLM/issues) is created for the bug you're about to fix, or feature you're about to add. Keep them as small as possible.
2. Please use `git pull --rebase` to fetch and merge updates from the upstream.
3. Rebase commits into well-formatted commits. Mention the issue being resolved in the commit message on a line all by itself like `Fixes #<bug>` (refer to [Linking a pull request to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) for more keywords you can use).
4. Push into `dev`. Mention which bug is being resolved in the description.

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
# Base Image
FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
# Labels
LABEL maintainer=chatchat
# Environment Variables
ENV HOME=/Langchain-Chatchat
# Commands
WORKDIR /
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apt-get update -y && \
apt-get install -y --no-install-recommends python3.11 python3-pip curl libgl1 libglib2.0-0 jq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -f /usr/bin/python3 && \
ln -s /usr/bin/python3.11 /usr/bin/python3 && \
mkdir -p $HOME
# Copy the application files
COPY . $HOME
WORKDIR $HOME
# Install dependencies from requirements.txt
RUN pip3 install -r requirements.txt -i https://pypi.org/simple && \
python3 copy_config_example.py && \
sed -i 's|MODEL_ROOT_PATH = ""|MODEL_ROOT_PATH = "/Langchain-Chatchat"|' configs/model_config.py && \
python3 init_database.py --recreate-vs
EXPOSE 22 7861 8501
ENTRYPOINT ["python3", "startup.py", "-a"]

535
README.md
View File

@ -1,36 +1,49 @@
![](img/logo-long-chatchat-trans-v2.png)
**LangChain-Chatchat** (原 Langchain-ChatGLM): 基于 Langchain 与 ChatGLM 等大语言模型的本地知识库问答应用实现。
🌍 [READ THIS IN ENGLISH](README_en.md)
🌍 [日本語で読む](README_ja.md)
📃 **LangChain-Chatchat** (原 Langchain-ChatGLM)
基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。
### ⚠️ 重要提示
`0.2.10`将会是`0.2.x`系列的最后一个版本,`0.2.x`系列版本将会停止更新和技术支持,全力研发具有更强应用性的 `Langchain-Chatchat 0.3.x`
`0.2.10` 的后续 bug 修复将会直接推送到`master`分支,而不再进行版本更新。
---
## 目录
* [介绍](README.md#介绍)
* [变更日志](README.md#变更日志)
* [模型支持](README.md#模型支持)
* [Docker 部署](README.md#Docker-部署)
* [开发部署](README.md#开发部署)
* [软件需求](README.md#软件需求)
* [1. 开发环境准备](README.md#1.-开发环境准备)
* [2. 下载模型至本地](README.md#2.-下载模型至本地)
* [3. 设置配置项](README.md#3.-设置配置项)
* [4. 知识库初始化与迁移](README.md#4.-知识库初始化与迁移)
* [5. 一键启动API服务或WebUI服务](README.md#6.-一键启动)
* [6. 分步启动 API 服务或 Web UI](README.md#5.-启动-API-服务或-Web-UI)
* [常见问题](README.md#常见问题)
* [路线图](README.md#路线图)
* [项目交流群](README.md#项目交流群)
---
* [解决的痛点](README.md#解决的痛点)
* [快速上手](README.md#快速上手)
* [1. 环境配置](README.md#1-环境配置)
* [2. 模型下载](README.md#2-模型下载)
* [3. 初始化知识库和配置文件](README.md#3-初始化知识库和配置文件)
* [4. 一键启动](README.md#4-一键启动)
* [5. 启动界面示例](README.md#5-启动界面示例)
* [联系我们](README.md#联系我们)
## 介绍
🤖️ 一种利用 [langchain](https://github.com/hwchase17/langchain) 思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。
🤖️ 一种利用 [langchain](https://github.com/langchain-ai/langchain)
思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。
💡 受 [GanymedeNil](https://github.com/GanymedeNil) 的项目 [document.ai](https://github.com/GanymedeNil/document.ai) 和 [AlexZhangji](https://github.com/AlexZhangji) 创建的 [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216) 启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中通过使用 [FastChat](https://github.com/lm-sys/FastChat) 接入 Vicuna, Alpaca, LLaMA, Koala, RWKV 等模型,依托于 [langchain](https://github.com/langchain-ai/langchain) 框架支持通过基于 [FastAPI](https://github.com/tiangolo/fastapi) 提供的 API 调用服务,或使用基于 [Streamlit](https://github.com/streamlit/streamlit) 的 WebUI 进行操作。
💡 受 [GanymedeNil](https://github.com/GanymedeNil) 的项目 [document.ai](https://github.com/GanymedeNil/document.ai)
和 [AlexZhangji](https://github.com/AlexZhangji)
创建的 [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216)
启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中通过使用 [FastChat](https://github.com/lm-sys/FastChat)
接入 Vicuna, Alpaca, LLaMA, Koala, RWKV 等模型,依托于 [langchain](https://github.com/langchain-ai/langchain)
框架支持通过基于 [FastAPI](https://github.com/tiangolo/fastapi) 提供的 API
调用服务,或使用基于 [Streamlit](https://github.com/streamlit/streamlit) 的 WebUI 进行操作。
✅ 依托于本项目支持的开源 LLM 与 Embedding 模型,本项目可实现全部使用**开源**模型**离线私有部署**。与此同时,本项目也支持 OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。
✅ 依托于本项目支持的开源 LLM 与 Embedding 模型,本项目可实现全部使用**开源**模型**离线私有部署**。与此同时,本项目也支持
OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。
⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 -> 在文本向量中匹配出与问句向量最相似的 `top k`个 -> 匹配出的文本作为上下文和问题一起添加到 `prompt`中 -> 提交给 `LLM`生成回答。
⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 ->
在文本向量中匹配出与问句向量最相似的 `top k`个 -> 匹配出的文本作为上下文和问题一起添加到 `prompt`中 -> 提交给 `LLM`生成回答。
📺 [原理介绍视频](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)
@ -42,446 +55,152 @@
🚩 本项目未涉及微调、训练过程,但可利用微调或训练对本项目效果进行优化。
🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/imClumsyPanda/langchain-ChatGLM/Langchain-Chatchat) 中 `v6` 版本所使用代码已更新至本项目 `0.2.2` 版本。
🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) 中 `0.2.10`
🐳 [Docker 镜像](registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.0)
版本所使用代码已更新至本项目 `v0.2.10` 版本。
💻 一行命令运行 Docker
🐳 [Docker 镜像](isafetech/chatchat:0.2.10) 已经更新到 ```0.2.10``` 版本。
🌲 本次更新后同时支持DockerHub、阿里云、腾讯云镜像源
```shell
docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.0
docker run -d --gpus all -p 80:8501 isafetech/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 uswccr.ccs.tencentyun.com/chatchat/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.10
```
---
🧩 本项目有一个非常完整的[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) README只是一个简单的介绍_
_仅仅是入门教程能够基础运行__。
如果你想要更深入的了解本项目,或者想对本项目做出贡献。请移步 [Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
界面
## 变更日志
## 解决的痛点
参见 [版本更新日志](https://github.com/imClumsyPanda/langchain-ChatGLM/releases)。
该项目是一个可以实现 __完全本地化__推理的知识库增强方案, 重点解决数据安全保护,私域化部署的企业痛点。
本开源方案采用```Apache License```,可以免费商用,无需付费。
`0.1.x` 升级过来的用户请注意,需要按照[开发部署](README.md#3.-开发部署)过程操作,将现有知识库迁移到新格式,具体见[知识库初始化与迁移](docs/INSTALL.md#知识库初始化与迁移)。
我们支持市面上主流的本地大语言模型和Embedding模型支持开源的本地向量数据库。
支持列表详见[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
### `0.2.0` 版本与 `0.1.x` 版本区别
## 快速上手
1. 使用 [FastChat](https://github.com/lm-sys/FastChat) 提供开源 LLM 模型的 API以 OpenAI API 接口形式接入,提升 LLM 模型加载效果;
2. 使用 [langchain](https://github.com/langchain-ai/langchain) 中已有 Chain 的实现,便于后续接入不同类型 Chain并将对 Agent 接入开展测试;
3. 使用 [FastAPI](https://github.com/tiangolo/fastapi) 提供 API 服务,全部接口可在 FastAPI 自动生成的 docs 中开展测试,且所有对话接口支持通过参数设置流式或非流式输出;
4. 使用 [Streamlit](https://github.com/streamlit/streamlit) 提供 WebUI 服务,可选是否基于 API 服务启动 WebUI增加会话管理可以自定义会话主题并切换且后续可支持不同形式输出内容的显示
5. 项目中默认 LLM 模型改为 [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b),默认 Embedding 模型改为 [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base),文件加载方式与文段划分方式也有调整,后续将重新实现上下文扩充,并增加可选设置;
6. 项目中扩充了对不同类型向量库的支持,除支持 [FAISS](https://github.com/facebookresearch/faiss) 向量库外,还提供 [Milvus](https://github.com/milvus-io/milvus), [PGVector](https://github.com/pgvector/pgvector) 向量库的接入;
7. 项目中搜索引擎对话,除 Bing 搜索外,增加 DuckDuckGo 搜索选项DuckDuckGo 搜索无需配置 API Key在可访问国外服务环境下可直接使用。
### 1. 环境配置
---
+ 首先,确保你的机器安装了 Python 3.8 - 3.11 (我们强烈推荐使用 Python3.11)。
## 模型支持
```
$ python --version
Python 3.11.7
```
本项目中默认使用的 LLM 模型为 [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b),默认使用的 Embedding 模型为 [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) 为例。
### LLM 模型支持
本项目最新版本中基于 [FastChat](https://github.com/lm-sys/FastChat) 进行本地 LLM 模型接入,支持模型如下:
- [meta-llama/Llama-2-7b-chat-hf](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf)
- Vicuna, Alpaca, LLaMA, Koala
- [BlinkDL/RWKV-4-Raven](https://huggingface.co/BlinkDL/rwkv-4-raven)
- [camel-ai/CAMEL-13B-Combined-Data](https://huggingface.co/camel-ai/CAMEL-13B-Combined-Data)
- [databricks/dolly-v2-12b](https://huggingface.co/databricks/dolly-v2-12b)
- [FreedomIntelligence/phoenix-inst-chat-7b](https://huggingface.co/FreedomIntelligence/phoenix-inst-chat-7b)
- [h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b](https://huggingface.co/h2oai/h2ogpt-gm-oasst1-en-2048-open-llama-7b)
- [lcw99/polyglot-ko-12.8b-chang-instruct-chat](https://huggingface.co/lcw99/polyglot-ko-12.8b-chang-instruct-chat)
- [lmsys/fastchat-t5-3b-v1.0](https://huggingface.co/lmsys/fastchat-t5)
- [mosaicml/mpt-7b-chat](https://huggingface.co/mosaicml/mpt-7b-chat)
- [Neutralzz/BiLLa-7B-SFT](https://huggingface.co/Neutralzz/BiLLa-7B-SFT)
- [nomic-ai/gpt4all-13b-snoozy](https://huggingface.co/nomic-ai/gpt4all-13b-snoozy)
- [NousResearch/Nous-Hermes-13b](https://huggingface.co/NousResearch/Nous-Hermes-13b)
- [openaccess-ai-collective/manticore-13b-chat-pyg](https://huggingface.co/openaccess-ai-collective/manticore-13b-chat-pyg)
- [OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5](https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5)
- [project-baize/baize-v2-7b](https://huggingface.co/project-baize/baize-v2-7b)
- [Salesforce/codet5p-6b](https://huggingface.co/Salesforce/codet5p-6b)
- [StabilityAI/stablelm-tuned-alpha-7b](https://huggingface.co/stabilityai/stablelm-tuned-alpha-7b)
- [THUDM/chatglm-6b](https://huggingface.co/THUDM/chatglm-6b)
- [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b)
- [tiiuae/falcon-40b](https://huggingface.co/tiiuae/falcon-40b)
- [timdettmers/guanaco-33b-merged](https://huggingface.co/timdettmers/guanaco-33b-merged)
- [togethercomputer/RedPajama-INCITE-7B-Chat](https://huggingface.co/togethercomputer/RedPajama-INCITE-7B-Chat)
- [WizardLM/WizardLM-13B-V1.0](https://huggingface.co/WizardLM/WizardLM-13B-V1.0)
- [WizardLM/WizardCoder-15B-V1.0](https://huggingface.co/WizardLM/WizardCoder-15B-V1.0)
- [baichuan-inc/baichuan-7B](https://huggingface.co/baichuan-inc/baichuan-7B)
- [internlm/internlm-chat-7b](https://huggingface.co/internlm/internlm-chat-7b)
- [Qwen/Qwen-7B-Chat](https://huggingface.co/Qwen/Qwen-7B-Chat)
- [HuggingFaceH4/starchat-beta](https://huggingface.co/HuggingFaceH4/starchat-beta)
- 任何 [EleutherAI](https://huggingface.co/EleutherAI) 的 pythia 模型,如 [pythia-6.9b](https://huggingface.co/EleutherAI/pythia-6.9b)
- 在以上模型基础上训练的任何 [Peft](https://github.com/huggingface/peft) 适配器。为了激活,模型路径中必须有 `peft` 。注意如果加载多个peft模型你可以通过在任何模型工作器中设置环境变量 `PEFT_SHARE_BASE_WEIGHTS=true` 来使它们共享基础模型的权重。
以上模型支持列表可能随 [FastChat](https://github.com/lm-sys/FastChat) 更新而持续更新,可参考 [FastChat 已支持模型列表](https://github.com/lm-sys/FastChat/blob/main/docs/model_support.md)。
除本地模型外,本项目也支持直接接入 OpenAI API具体设置可参考 `configs/model_configs.py.example` 中的 `llm_model_dict``openai-chatgpt-3.5` 配置信息。
### Embedding 模型支持
本项目支持调用 [HuggingFace](https://huggingface.co/models?pipeline_tag=sentence-similarity) 中的 Embedding 模型,已支持的 Embedding 模型如下:
- [moka-ai/m3e-small](https://huggingface.co/moka-ai/m3e-small)
- [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base)
- [moka-ai/m3e-large](https://huggingface.co/moka-ai/m3e-large)
- [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh)
- [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh)
- [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh)
- [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct)
- [text2vec-base-chinese-sentence](https://huggingface.co/shibing624/text2vec-base-chinese-sentence)
- [text2vec-base-chinese-paraphrase](https://huggingface.co/shibing624/text2vec-base-chinese-paraphrase)
- [text2vec-base-multilingual](https://huggingface.co/shibing624/text2vec-base-multilingual)
- [shibing624/text2vec-base-chinese](https://huggingface.co/shibing624/text2vec-base-chinese)
- [GanymedeNil/text2vec-large-chinese](https://huggingface.co/GanymedeNil/text2vec-large-chinese)
- [nghuyong/ernie-3.0-nano-zh](https://huggingface.co/nghuyong/ernie-3.0-nano-zh)
- [nghuyong/ernie-3.0-base-zh](https://huggingface.co/nghuyong/ernie-3.0-base-zh)
- [OpenAI/text-embedding-ada-002](https://platform.openai.com/docs/guides/embeddings)
---
## Docker 部署
🐳 Docker 镜像地址: `registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.0)`
接着,创建一个虚拟环境,并在虚拟环境内安装项目的依赖
```shell
docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.0
# 拉取仓库
$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git
# 进入目录
$ cd Langchain-Chatchat
# 安装全部依赖
$ pip install -r requirements.txt
$ pip install -r requirements_api.txt
$ pip install -r requirements_webui.txt
# 默认依赖包括基本运行环境FAISS向量库。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。
```
- 该版本镜像大小 `33.9GB`,使用 `v0.2.0`,以 `nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04` 为基础镜像
- 该版本内置一个 `embedding` 模型:`m3e-large`,内置 `chatglm2-6b-32k`
- 该版本目标为方便一键部署使用请确保您已经在Linux发行版上安装了NVIDIA驱动程序
- 请注意您不需要在主机系统上安装CUDA工具包但需要安装 `NVIDIA Driver` 以及 `NVIDIA Container Toolkit`,请参考[安装指南](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
- 首次拉取和启动均需要一定时间,首次启动时请参照下图使用 `docker logs -f <container id>` 查看日志
- 如遇到启动过程卡在 `Waiting..` 步骤,建议使用 `docker exec -it <container id> bash` 进入 `/logs/` 目录查看对应阶段日志
请注意LangChain-Chatchat `0.2.x` 系列是针对 Langchain `0.0.x` 系列版本的,如果你使用的是 Langchain `0.1.x`
系列版本,需要降级您的`Langchain`版本。
---
### 2. 模型下载
## 开发部署
如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding
模型可以从 [HuggingFace](https://huggingface.co/models) 下载。
### 软件需求
以本项目中默认使用的 LLM 模型 [THUDM/ChatGLM3-6B](https://huggingface.co/THUDM/chatglm3-6b) 与 Embedding
模型 [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) 为例:
本项目已在 Python 3.8.1 - 3.10CUDA 11.7 环境下完成测试。已在 Windows、ARM 架构的 macOS、Linux 系统中完成测试。
### 1. 开发环境准备
参见 [开发环境准备](docs/INSTALL.md)。
**请注意:** `0.2.0` 及更新版本的依赖包与 `0.1.x` 版本依赖包可能发生冲突,强烈建议新建环境后重新安装依赖包。
### 2. 下载模型至本地
如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 [HuggingFace](https://huggingface.co/models) 下载。
以本项目中默认使用的 LLM 模型 [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b) 与 Embedding 模型 [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) 为例:
下载模型需要先[安装Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage),然后运行
下载模型需要先[安装 Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage)
,然后运行
```Shell
$ git clone https://huggingface.co/THUDM/chatglm2-6b
$ git clone https://huggingface.co/moka-ai/m3e-base
$ git lfs install
$ git clone https://huggingface.co/THUDM/chatglm3-6b
$ git clone https://huggingface.co/BAAI/bge-large-zh
```
### 3. 设置配置项
### 3. 初始化知识库和配置文件
复制模型相关参数配置模板文件 [configs/model_config.py.example](configs/model_config.py.example) 存储至项目路径下 `./configs` 路径下,并重命名为 `model_config.py`
按照下列方式初始化自己的知识库和简单的复制配置文件
复制服务相关参数配置模板文件 [configs/server_config.py.example](configs/server_config.py.example) 存储至项目路径下 `./configs` 路径下,并重命名为 `server_config.py`
```shell
$ python copy_config_example.py
$ python init_database.py --recreate-vs
```
在开始执行 Web UI 或命令行交互前,请先检查 `configs/model_config.py``configs/server_config.py` 中的各项模型参数设计是否符合需求:
### 4. 一键启动
- 请确认已下载至本地的 LLM 模型本地存储路径写在 `llm_model_dict` 对应模型的 `local_model_path` 属性中,如:
```python
llm_model_dict={
"chatglm2-6b": {
"local_model_path": "/Users/xxx/Downloads/chatglm2-6b",
"api_base_url": "http://localhost:8888/v1", # "name"修改为 FastChat 服务中的"api_base_url"
"api_key": "EMPTY"
},
}
```
- 请确认已下载至本地的 Embedding 模型本地存储路径写在 `embedding_model_dict` 对应模型位置,如:
```python
embedding_model_dict = {
"m3e-base": "/Users/xxx/Downloads/m3e-base",
}
```
如果你选择使用OpenAI的Embedding模型请将模型的 ``key``写入 `embedding_model_dict`中。使用该模型你需要能够访问OpenAI官的API或设置代理。
### 4. 知识库初始化与迁移
当前项目的知识库信息存储在数据库中,在正式运行项目之前请先初始化数据库(我们强烈建议您在执行操作前备份您的知识文件)。
- 如果您是从 `0.1.x` 版本升级过来的用户针对已建立的知识库请确认知识库的向量库类型、Embedding 模型与 `configs/model_config.py` 中默认设置一致,如无变化只需以下命令将现有知识库信息添加到数据库即可:
```shell
$ python init_database.py
```
- 如果您是第一次运行本项目,知识库尚未建立,或者配置文件中的知识库类型、嵌入模型发生变化,或者之前的向量库没有开启 `normalize_L2`,需要以下命令初始化或重建知识库:
```shell
$ python init_database.py --recreate-vs
```
### 5. 一键启动API 服务或 Web UI
#### 5.1 启动命令
一键启动脚本 startup.py,一键启动所有 Fastchat 服务、API 服务、WebUI 服务,示例代码:
按照以下命令启动项目
```shell
$ python startup.py -a
```
并可使用 `Ctrl + C` 直接关闭所有运行服务。如果一次结束不了,可以多按几次。
### 5. 启动界面示例
可选参数包括 `-a (或--all-webui)`, `--all-api`, `--llm-api`, `-c (或--controller)`, `--openai-api`,
`-m (或--model-worker)`, `--api`, `--webui`,其中:
如果正常启动,你将能看到以下界面
- `--all-webui` 为一键启动 WebUI 所有依赖服务;
- `--all-api` 为一键启动 API 所有依赖服务;
- `--llm-api` 为一键启动 Fastchat 所有依赖的 LLM 服务;
- `--openai-api` 为仅启动 FastChat 的 controller 和 openai-api-server 服务;
- 其他为单独服务启动选项。
1. FastAPI Docs 界面
#### 5.2 启动非默认模型
![](img/fastapi_docs_026.png)
若想指定非默认模型,需要用 `--model-name` 选项,示例:
```shell
$ python startup.py --all-webui --model-name Qwen-7B-Chat
```
更多信息可通过 `python startup.py -h`查看。
#### 5.3 多卡加载
项目支持多卡加载,需在 startup.py 中的 create_model_worker_app 函数中,修改如下三个参数:
```python
gpus=None,
num_gpus=1,
max_gpu_memory="20GiB"
```
其中,`gpus` 控制使用的显卡的ID例如 "0,1";
`num_gpus` 控制使用的卡数;
`max_gpu_memory` 控制每个卡使用的显存容量。
注1server_config.py的FSCHAT_MODEL_WORKERS字典中也增加了相关配置如有需要也可通过修改FSCHAT_MODEL_WORKERS字典中对应参数实现多卡加载。
注2少数情况下gpus参数会不生效此时需要通过设置环境变量CUDA_VISIBLE_DEVICES来指定torch可见的gpu,示例代码:
```shell
CUDA_VISIBLE_DEVICES=0,1 python startup.py -a
```
#### 5.4 PEFT 加载(包括lora,p-tuning,prefix tuning, prompt tuning,ia3等)
本项目基于 FastChat 加载 LLM 服务,故需以 FastChat 加载 PEFT 路径,即保证路径名称里必须有 peft 这个词,配置文件的名字为 adapter_config.jsonpeft 路径下包含.bin 格式的 PEFT 权重peft路径在startup.py中create_model_worker_app函数的args.model_names中指定并开启环境变量PEFT_SHARE_BASE_WEIGHTS=true参数。
如果上述方式启动失败则需要以标准的fastchat服务启动方式分步启动分步启动步骤参考第六节PEFT加载详细步骤参考[加载lora微调后模型失效](https://github.com/chatchat-space/Langchain-Chatchat/issues/1130#issuecomment-1685291822)
#### **5.5 注意事项:**
**1. startup 脚本用多进程方式启动各模块的服务,可能会导致打印顺序问题,请等待全部服务发起后再调用,并根据默认或指定端口调用服务(默认 LLM API 服务端口:`127.0.0.1:8888`,默认 API 服务端口:`127.0.0.1:7861`,默认 WebUI 服务端口:`本机IP8501`)**
**2.服务启动时间示设备不同而不同,约 3-10 分钟,如长时间没有启动请前往 `./logs`目录下监控日志,定位问题。**
**3. 在Linux上使用ctrl+C退出可能会由于linux的多进程机制导致multiprocessing遗留孤儿进程可通过shutdown_all.sh进行退出**
#### 5.6 启动界面示例:
1. FastAPI docs 界面
![](img/fastapi_docs_020_0.png)
2. webui启动界面示例
- Web UI 对话界面:
![img](img/webui_0813_0.png)
- Web UI 知识库管理页面:
![](img/webui_0813_1.png)
### 6 分步启动 API 服务或 Web UI
注意:如使用了一键启动方式,可忽略本节。
#### 6.1 启动 LLM 服务
如需使用开源模型进行本地部署,需首先启动 LLM 服务,启动方式分为三种:
- [基于多进程脚本 llm_api.py 启动 LLM 服务](README.md#5.1.1-基于多进程脚本-llm_api.py-启动-LLM-服务)
- [基于命令行脚本 llm_api_stale.py 启动 LLM 服务](README.md#5.1.2-基于命令行脚本-llm_api_stale.py-启动-LLM-服务)
- [PEFT 加载](README.md#5.1.3-PEFT-加载)
三种方式只需选择一个即可,具体操作方式详见 5.1.1 - 5.1.3。
如果启动在线的API服务如 OPENAI 的 API 接口),则无需启动 LLM 服务,即 5.1 小节的任何命令均无需启动。
##### 6.1.1 基于多进程脚本 llm_api.py 启动 LLM 服务
在项目根目录下,执行 [server/llm_api.py](server/llm_api.py) 脚本启动 **LLM 模型**服务:
```shell
$ python server/llm_api.py
```
项目支持多卡加载,需在 llm_api.py 中的 create_model_worker_app 函数中,修改如下三个参数:
```python
gpus=None,
num_gpus=1,
max_gpu_memory="20GiB"
```
其中,`gpus` 控制使用的显卡的ID如果 "0,1";
`num_gpus` 控制使用的卡数;
`max_gpu_memory` 控制每个卡使用的显存容量。
##### 6.1.2 基于命令行脚本 llm_api_stale.py 启动 LLM 服务
⚠️ **注意:**
**1.llm_api_stale.py脚本原生仅适用于linux,mac设备需要安装对应的linux命令,win平台请使用wsl;**
**2.加载非默认模型需要用命令行参数--model-path-address指定模型不会读取model_config.py配置;**
在项目根目录下,执行 [server/llm_api_stale.py](server/llm_api_stale.py) 脚本启动 **LLM 模型**服务:
```shell
$ python server/llm_api_stale.py
```
该方式支持启动多个worker示例启动方式
```shell
$ python server/llm_api_stale.py --model-path-address model1@host1@port1 model2@host2@port2
```
如果出现server端口占用情况需手动指定server端口,并同步修改model_config.py下对应模型的base_api_url为指定端口:
```shell
$ python server/llm_api_stale.py --server-port 8887
```
如果要启动多卡加载,示例命令如下:
```shell
$ python server/llm_api_stale.py --gpus 0,1 --num-gpus 2 --max-gpu-memory 10GiB
```
以如上方式启动LLM服务会以nohup命令在后台运行 FastChat 服务,如需停止服务,可以运行如下命令:
```shell
$ python server/llm_api_shutdown.py --serve all
```
亦可单独停止一个 FastChat 服务模块,可选 [`all`, `controller`, `model_worker`, `openai_api_server`]
##### 6.1.3 PEFT 加载(包括lora,p-tuning,prefix tuning, prompt tuning,ia3等)
本项目基于 FastChat 加载 LLM 服务,故需以 FastChat 加载 PEFT 路径,即保证路径名称里必须有 peft 这个词,配置文件的名字为 adapter_config.jsonpeft 路径下包含 model.bin 格式的 PEFT 权重。
详细步骤参考[加载lora微调后模型失效](https://github.com/chatchat-space/Langchain-Chatchat/issues/1130#issuecomment-1685291822)
![image](https://github.com/chatchat-space/Langchain-Chatchat/assets/22924096/4e056c1c-5c4b-4865-a1af-859cd58a625d)
#### 6.2 启动 API 服务
本地部署情况下,按照 [5.1 节](README.md#5.1-启动-LLM-服务)**启动 LLM 服务后**,再执行 [server/api.py](server/api.py) 脚本启动 **API** 服务;
在线调用API服务的情况下直接执执行 [server/api.py](server/api.py) 脚本启动 **API** 服务;
调用命令示例:
```shell
$ python server/api.py
```
启动 API 服务后,可访问 `localhost:7861``{API 所在服务器 IP}:7861` FastAPI 自动生成的 docs 进行接口查看与测试。
- FastAPI docs 界面
![](img/fastapi_docs_020_0.png)
#### 6.3 启动 Web UI 服务
按照 [5.2 节](README.md#5.2-启动-API-服务)**启动 API 服务后**,执行 [webui.py](webui.py) 启动 **Web UI** 服务(默认使用端口 `8501`
```shell
$ streamlit run webui.py
```
使用 Langchain-Chatchat 主题色启动 **Web UI** 服务(默认使用端口 `8501`
```shell
$ streamlit run webui.py --theme.base "light" --theme.primaryColor "#165dff" --theme.secondaryBackgroundColor "#f5f5f5" --theme.textColor "#000000"
```
或使用以下命令指定启动 **Web UI** 服务并指定端口号
```shell
$ streamlit run webui.py --server.port 666
```
2. Web UI 启动界面示例:
- Web UI 对话界面:
![](img/webui_0813_0.png)
![img](img/LLM_success.png)
- Web UI 知识库管理页面:
![](img/webui_0813_1.png)
![](img/init_knowledge_base.jpg)
### 注意
以上方式只是为了快速上手,如果需要更多的功能和自定义启动方式
,请参考[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
---
## 常见问题
## 项目里程碑
参见 [常见问题](docs/FAQ.md)。
+ `2023年4月`: `Langchain-ChatGLM 0.1.0` 发布,支持基于 ChatGLM-6B 模型的本地知识库问答。
+ `2023年8月`: `Langchain-ChatGLM` 改名为 `Langchain-Chatchat``0.2.0` 发布,使用 `fastchat` 作为模型加载方案,支持更多的模型和数据库。
+ `2023年10月`: `Langchain-Chatchat 0.2.5` 发布,推出 Agent 内容,开源项目在`Founder Park & Zhipu AI & Zilliz`
举办的黑客马拉松获得三等奖。
+ `2023年12月`: `Langchain-Chatchat` 开源项目获得超过 **20K** stars.
+ `2024年1月`: `LangChain 0.1.x` 推出,`Langchain-Chatchat 0.2.x` 发布稳定版本`0.2.10`
后将停止更新和技术支持,全力研发具有更强应用性的 `Langchain-Chatchat 0.3.x`
+ 🔥 让我们一起期待未来 Chatchat 的故事 ···
---
## 路线图
## 联系我们
- [X] Langchain 应用
- [X] 本地数据接入
- [X] 接入非结构化文档
- [X] .md
- [X] .txt
- [X] .docx
- [ ] 结构化数据接入
- [X] .csv
- [ ] .xlsx
- [ ] 分词及召回
- [ ] 接入不同类型 TextSplitter
- [ ] 优化依据中文标点符号设计的 ChineseTextSplitter
- [ ] 重新实现上下文拼接召回
- [ ] 本地网页接入
- [ ] SQL 接入
- [ ] 知识图谱/图数据库接入
- [X] 搜索引擎接入
- [X] Bing 搜索
- [X] DuckDuckGo 搜索
- [ ] Agent 实现
- [X] LLM 模型接入
- [X] 支持通过调用 [FastChat](https://github.com/lm-sys/fastchat) api 调用 llm
- [ ] 支持 ChatGLM API 等 LLM API 的接入
- [X] Embedding 模型接入
- [X] 支持调用 HuggingFace 中各开源 Emebdding 模型
- [ ] 支持 OpenAI Embedding API 等 Embedding API 的接入
- [X] 基于 FastAPI 的 API 方式调用
- [X] Web UI
- [X] 基于 Streamlit 的 Web UI
### Telegram
---
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatglm")](https://t.me/+RjliQ3jnJ1YyN2E9)
## 项目交流群
### 项目交流群
<img src="img/qr_code_108.jpg" alt="二维码" width="300" />
<img src="img/qr_code_58.jpg" alt="二维码" width="300" height="300" />
🎉 Langchain-Chatchat 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
🎉 langchain-ChatGLM 项目微信交流群,如果你也对本项目感兴趣,欢迎加入群聊参与讨论交流。
### 公众号
<img src="img/official_wechat_mp_account.png" alt="二维码" width="300" />
🎉 Langchain-Chatchat 项目官方公众号,欢迎扫码关注。

207
README_en.md Normal file
View File

@ -0,0 +1,207 @@
![](img/logo-long-chatchat-trans-v2.png)
🌍 [中文文档](README.md)
🌍 [日本語で読む](README_ja.md)
📃 **LangChain-Chatchat** (formerly Langchain-ChatGLM):
A LLM application aims to implement knowledge and search engine based QA based on Langchain and open-source or remote
LLM API.
⚠️`0.2.10` will be the last version of the `0.2.x` series. The `0.2.x` series will stop updating and technical support,
and strive to develop `Langchain-Chachat 0.3.x` with stronger applicability.
Subsequent bug fixes for `0.2.10` will be pushed directly to the `master` branch without version updates.
---
## Table of Contents
- [Introduction](README.md#Introduction)
- [Pain Points Addressed](README.md#Pain-Points-Addressed)
- [Quick Start](README.md#Quick-Start)
- [1. Environment Setup](README.md#1-Environment-Setup)
- [2. Model Download](README.md#2-Model-Download)
- [3. Initialize Knowledge Base and Configuration Files](README.md#3-Initialize-Knowledge-Base-and-Configuration-Files)
- [4. One-Click Startup](README.md#4-One-Click-Startup)
- [5. Startup Interface Examples](README.md#5-Startup-Interface-Examples)
- [Contact Us](README.md#Contact-Us)
## Introduction
🤖️ A Q&A application based on local knowledge base implemented using the idea
of [langchain](https://github.com/langchain-ai/langchain). The goal is to build a KBQA(Knowledge based Q&A) solution
that
is friendly to Chinese scenarios and open source models and can run both offline and online.
💡 Inspired by [document.ai](https://github.com/GanymedeNil/document.ai)
and [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216) , we build a local knowledge base question
answering application that can be implemented using an open source model or remote LLM api throughout the process. In
the latest version of this project, [FastChat](https://github.com/lm-sys/FastChat) is used to access Vicuna, Alpaca,
LLaMA, Koala, RWKV and many other models. Relying on [langchain](https://github.com/langchain-ai/langchain) , this
project supports calling services through the API provided based on [FastAPI](https://github.com/tiangolo/fastapi), or
using the WebUI based on [Streamlit](https://github.com/streamlit/streamlit).
✅ Relying on the open source LLM and Embedding models, this project can realize full-process **offline private
deployment**. At the same time, this project also supports the call of OpenAI GPT API- and Zhipu API, and will continue
to expand the access to various models and remote APIs in the future.
⛓️ The implementation principle of this project is shown in the graph below. The main process includes: loading files ->
reading text -> text segmentation -> text vectorization -> question vectorization -> matching the `top-k` most similar
to the question vector in the text vector -> The matched text is added to `prompt `as context and question -> submitte
to `LLM` to generate an answer.
📺[video introduction](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)
![实现原理图](img/langchain+chatglm.png)
The main process analysis from the aspect of document process:
![实现原理图2](img/langchain+chatglm2.png)
🚩 The training or fine-tuning are not involved in the project, but still, one always can improve performance by do
these.
🌐 [AutoDL image](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) is supported, and in `0.2.10` the codes are update to v0.2.10.
🐳 [Docker image](isafetech/chatchat:0.2.10) is supported to ```0.2.10```.
🌲 The latest update also provides support for image sources from DockerHub, Ali Cloud, and Tencent Cloud:
```shell
docker run -d --gpus all -p 80:8501 isafetech/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 uswccr.ccs.tencentyun.com/chatchat/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.10
```
## Pain Points Addressed
This project is a solution for enhancing knowledge bases with fully localized inference, specifically addressing the
pain points of data security and private deployments for businesses.
This open-source solution is under the Apache License and can be used for commercial purposes for free, with no fees
required.
We support mainstream local large prophecy models and Embedding models available in the market, as well as open-source
local vector databases. For a detailed list of supported models and databases, please refer to
our [Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
## Quick Start
### Environment Setup
First, make sure your machine has Python 3.10 installed.
```
$ python --version
Python 3.10.12
```
Then, create a virtual environment and install the project's dependencies within the virtual environment.
```shell
# 拉取仓库
$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git
# 进入目录
$ cd Langchain-Chatchat
# 安装全部依赖
$ pip install -r requirements.txt
$ pip install -r requirements_api.txt
$ pip install -r requirements_webui.txt
# 默认依赖包括基本运行环境FAISS向量库。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。
```
Please note that the LangChain-Chachat `0.2.x` series is for the Langchain `0.0.x` series version. If you are using the
Langchain `0.1.x` series version, you need to downgrade.
### Model Download
If you need to run this project locally or in an offline environment, you must first download the required models for
the project. Typically, open-source LLM and Embedding models can be downloaded from HuggingFace.
Taking the default LLM model used in this project, [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b), and
the Embedding model [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) as examples:
To download the models, you need to first
install [Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage)
and then run:
```Shell
$ git lfs install
$ git clone https://huggingface.co/THUDM/chatglm2-6b
$ git clone https://huggingface.co/moka-ai/m3e-base
```
### Initializing the Knowledge Base and Config File
Follow the steps below to initialize your own knowledge base and config file:
```shell
$ python copy_config_example.py
$ python init_database.py --recreate-vs
```
### One-Click Launch
To start the project, run the following command:
```shell
$ python startup.py -a
```
### Example of Launch Interface
1. FastAPI docs interface
![](img/fastapi_docs_026.png)
2. webui page
- Web UI dialog page:
![img](img/LLM_success.png)
- Web UI knowledge base management page:
![](img/init_knowledge_base.jpg)
### Note
The above instructions are provided for a quick start. If you need more features or want to customize the launch method,
please refer to the [Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/).
---
## Project Milestones
+ `April 2023`: `Langchain-ChatGLM 0.1.0` released, supporting local knowledge base question and answer based on the
ChatGLM-6B model.
+ `August 2023`: `Langchain-ChatGLM` was renamed to `Langchain-Chatchat`, `0.2.0` was released, using `fastchat` as the
model loading solution, supporting more models and databases.
+ `October 2023`: `Langchain-Chachat 0.2.5` was released, Agent content was launched, and the open source project won
the third prize in the hackathon held by `Founder Park & Zhipu AI & Zilliz`.
+ `December 2023`: `Langchain-Chachat` open source project received more than **20K** stars.
+ `January 2024`: `LangChain 0.1.x` is launched, `Langchain-Chachat 0.2.x` is released. After the stable
version `0.2.10` is released, updates and technical support will be stopped, and all efforts will be made to
develop `Langchain with stronger applicability -Chat 0.3.x`.
+ 🔥 Lets look forward to the future Chatchat stories together···
---
## Contact Us
### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatglm")](https://t.me/+RjliQ3jnJ1YyN2E9)
### WeChat Group
<img src="img/qr_code_90.jpg" alt="二维码" width="300" height="300" />
### WeChat Official Account
<img src="img/official_wechat_mp_account.png" alt="图片" width="900" height="300" />

200
README_ja.md Normal file
View File

@ -0,0 +1,200 @@
![](img/logo-long-chatchat-trans-v2.png)
🌍 [中文文档](README.md)
🌍 [READ THIS IN ENGLISH](README_en.md)
📃 **LangChain-Chatchat** (旧名 Langchain-ChatGLM)
ChatGLM などの大規模な言語モデルや Langchain などのアプリケーション フレームワークに基づいた、オープン
ソースのオフライン展開可能な検索拡張生成 (RAG) 大規模モデル ナレッジ ベース プロジェクトです。
⚠️`0.2.10``0.2.x` シリーズの最終バージョンとなり、`0.2.x`
シリーズはアップデートと技術サポートを終了し、より適用性の高い `Langchain-Chachat 0.3.x` の開発に努めます。 。
`0.2.10` のその後のバグ修正は、バージョン更新なしで `master` ブランチに直接プッシュされます。
---
## 目次
- [イントロ](README_ja.md#イントロ)
- [ペインポイントへの対応](README_ja.md#ペインポイントへの対応)
- [クイックスタート](README_ja.md#クイックスタート)
- [1. 環境セットアップ](README_ja.md#環境セットアップ)
- [2. モデルをダウンロード](README_ja.md#モデルをダウンロード)
- [3. ナレッジベースと設定ファイルの初期化](README_ja.md#ナレッジベースと設定ファイルの初期化)
- [4. ワンクリック起動](README_ja.md#ワンクリック起動)
- [5. 起動インターフェースの例](README_ja.md#起動インターフェースの例)
- [お問い合わせ](README_ja.md#お問い合わせ)
## イントロ
🤖️ [langchain](https://github.com/hwchase17/langchain) のアイデアを用いて実装された、ローカルナレッジベースに基づく Q&A
アプリケーション。
目標は、中国のシナリオとオープンソースモデルに親和性があり、オフラインとオンラインの両方で実行可能な KBQAナレッジベースの
Q&Aソリューションを構築することです。
💡 [document.ai](https://github.com/GanymedeNil/document.ai)
と [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216) に触発され、
プロセス全体を通してオープンソースモデルまたはリモート LLM api を使用して実装することができるローカルナレッジベースの質問応答アプリケーションを構築します。
このプロジェクトの最新バージョンでは、[FastChat](https://github.com/lm-sys/FastChat)
を使用して、Vicuna、Alpaca、LLaMA、Koala、RWKV、その他多くのモデルにアクセスしています。
このプロジェクトは [langchain](https://github.com/langchain-ai/langchain)
に依存し、[FastAPI](https://github.com/tiangolo/fastapi) に基づいて提供されるAPIを通してサービスを呼び出したり、
[Streamlit](https://github.com/streamlit/streamlit) に基づいて WebUI を使ったりすることをサポートしています。
✅ オープンソースの LLM と Embedding モデルに依存して、このプロジェクトはフルプロセスの **オフラインプライベートデプロイメント
** を実現することができます。
同時に、本プロジェクトは OpenAI GPT API や Zhipu API の呼び出しにも対応しており、今後も様々な機種やリモート API
へのアクセスを拡大していきます。
⛓️ このプロジェクトの実施原則を下のグラフに示します。主なプロセスは以下の通りです:
ファイルの読み込み -> テキストの読み込み -> テキストのセグメンテーション -> テキストのベクトル化 -> 質問のベクトル化 ->
質問ベクトルと最も似ている `top-k` をテキストベクトルでマッチング ->
マッチしたテキストをコンテキストと質問として `prompt` に追加 -> 回答を生成するために `LLM` に送信。
📺[video introduction](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)
![实现原理图](img/langchain+chatglm.png)
文書プロセスの側面からの主なプロセス分析:
![实现原理图2](img/langchain+chatglm2.png)
🚩 トレーニングやファインチューニングはプロジェクトには含まれないが、これらを行うことで必ずパフォーマンスを向上させることができます。
🌐 [AutoDL イメージ](registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.5)がサポートされ、`0.2.10` では v0.2.10
にアップデートされました。
🐳 [Docker イメージ](isafetech/chatchat:0.2.10)
🌲 今回のアップデートにより、DockerHub、阿里雲、騰訊のクラウドにも対応しました。より広範なクラウド環境で利用可能となりました。
```shell
docker run -d --gpus all -p 80:8501 isafetech/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 uswccr.ccs.tencentyun.com/chatchat/chatchat:0.2.10
docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.10
```
## ペインポイントへの対応
このプロジェクトは、完全にローカライズされた推論によってナレッジベースを強化するソリューションであり、特にデータセキュリティと企業向けのプライベートな展開の問題に取り組んでいます。
このオープンソースソリューションは Apache ライセンスに基づき、無償で商用利用できます。
私たちは、市場で入手可能な主流のローカル大予言モデルや Embedding モデル、オープンソースのローカルベクターデータベースをサポートしています。
対応機種とデータベースの詳細については、[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) をご参照ください。
## クイックスタート
### 環境セットアップ
まず、マシンにPython 3.10がインストールされていることを確認してください。
```
$ python --version
Python 3.11.7
```
次に、仮想環境を作成し、プロジェクトの依存関係を仮想環境内にインストールする。
```shell
# リポジトリをクローン
$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git
# ディレクトリに移動
$ cd Langchain-Chatchat
# すべての依存関係をインストール
$ pip install -r requirements.txt
$ pip install -r requirements_api.txt
$ pip install -r requirements_webui.txt
# デフォルトの依存関係には、基本的な実行環境(FAISS ベクターライブラリ)が含まれます。milvus/pg_vector などのベクターライブラリを使用する場合は、requirements.txt 内の対応する依存関係のコメントを解除してからインストールしてください。
```
LangChain-Chachat `0.2.x` シリーズは Langchain `0.0.x` シリーズ用です。Langchain `0.1.x` シリーズをお使いの場合は、ダウングレードする必要があります。
### モデルをダウンロード
このプロジェクトをローカルまたはオフライン環境で実行する必要がある場合は、まずプロジェクトに必要なモデルをダウンロードする必要があります。
通常、オープンソースの LLM と Embedding モデルは Hugging Face からダウンロードできる。
このプロジェクトで使用されているデフォルトの LLM
モデルである [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b)と、Embedding
モデル [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) を例にとると、次のようになります:
モデルをダウンロードするには、まず [Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage)
をインストールし、次のように実行する必要があります:
```Shell
$ git lfs install
$ git clone https://huggingface.co/THUDM/chatglm2-6b
$ git clone https://huggingface.co/moka-ai/m3e-base
```
### ナレッジベースと設定ファイルの初期化
以下の手順に従って、ナレッジベースと設定ファイルを初期化してください:
```shell
$ python copy_config_example.py
$ python init_database.py --recreate-vs
```
### ワンクリック起動
プロジェクトを開始するには、次のコマンドを実行します:
```shell
$ python startup.py -a
```
### 起動インターフェースの例
1. FastAPI docs インターフェース
![](img/fastapi_docs_026.png)
2. webui ページ
- Web UI ダイアログページ:
![img](img/LLM_success.png)
- Web UI ナレッジベースマネジメントページ:
![](img/init_knowledge_base.jpg)
### 注
上記の手順はクイックスタートのために提供されています。より多くの機能が必要な場合や、起動方法をカスタマイズしたい場合は、[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/)
を参照してください。
---
## プロジェクトのマイルストーン
+ `2023 年 4 月`: `Langchain-ChatGLM 0.1.0` がリリースされ、ChatGLM-6B モデルに基づくローカル ナレッジ ベースの質問と回答がサポートされました。
+ `2023 年 8 月`: `Langchain-ChatGLM``Langchain-Chatchat` に名前変更され、モデル読み込みソリューションとして `fastchat` を使用し、より多くのモデルとデータベースをサポートする `0.2.0` がリリースされました。
+ `2023 年 10 月`: `Langchain-Chachat 0.2.5` リリース、エージェント コンテンツ、オープンソース プロジェクトを`Founder Park & Zhipu AI & Zilliz`で開始
開催したハッカソンでは3位に入賞しました。
+ `2023 年 12 月`: `Langchain-Chachat`オープンソース プロジェクトは **20,000** つ以上のスターを獲得しました。
+ `2024 年 1 月`: `LangChain 0.1.x` がリリースされ、`Langchain-Chachat 0.2.x` が安定版 `0.2.10` をリリースしました。
今後はアップデートと技術サポートを停止し、より適用性の高い`Langchain-Chachat 0.3.x`の開発に努める予定です。
+ 🔥 これからのChatchatストーリーを一緒に楽しみにしましょう···
---
## お問い合わせ
### Telegram
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white "langchain-chatglm")](https://t.me/+RjliQ3jnJ1YyN2E9)
### WeChat グループ
<img src="img/qr_code_90.jpg" alt="二维码" width="300" height="300" />
### WeChat 公式アカウント
<img src="img/official_wechat_mp_account.png" alt="图片" width="900" height="300" />

View File

@ -1,19 +1,12 @@
from langchain.chat_models import ChatOpenAI
from configs.model_config import llm_model_dict, LLM_MODEL
from langchain import LLMChain
from server.utils import get_ChatOpenAI
from configs.model_config import LLM_MODELS, TEMPERATURE
from langchain.chains import LLMChain
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
)
model = ChatOpenAI(
streaming=True,
verbose=True,
# callbacks=[callback],
openai_api_key=llm_model_dict[LLM_MODEL]["api_key"],
openai_api_base=llm_model_dict[LLM_MODEL]["api_base_url"],
model_name=LLM_MODEL
)
model = get_ChatOpenAI(model_name=LLM_MODELS[0], temperature=TEMPERATURE)
human_prompt = "{input}"

View File

@ -1,4 +1,8 @@
from .basic_config import *
from .model_config import *
from .kb_config import *
from .server_config import *
from .prompt_config import *
VERSION = "v0.2.3"
VERSION = "v0.2.10"

View File

@ -0,0 +1,32 @@
import logging
import os
import langchain
import tempfile
import shutil
# 是否显示详细日志
log_verbose = False
langchain.verbose = False
# 通常情况下不需要更改以下内容
# 日志格式
LOG_FORMAT = "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logging.basicConfig(format=LOG_FORMAT)
# 日志存储路径
LOG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs")
if not os.path.exists(LOG_PATH):
os.mkdir(LOG_PATH)
# 临时文件目录,主要用于文件对话
BASE_TEMP_DIR = os.path.join(tempfile.gettempdir(), "chatchat")
try:
shutil.rmtree(BASE_TEMP_DIR)
except Exception:
pass
os.makedirs(BASE_TEMP_DIR, exist_ok=True)

View File

@ -0,0 +1,146 @@
import os
# 默认使用的知识库
DEFAULT_KNOWLEDGE_BASE = "samples"
# 默认向量库/全文检索引擎类型。可选faiss, milvus(离线) & zilliz(在线), pgvector, chromadb 全文检索引擎es
DEFAULT_VS_TYPE = "faiss"
# 缓存向量库数量针对FAISS
CACHED_VS_NUM = 1
# 缓存临时向量库数量针对FAISS用于文件对话
CACHED_MEMO_VS_NUM = 10
# 知识库中单段文本长度(不适用MarkdownHeaderTextSplitter)
CHUNK_SIZE = 250
# 知识库中相邻文本重合长度(不适用MarkdownHeaderTextSplitter)
OVERLAP_SIZE = 50
# 知识库匹配向量数量
VECTOR_SEARCH_TOP_K = 3
# 知识库匹配的距离阈值一般取值范围在0-1之间SCORE越小距离越小从而相关度越高。
# 但有用户报告遇到过匹配分值超过1的情况为了兼容性默认设为1在WEBUI中调整范围为0-2
SCORE_THRESHOLD = 1.0
# 默认搜索引擎。可选bing, duckduckgo, metaphor
DEFAULT_SEARCH_ENGINE = "duckduckgo"
# 搜索引擎匹配结题数量
SEARCH_ENGINE_TOP_K = 3
# Bing 搜索必备变量
# 使用 Bing 搜索需要使用 Bing Subscription Key,需要在azure port中申请试用bing search
# 具体申请方式请见
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/create-bing-search-service-resource
# 使用python创建bing api 搜索实例详见:
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/quickstarts/rest/python
BING_SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search"
# 注意不是bing Webmaster Tools的api key
# 此外如果是在服务器上报Failed to establish a new connection: [Errno 110] Connection timed out
# 是因为服务器加了防火墙需要联系管理员加白名单如果公司的服务器的话就别想了GG
BING_SUBSCRIPTION_KEY = ""
# metaphor搜索需要KEY
METAPHOR_API_KEY = ""
# 心知天气 API KEY用于天气Agent。申请https://www.seniverse.com/
SENIVERSE_API_KEY = ""
# 是否开启中文标题加强,以及标题增强的相关配置
# 通过增加标题判断判断哪些文本为标题并在metadata中进行标记
# 然后将文本与往上一级的标题进行拼合,实现文本信息的增强。
ZH_TITLE_ENHANCE = False
# PDF OCR 控制:只对宽高超过页面一定比例(图片宽/页面宽,图片高/页面高)的图片进行 OCR。
# 这样可以避免 PDF 中一些小图片的干扰,提高非扫描版 PDF 处理速度
PDF_OCR_THRESHOLD = (0.6, 0.6)
# 每个知识库的初始化介绍用于在初始化知识库时显示和Agent调用没写则没有介绍不会被Agent调用。
KB_INFO = {
"知识库名称": "知识库介绍",
"samples": "关于本项目issue的解答",
}
# 通常情况下不需要更改以下内容
# 知识库默认存储路径
KB_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "knowledge_base")
if not os.path.exists(KB_ROOT_PATH):
os.mkdir(KB_ROOT_PATH)
# 数据库默认存储路径。
# 如果使用sqlite可以直接修改DB_ROOT_PATH如果使用其它数据库请直接修改SQLALCHEMY_DATABASE_URI。
DB_ROOT_PATH = os.path.join(KB_ROOT_PATH, "info.db")
SQLALCHEMY_DATABASE_URI = f"sqlite:///{DB_ROOT_PATH}"
# 可选向量库类型及对应配置
kbs_config = {
"faiss": {
},
"milvus": {
"host": "127.0.0.1",
"port": "19530",
"user": "",
"password": "",
"secure": False,
},
"zilliz": {
"host": "in01-a7ce524e41e3935.ali-cn-hangzhou.vectordb.zilliz.com.cn",
"port": "19530",
"user": "",
"password": "",
"secure": True,
},
"pg": {
"connection_uri": "postgresql://postgres:postgres@127.0.0.1:5432/langchain_chatchat",
},
"es": {
"host": "127.0.0.1",
"port": "9200",
"index_name": "test_index",
"user": "",
"password": ""
},
"milvus_kwargs":{
"search_params":{"metric_type": "L2"}, #在此处增加search_params
"index_params":{"metric_type": "L2","index_type": "HNSW"} # 在此处增加index_params
},
"chromadb": {}
}
# TextSplitter配置项如果你不明白其中的含义就不要修改。
text_splitter_dict = {
"ChineseRecursiveTextSplitter": {
"source": "huggingface", # 选择tiktoken则使用openai的方法
"tokenizer_name_or_path": "",
},
"SpacyTextSplitter": {
"source": "huggingface",
"tokenizer_name_or_path": "gpt2",
},
"RecursiveCharacterTextSplitter": {
"source": "tiktoken",
"tokenizer_name_or_path": "cl100k_base",
},
"MarkdownHeaderTextSplitter": {
"headers_to_split_on":
[
("#", "head1"),
("##", "head2"),
("###", "head3"),
("####", "head4"),
]
},
}
# TEXT_SPLITTER 名称
TEXT_SPLITTER_NAME = "ChineseRecursiveTextSplitter"
# Embedding模型定制词语的词表文件
EMBEDDING_KEYWORD_FILE = "embedding_keywords.txt"

View File

@ -1,177 +1,327 @@
import os
import logging
# 日志格式
LOG_FORMAT = "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logging.basicConfig(format=LOG_FORMAT)
# 在以下字典中修改属性值以指定本地embedding模型存储位置
# 如将 "text2vec": "GanymedeNil/text2vec-large-chinese" 修改为 "text2vec": "User/Downloads/text2vec-large-chinese"
# 此处请写绝对路径
embedding_model_dict = {
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
"ernie-base": "nghuyong/ernie-3.0-base-zh",
"text2vec-base": "shibing624/text2vec-base-chinese",
"text2vec": "GanymedeNil/text2vec-large-chinese",
"text2vec-paraphrase": "shibing624/text2vec-base-chinese-paraphrase",
"text2vec-sentence": "shibing624/text2vec-base-chinese-sentence",
"text2vec-multilingual": "shibing624/text2vec-base-multilingual",
"m3e-small": "moka-ai/m3e-small",
"m3e-base": "moka-ai/m3e-base",
"m3e-large": "moka-ai/m3e-large",
"bge-small-zh": "BAAI/bge-small-zh",
"bge-base-zh": "BAAI/bge-base-zh",
"bge-large-zh": "BAAI/bge-large-zh",
"bge-large-zh-noinstruct": "BAAI/bge-large-zh-noinstruct",
"text-embedding-ada-002": os.environ.get("OPENAI_API_KEY")
}
# 可以指定一个绝对路径统一存放所有的Embedding和LLM模型。
# 每个模型可以是一个单独的目录,也可以是某个目录下的二级子目录。
# 如果模型目录名称和 MODEL_PATH 中的 key 或 value 相同,程序会自动检测加载,无需修改 MODEL_PATH 中的路径。
MODEL_ROOT_PATH = ""
# 选用的 Embedding 名称
EMBEDDING_MODEL = "m3e-base"
EMBEDDING_MODEL = "bge-large-zh-v1.5"
# Embedding 模型运行设备。设为"auto"会自动检测,也可手动设定为"cuda","mps","cpu"其中之一。
# Embedding 模型运行设备。设为 "auto" 会自动检测(会有警告),也可手动设定为 "cuda","mps","cpu","xpu" 其中之一。
EMBEDDING_DEVICE = "auto"
llm_model_dict = {
"chatglm-6b": {
"local_model_path": "THUDM/chatglm-6b",
"api_base_url": "http://localhost:8888/v1", # "name"修改为fastchat服务中的"api_base_url"
"api_key": "EMPTY"
},
# 选用的reranker模型
RERANKER_MODEL = "bge-reranker-large"
# 是否启用reranker模型
USE_RERANKER = False
RERANKER_MAX_LENGTH = 1024
"chatglm2-6b": {
"local_model_path": "THUDM/chatglm2-6b",
"api_base_url": "http://localhost:8888/v1", # URL需要与运行fastchat服务端的server_config.FSCHAT_OPENAI_API一致
"api_key": "EMPTY"
},
# 如果需要在 EMBEDDING_MODEL 中增加自定义的关键字时配置
EMBEDDING_KEYWORD_FILE = "keywords.txt"
EMBEDDING_MODEL_OUTPUT_PATH = "output"
"chatglm2-6b-32k": {
"local_model_path": "THUDM/chatglm2-6b-32k", # "THUDM/chatglm2-6b-32k",
"api_base_url": "http://localhost:8888/v1", # "URL需要与运行fastchat服务端的server_config.FSCHAT_OPENAI_API一致
"api_key": "EMPTY"
},
# 要运行的 LLM 名称,可以包括本地模型和在线模型。列表中本地模型将在启动项目时全部加载。
# 列表中第一个模型将作为 API 和 WEBUI 的默认模型。
# 在这里我们使用目前主流的两个离线模型其中chatglm3-6b 为默认加载模型。
# 如果你的显存不足,可使用 Qwen-1_8B-Chat, 该模型 FP16 仅需 3.8G显存。
# 调用chatgpt时如果报出 urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.openai.com', port=443):
# Max retries exceeded with url: /v1/chat/completions
# 则需要将urllib3版本修改为1.25.11
# 如果依然报urllib3.exceptions.MaxRetryError: HTTPSConnectionPool则将https改为http
# 参考https://zhuanlan.zhihu.com/p/350015032
LLM_MODELS = ["chatglm3-6b", "zhipu-api", "openai-api"]
Agent_MODEL = None
# 如果报出raise NewConnectionError(
# urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000001FE4BDB85E0>:
# Failed to establish a new connection: [WinError 10060]
# 则是因为内地和香港的IP都被OPENAI封了需要切换为日本、新加坡等地
# 如果出现WARNING: Retrying langchain.chat_models.openai.acompletion_with_retry.<locals>._completion_with_retry in
# 4.0 seconds as it raised APIConnectionError: Error communicating with OpenAI.
# 需要添加代理访问(正常开的代理软件可能会拦截不上)需要设置配置openai_proxy 或者 使用环境遍历OPENAI_PROXY 进行设置
# 比如: "openai_proxy": 'http://127.0.0.1:4780'
"gpt-3.5-turbo": {
"api_base_url": "https://api.openai.com/v1",
"api_key": os.environ.get("OPENAI_API_KEY"),
"openai_proxy": os.environ.get("OPENAI_PROXY")
},
# 线上模型。当前支持智谱AI。
# 如果没有设置有效的local_model_path则认为是在线模型API。
# 请在server_config中为每个在线API设置不同的端口
# 具体注册及api key获取请前往 http://open.bigmodel.cn
"chatglm-api": {
"api_base_url": "http://127.0.0.1:8888/v1",
"api_key": os.environ.get("ZHIPUAI_API_KEY"),
"provider": "ChatGLMWorker",
"version": "chatglm_pro", # 可选包括 "chatglm_lite", "chatglm_std", "chatglm_pro"
},
}
# LLM 名称
LLM_MODEL = "chatglm2-6b"
# 历史对话轮数
HISTORY_LEN = 3
# LLM 运行设备。设为"auto"会自动检测,也可手动设定为"cuda","mps","cpu"其中之一。
# LLM 模型运行设备。设为"auto"会自动检测(会有警告),也可手动设定为 "cuda","mps","cpu","xpu" 其中之一。
LLM_DEVICE = "auto"
# 日志存储路径
LOG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs")
if not os.path.exists(LOG_PATH):
os.mkdir(LOG_PATH)
HISTORY_LEN = 3
# 知识库默认存储路径
KB_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "knowledge_base")
MAX_TOKENS = 2048
# 数据库默认存储路径。
# 如果使用sqlite可以直接修改DB_ROOT_PATH如果使用其它数据库请直接修改SQLALCHEMY_DATABASE_URI。
DB_ROOT_PATH = os.path.join(KB_ROOT_PATH, "info.db")
SQLALCHEMY_DATABASE_URI = f"sqlite:///{DB_ROOT_PATH}"
TEMPERATURE = 0.7
# 可选向量库类型及对应配置
kbs_config = {
"faiss": {
ONLINE_LLM_MODEL = {
"openai-api": {
"model_name": "gpt-4",
"api_base_url": "https://api.openai.com/v1",
"api_key": "",
"openai_proxy": "",
},
"milvus": {
"host": "127.0.0.1",
"port": "19530",
"user": "",
"password": "",
"secure": False,
# 智谱AI API,具体注册及api key获取请前往 http://open.bigmodel.cn
"zhipu-api": {
"api_key": "",
"version": "glm-4",
"provider": "ChatGLMWorker",
},
"pg": {
"connection_uri": "postgresql://postgres:postgres@127.0.0.1:5432/langchain_chatchat",
# 具体注册及api key获取请前往 https://api.minimax.chat/
"minimax-api": {
"group_id": "",
"api_key": "",
"is_pro": False,
"provider": "MiniMaxWorker",
},
# 具体注册及api key获取请前往 https://xinghuo.xfyun.cn/
"xinghuo-api": {
"APPID": "",
"APISecret": "",
"api_key": "",
"version": "v3.5", # 你使用的讯飞星火大模型版本,可选包括 "v3.5","v3.0", "v2.0", "v1.5"
"provider": "XingHuoWorker",
},
# 百度千帆 API申请方式请参考 https://cloud.baidu.com/doc/WENXINWORKSHOP/s/4lilb2lpf
"qianfan-api": {
"version": "ERNIE-Bot", # 注意大小写。当前支持 "ERNIE-Bot" 或 "ERNIE-Bot-turbo" 更多的见官方文档。
"version_url": "", # 也可以不填写version直接填写在千帆申请模型发布的API地址
"api_key": "",
"secret_key": "",
"provider": "QianFanWorker",
},
# 火山方舟 API文档参考 https://www.volcengine.com/docs/82379
"fangzhou-api": {
"version": "", # 对应火山方舟的 endpoint_id
"version_url": "",
"api_key": "",
"secret_key": "",
"provider": "FangZhouWorker",
},
# 阿里云通义千问 API文档参考 https://help.aliyun.com/zh/dashscope/developer-reference/api-details
"qwen-api": {
"version": "qwen-max",
"api_key": "",
"provider": "QwenWorker",
"embed_model": "text-embedding-v1" # embedding 模型名称
},
# 百川 API申请方式请参考 https://www.baichuan-ai.com/home#api-enter
"baichuan-api": {
"version": "Baichuan2-53B",
"api_key": "",
"secret_key": "",
"provider": "BaiChuanWorker",
},
# Azure API
"azure-api": {
"deployment_name": "", # 部署容器的名字
"resource_name": "", # https://{resource_name}.openai.azure.com/openai/ 填写resource_name的部分其他部分不要填写
"api_version": "", # API的版本不是模型版本
"api_key": "",
"provider": "AzureWorker",
},
# 昆仑万维天工 API https://model-platform.tiangong.cn/
"tiangong-api": {
"version": "SkyChat-MegaVerse",
"api_key": "",
"secret_key": "",
"provider": "TianGongWorker",
},
# Gemini API https://makersuite.google.com/app/apikey
"gemini-api": {
"api_key": "",
"provider": "GeminiWorker",
},
# Claude API : https://www.anthropic.com/api
# Available models:
# Claude 3 Opus: claude-3-opus-20240229
# Claude 3 Sonnet claude-3-sonnet-20240229
# Claude 3 Haiku claude-3-haiku-20240307
"claude-api": {
"api_key": "",
"version": "2023-06-01",
"model_name":"claude-3-opus-20240229",
"provider": "ClaudeWorker",
}
}
# 在以下字典中修改属性值以指定本地embedding模型存储位置。支持3种设置方法
# 1、将对应的值修改为模型绝对路径
# 2、不修改此处的值以 text2vec 为例):
# 2.1 如果{MODEL_ROOT_PATH}下存在如下任一子目录:
# - text2vec
# - GanymedeNil/text2vec-large-chinese
# - text2vec-large-chinese
# 2.2 如果以上本地路径不存在则使用huggingface模型
MODEL_PATH = {
"embed_model": {
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
"ernie-base": "nghuyong/ernie-3.0-base-zh",
"text2vec-base": "shibing624/text2vec-base-chinese",
"text2vec": "GanymedeNil/text2vec-large-chinese",
"text2vec-paraphrase": "shibing624/text2vec-base-chinese-paraphrase",
"text2vec-sentence": "shibing624/text2vec-base-chinese-sentence",
"text2vec-multilingual": "shibing624/text2vec-base-multilingual",
"text2vec-bge-large-chinese": "shibing624/text2vec-bge-large-chinese",
"m3e-small": "moka-ai/m3e-small",
"m3e-base": "moka-ai/m3e-base",
"m3e-large": "moka-ai/m3e-large",
"bge-small-zh": "BAAI/bge-small-zh",
"bge-base-zh": "BAAI/bge-base-zh",
"bge-large-zh": "BAAI/bge-large-zh",
"bge-large-zh-noinstruct": "BAAI/bge-large-zh-noinstruct",
"bge-base-zh-v1.5": "BAAI/bge-base-zh-v1.5",
"bge-large-zh-v1.5": "BAAI/bge-large-zh-v1.5",
"bge-m3": "BAAI/bge-m3",
"piccolo-base-zh": "sensenova/piccolo-base-zh",
"piccolo-large-zh": "sensenova/piccolo-large-zh",
"nlp_gte_sentence-embedding_chinese-large": "damo/nlp_gte_sentence-embedding_chinese-large",
"text-embedding-ada-002": "your OPENAI_API_KEY",
},
"llm_model": {
"chatglm2-6b": "THUDM/chatglm2-6b",
"chatglm2-6b-32k": "THUDM/chatglm2-6b-32k",
"chatglm3-6b": "THUDM/chatglm3-6b",
"chatglm3-6b-32k": "THUDM/chatglm3-6b-32k",
"Orion-14B-Chat": "OrionStarAI/Orion-14B-Chat",
"Orion-14B-Chat-Plugin": "OrionStarAI/Orion-14B-Chat-Plugin",
"Orion-14B-LongChat": "OrionStarAI/Orion-14B-LongChat",
"Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
"Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
"Llama-2-70b-chat-hf": "meta-llama/Llama-2-70b-chat-hf",
"Qwen-1_8B-Chat": "Qwen/Qwen-1_8B-Chat",
"Qwen-7B-Chat": "Qwen/Qwen-7B-Chat",
"Qwen-14B-Chat": "Qwen/Qwen-14B-Chat",
"Qwen-72B-Chat": "Qwen/Qwen-72B-Chat",
# Qwen1.5 模型 VLLM可能出现问题
"Qwen1.5-0.5B-Chat": "Qwen/Qwen1.5-0.5B-Chat",
"Qwen1.5-1.8B-Chat": "Qwen/Qwen1.5-1.8B-Chat",
"Qwen1.5-4B-Chat": "Qwen/Qwen1.5-4B-Chat",
"Qwen1.5-7B-Chat": "Qwen/Qwen1.5-7B-Chat",
"Qwen1.5-14B-Chat": "Qwen/Qwen1.5-14B-Chat",
"Qwen1.5-72B-Chat": "Qwen/Qwen1.5-72B-Chat",
"baichuan-7b-chat": "baichuan-inc/Baichuan-7B-Chat",
"baichuan-13b-chat": "baichuan-inc/Baichuan-13B-Chat",
"baichuan2-7b-chat": "baichuan-inc/Baichuan2-7B-Chat",
"baichuan2-13b-chat": "baichuan-inc/Baichuan2-13B-Chat",
"internlm-7b": "internlm/internlm-7b",
"internlm-chat-7b": "internlm/internlm-chat-7b",
"internlm2-chat-7b": "internlm/internlm2-chat-7b",
"internlm2-chat-20b": "internlm/internlm2-chat-20b",
"BlueLM-7B-Chat": "vivo-ai/BlueLM-7B-Chat",
"BlueLM-7B-Chat-32k": "vivo-ai/BlueLM-7B-Chat-32k",
"Yi-34B-Chat": "https://huggingface.co/01-ai/Yi-34B-Chat",
"agentlm-7b": "THUDM/agentlm-7b",
"agentlm-13b": "THUDM/agentlm-13b",
"agentlm-70b": "THUDM/agentlm-70b",
"falcon-7b": "tiiuae/falcon-7b",
"falcon-40b": "tiiuae/falcon-40b",
"falcon-rw-7b": "tiiuae/falcon-rw-7b",
"aquila-7b": "BAAI/Aquila-7B",
"aquilachat-7b": "BAAI/AquilaChat-7B",
"open_llama_13b": "openlm-research/open_llama_13b",
"vicuna-13b-v1.5": "lmsys/vicuna-13b-v1.5",
"koala": "young-geng/koala",
"mpt-7b": "mosaicml/mpt-7b",
"mpt-7b-storywriter": "mosaicml/mpt-7b-storywriter",
"mpt-30b": "mosaicml/mpt-30b",
"opt-66b": "facebook/opt-66b",
"opt-iml-max-30b": "facebook/opt-iml-max-30b",
"gpt2": "gpt2",
"gpt2-xl": "gpt2-xl",
"gpt-j-6b": "EleutherAI/gpt-j-6b",
"gpt4all-j": "nomic-ai/gpt4all-j",
"gpt-neox-20b": "EleutherAI/gpt-neox-20b",
"pythia-12b": "EleutherAI/pythia-12b",
"oasst-sft-4-pythia-12b-epoch-3.5": "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
"dolly-v2-12b": "databricks/dolly-v2-12b",
"stablelm-tuned-alpha-7b": "stabilityai/stablelm-tuned-alpha-7b",
},
"reranker": {
"bge-reranker-large": "BAAI/bge-reranker-large",
"bge-reranker-base": "BAAI/bge-reranker-base",
}
}
# 默认向量库类型。可选faiss, milvus, pg.
DEFAULT_VS_TYPE = "faiss"
# 缓存向量库数量
CACHED_VS_NUM = 1
# 知识库中单段文本长度
CHUNK_SIZE = 250
# 知识库中相邻文本重合长度
OVERLAP_SIZE = 50
# 知识库匹配向量数量
VECTOR_SEARCH_TOP_K = 5
# 知识库匹配相关度阈值取值范围在0-1之间SCORE越小相关度越高取到1相当于不筛选建议设置在0.5左右
SCORE_THRESHOLD = 1
# 搜索引擎匹配结题数量
SEARCH_ENGINE_TOP_K = 5
# 通常情况下不需要更改以下内容
# nltk 模型存储路径
NLTK_DATA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "nltk_data")
# 基于本地知识问答的提示词模版使用Jinja2语法简单点就是用双大括号代替f-string的单大括号
PROMPT_TEMPLATE = """<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。 </指令>
# 使用VLLM可能导致模型推理能力下降无法完成Agent任务
VLLM_MODEL_DICT = {
"chatglm2-6b": "THUDM/chatglm2-6b",
"chatglm2-6b-32k": "THUDM/chatglm2-6b-32k",
"chatglm3-6b": "THUDM/chatglm3-6b",
"chatglm3-6b-32k": "THUDM/chatglm3-6b-32k",
<已知信息>{{ context }}</已知信息>
"Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
"Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
"Llama-2-70b-chat-hf": "meta-llama/Llama-2-70b-chat-hf",
<问题>{{ question }}</问题>"""
"Qwen-1_8B-Chat": "Qwen/Qwen-1_8B-Chat",
"Qwen-7B-Chat": "Qwen/Qwen-7B-Chat",
"Qwen-14B-Chat": "Qwen/Qwen-14B-Chat",
"Qwen-72B-Chat": "Qwen/Qwen-72B-Chat",
# API 是否开启跨域默认为False如果需要开启请设置为True
# is open cross domain
OPEN_CROSS_DOMAIN = False
"baichuan-7b-chat": "baichuan-inc/Baichuan-7B-Chat",
"baichuan-13b-chat": "baichuan-inc/Baichuan-13B-Chat",
"baichuan2-7b-chat": "baichuan-inc/Baichuan-7B-Chat",
"baichuan2-13b-chat": "baichuan-inc/Baichuan-13B-Chat",
# Bing 搜索必备变量
# 使用 Bing 搜索需要使用 Bing Subscription Key,需要在azure port中申请试用bing search
# 具体申请方式请见
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/create-bing-search-service-resource
# 使用python创建bing api 搜索实例详见:
# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/quickstarts/rest/python
BING_SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search"
# 注意不是bing Webmaster Tools的api key
"BlueLM-7B-Chat": "vivo-ai/BlueLM-7B-Chat",
"BlueLM-7B-Chat-32k": "vivo-ai/BlueLM-7B-Chat-32k",
# 此外如果是在服务器上报Failed to establish a new connection: [Errno 110] Connection timed out
# 是因为服务器加了防火墙需要联系管理员加白名单如果公司的服务器的话就别想了GG
BING_SUBSCRIPTION_KEY = ""
"internlm-7b": "internlm/internlm-7b",
"internlm-chat-7b": "internlm/internlm-chat-7b",
"internlm2-chat-7b": "internlm/Models/internlm2-chat-7b",
"internlm2-chat-20b": "internlm/Models/internlm2-chat-20b",
# 是否开启中文标题加强,以及标题增强的相关配置
# 通过增加标题判断判断哪些文本为标题并在metadata中进行标记
# 然后将文本与往上一级的标题进行拼合,实现文本信息的增强。
ZH_TITLE_ENHANCE = False
"aquila-7b": "BAAI/Aquila-7B",
"aquilachat-7b": "BAAI/AquilaChat-7B",
"falcon-7b": "tiiuae/falcon-7b",
"falcon-40b": "tiiuae/falcon-40b",
"falcon-rw-7b": "tiiuae/falcon-rw-7b",
"gpt2": "gpt2",
"gpt2-xl": "gpt2-xl",
"gpt-j-6b": "EleutherAI/gpt-j-6b",
"gpt4all-j": "nomic-ai/gpt4all-j",
"gpt-neox-20b": "EleutherAI/gpt-neox-20b",
"pythia-12b": "EleutherAI/pythia-12b",
"oasst-sft-4-pythia-12b-epoch-3.5": "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
"dolly-v2-12b": "databricks/dolly-v2-12b",
"stablelm-tuned-alpha-7b": "stabilityai/stablelm-tuned-alpha-7b",
"open_llama_13b": "openlm-research/open_llama_13b",
"vicuna-13b-v1.3": "lmsys/vicuna-13b-v1.3",
"koala": "young-geng/koala",
"mpt-7b": "mosaicml/mpt-7b",
"mpt-7b-storywriter": "mosaicml/mpt-7b-storywriter",
"mpt-30b": "mosaicml/mpt-30b",
"opt-66b": "facebook/opt-66b",
"opt-iml-max-30b": "facebook/opt-iml-max-30b",
}
SUPPORT_AGENT_MODEL = [
"openai-api", # GPT4 模型
"qwen-api", # Qwen Max模型
"zhipu-api", # 智谱AI GLM4模型
"Qwen", # 所有Qwen系列本地模型
"chatglm3-6b",
"internlm2-chat-20b",
"Orion-14B-Chat-Plugin",
]

View File

@ -0,0 +1,127 @@
# prompt模板使用Jinja2语法简单点就是用双大括号代替f-string的单大括号
# 本配置文件支持热加载修改prompt模板后无需重启服务。
# LLM对话支持的变量
# - input: 用户输入内容
# 知识库和搜索引擎对话支持的变量:
# - context: 从检索结果拼接的知识文本
# - question: 用户提出的问题
# Agent对话支持的变量
# - tools: 可用的工具列表
# - tool_names: 可用的工具名称列表
# - history: 用户和Agent的对话历史
# - input: 用户输入内容
# - agent_scratchpad: Agent的思维记录
PROMPT_TEMPLATES = {
"llm_chat": {
"default":
'{{ input }}',
"with_history":
'The following is a friendly conversation between a human and an AI. '
'The AI is talkative and provides lots of specific details from its context. '
'If the AI does not know the answer to a question, it truthfully says it does not know.\n\n'
'Current conversation:\n'
'{history}\n'
'Human: {input}\n'
'AI:',
"py":
'你是一个聪明的代码助手请你给我写出简单的py代码。 \n'
'{{ input }}',
},
"knowledge_base_chat": {
"default":
'<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,'
'不允许在答案中添加编造成分,答案请使用中文。 </指令>\n'
'<已知信息>{{ context }}</已知信息>\n'
'<问题>{{ question }}</问题>\n',
"text":
'<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,答案请使用中文。 </指令>\n'
'<已知信息>{{ context }}</已知信息>\n'
'<问题>{{ question }}</问题>\n',
"empty": # 搜不到知识库的时候使用
'请你回答我的问题:\n'
'{{ question }}\n\n',
},
"search_engine_chat": {
"default":
'<指令>这是我搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题。'
'如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。 </指令>\n'
'<已知信息>{{ context }}</已知信息>\n'
'<问题>{{ question }}</问题>\n',
"search":
'<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,答案请使用中文。 </指令>\n'
'<已知信息>{{ context }}</已知信息>\n'
'<问题>{{ question }}</问题>\n',
},
"agent_chat": {
"default":
'Answer the following questions as best you can. If it is in order, you can use some tools appropriately. '
'You have access to the following tools:\n\n'
'{tools}\n\n'
'Use the following format:\n'
'Question: the input question you must answer1\n'
'Thought: you should always think about what to do and what tools to use.\n'
'Action: the action to take, should be one of [{tool_names}]\n'
'Action Input: the input to the action\n'
'Observation: the result of the action\n'
'... (this Thought/Action/Action Input/Observation can be repeated zero or more times)\n'
'Thought: I now know the final answer\n'
'Final Answer: the final answer to the original input question\n'
'Begin!\n\n'
'history: {history}\n\n'
'Question: {input}\n\n'
'Thought: {agent_scratchpad}\n',
"ChatGLM3":
'You can answer using the tools, or answer directly using your knowledge without using the tools. '
'Respond to the human as helpfully and accurately as possible.\n'
'You have access to the following tools:\n'
'{tools}\n'
'Use a json blob to specify a tool by providing an action key (tool name) '
'and an action_input key (tool input).\n'
'Valid "action" values: "Final Answer" or [{tool_names}]'
'Provide only ONE action per $JSON_BLOB, as shown:\n\n'
'```\n'
'{{{{\n'
' "action": $TOOL_NAME,\n'
' "action_input": $INPUT\n'
'}}}}\n'
'```\n\n'
'Follow this format:\n\n'
'Question: input question to answer\n'
'Thought: consider previous and subsequent steps\n'
'Action:\n'
'```\n'
'$JSON_BLOB\n'
'```\n'
'Observation: action result\n'
'... (repeat Thought/Action/Observation N times)\n'
'Thought: I know what to respond\n'
'Action:\n'
'```\n'
'{{{{\n'
' "action": "Final Answer",\n'
' "action_input": "Final response to human"\n'
'}}}}\n'
'Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. '
'Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation:.\n'
'history: {history}\n\n'
'Question: {input}\n\n'
'Thought: {agent_scratchpad}',
}
}

View File

@ -1,5 +1,5 @@
from .model_config import LLM_MODEL, llm_model_dict, LLM_DEVICE
import httpx
import sys
from configs.model_config import LLM_DEVICE
# httpx 请求默认超时时间(秒)。如果加载模型或对话较慢,出现超时错误,可以适当加大该值。
HTTPX_DEFAULT_TIMEOUT = 300.0
@ -8,8 +8,8 @@ HTTPX_DEFAULT_TIMEOUT = 300.0
# is open cross domain
OPEN_CROSS_DOMAIN = False
# 各服务器默认绑定host
DEFAULT_BIND_HOST = "127.0.0.1"
# 各服务器默认绑定host。如改为"0.0.0.0"需要修改下方所有XX_SERVER的host
DEFAULT_BIND_HOST = "0.0.0.0" if sys.platform != "win32" else "127.0.0.1"
# webui.py server
WEBUI_SERVER = {
@ -26,25 +26,28 @@ API_SERVER = {
# fastchat openai_api server
FSCHAT_OPENAI_API = {
"host": DEFAULT_BIND_HOST,
"port": 8888, # model_config.llm_model_dict中模型配置的api_base_url需要与这里一致。
"port": 20000,
}
# fastchat model_worker server
# 这些模型必须是在model_config.llm_model_dict中正确配置的。
# 在启动startup.py时可用通过`--model-worker --model-name xxxx`指定模型不指定则为LLM_MODEL
# 这些模型必须是在model_config.MODEL_PATH或ONLINE_MODEL中正确配置的。
# 在启动startup.py时可用通过`--model-name xxxx yyyy`指定模型不指定则为LLM_MODELS
FSCHAT_MODEL_WORKERS = {
# 所有模型共用的默认配置,可在模型专项配置或llm_model_dict中进行覆盖。
# 所有模型共用的默认配置,可在模型专项配置中进行覆盖。
"default": {
"host": DEFAULT_BIND_HOST,
"port": 20002,
"device": LLM_DEVICE,
# False,'vllm',使用的推理加速框架,使用vllm如果出现HuggingFace通信问题参见doc/FAQ
# vllm对一些模型支持还不成熟暂时默认关闭
"infer_turbo": False,
# 多卡加载需要配置的参数
# "gpus": None, # 使用的GPU以str的格式指定如"0,1"
# model_worker多卡加载需要配置的参数
# "gpus": None, # 使用的GPU以str的格式指定如"0,1"如失效请使用CUDA_VISIBLE_DEVICES="0,1"等形式指定
# "num_gpus": 1, # 使用GPU的数量
# "max_gpu_memory": "20GiB", # 每个GPU占用的最大显存
# 以下为非常用参数,可根据需要配置
# 以下为model_worker非常用参数,可根据需要配置
# "load_8bit": False, # 开启8bit量化
# "cpu_offloading": None,
# "gptq_ckpt": None,
@ -54,26 +57,81 @@ FSCHAT_MODEL_WORKERS = {
# "awq_ckpt": None,
# "awq_wbits": 16,
# "awq_groupsize": -1,
# "model_names": [LLM_MODEL],
# "model_names": LLM_MODELS,
# "conv_template": None,
# "limit_worker_concurrency": 5,
# "stream_interval": 2,
# "no_register": False,
# "embed_in_truncate": False,
# 以下为vllm_worker配置参数,注意使用vllm必须有gpu仅在Linux测试通过
# tokenizer = model_path # 如果tokenizer与model_path不一致在此处添加
# 'tokenizer_mode':'auto',
# 'trust_remote_code':True,
# 'download_dir':None,
# 'load_format':'auto',
# 'dtype':'auto',
# 'seed':0,
# 'worker_use_ray':False,
# 'pipeline_parallel_size':1,
# 'tensor_parallel_size':1,
# 'block_size':16,
# 'swap_space':4 , # GiB
# 'gpu_memory_utilization':0.90,
# 'max_num_batched_tokens':2560,
# 'max_num_seqs':256,
# 'disable_log_stats':False,
# 'conv_template':None,
# 'limit_worker_concurrency':5,
# 'no_register':False,
# 'num_gpus': 1
# 'engine_use_ray': False,
# 'disable_log_requests': False
},
"baichuan-7b": { # 使用default中的IP和端口
"device": "cpu",
"chatglm3-6b": {
"device": "cuda",
},
"chatglm-api": { # 请为每个在线API设置不同的端口
"port": 20003,
"Qwen1.5-0.5B-Chat": {
"device": "cuda",
},
# 以下配置可以不用修改在model_config中设置启动的模型
"zhipu-api": {
"port": 21001,
},
"minimax-api": {
"port": 21002,
},
"xinghuo-api": {
"port": 21003,
},
"qianfan-api": {
"port": 21004,
},
"fangzhou-api": {
"port": 21005,
},
"qwen-api": {
"port": 21006,
},
"baichuan-api": {
"port": 21007,
},
"azure-api": {
"port": 21008,
},
"tiangong-api": {
"port": 21009,
},
"gemini-api": {
"port": 21010,
},
"claude-api": {
"port": 21011,
},
}
# fastchat multi model worker server
FSCHAT_MULTI_MODEL_WORKERS = {
# TODO:
}
# fastchat controller server
FSCHAT_CONTROLLER = {
"host": DEFAULT_BIND_HOST,
"port": 20001,

12
copy_config_example.py Normal file
View File

@ -0,0 +1,12 @@
# 用于批量将configs下的.example文件复制并命名为.py文件
import os
import shutil
if __name__ == "__main__":
files = os.listdir("configs")
src_files = [os.path.join("configs", file) for file in files if ".example" in file]
for src_file in src_files:
tar_file = src_file.replace(".example", "")
shutil.copy(src_file, tar_file)

View File

@ -1,32 +0,0 @@
## 变更日志
**[2023/04/15]**
1. 重构项目结构,在根目录下保留命令行 Demo [cli_demo.py](../cli_demo.py) 和 Web UI Demo [webui.py](../webui.py)
2. 对 Web UI 进行改进,修改为运行 Web UI 后首先按照 [configs/model_config.py](../configs/model_config.py) 默认选项加载模型,并增加报错提示信息等;
3. 对常见问题进行补充说明。
**[2023/04/12]**
1. 替换 Web UI 中的样例文件,避免出现 Ubuntu 中出现因文件编码无法读取的问题;
2. 替换`knowledge_based_chatglm.py`中的 prompt 模版,避免出现因 prompt 模版包含中英双语导致 chatglm 返回内容错乱的问题。
**[2023/04/11]**
1. 加入 Web UI V0.1 版本(感谢 [@liangtongt](https://github.com/liangtongt)
2. `README.md`中增加常见问题(感谢 [@calcitem](https://github.com/calcitem) 和 [@bolongliu](https://github.com/bolongliu)
3. 增加 LLM 和 Embedding 模型运行设备是否可用`cuda``mps``cpu`的自动判断。
4. 在`knowledge_based_chatglm.py`中增加对`filepath`的判断,在之前支持单个文件导入的基础上,现支持单个文件夹路径作为输入,输入后将会遍历文件夹中各个文件,并在命令行中显示每个文件是否成功加载。
**[2023/04/09]**
1. 使用`langchain`中的`RetrievalQA`替代之前选用的`ChatVectorDBChain`,替换后可以有效减少提问 2-3 次后因显存不足而停止运行的问题;
2. 在`knowledge_based_chatglm.py`中增加`EMBEDDING_MODEL``VECTOR_SEARCH_TOP_K``LLM_MODEL``LLM_HISTORY_LEN``REPLY_WITH_SOURCE`参数值设置;
3. 增加 GPU 显存需求更小的`chatglm-6b-int4``chatglm-6b-int4-qe`作为 LLM 模型备选项;
4. 更正`README.md`中的代码错误(感谢 [@calcitem](https://github.com/calcitem))。
**[2023/04/07]**
1. 解决加载 ChatGLM 模型时发生显存占用为双倍的问题 (感谢 [@suc16](https://github.com/suc16) 和 [@myml](https://github.com/myml))
2. 新增清理显存机制;
3. 新增`nghuyong/ernie-3.0-nano-zh``nghuyong/ernie-3.0-base-zh`作为 Embedding 模型备选项,相比`GanymedeNil/text2vec-large-chinese`占用显存资源更少 (感谢 [@lastrei](https://github.com/lastrei))。

29
docs/ES部署指南.md Normal file
View File

@ -0,0 +1,29 @@
# 实现基于ES的数据插入、检索、删除、更新
```shell
author: 唐国梁Tommy
e-mail: flytang186@qq.com
如果遇到任何问题,可以与我联系,我这边部署后服务是没有问题的。
```
## 第1步ES docker部署
```shell
docker network create elastic
docker run -id --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "xpack.security.http.ssl.enabled=false" -t docker.elastic.co/elasticsearch/elasticsearch:8.8.2
```
### 第2步Kibana docker部署
**注意Kibana版本与ES保持一致**
```shell
docker pull docker.elastic.co/kibana/kibana:{version}
docker run --name kibana --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:{version}
```
### 第3步核心代码
```shell
1. 核心代码路径
server/knowledge_base/kb_service/es_kb_service.py
2. 需要在 configs/model_config.py 中 配置 ES参数IP PORT
```

View File

@ -1,185 +0,0 @@
### 常见问题
Q1: 本项目支持哪些文件格式?
A1: 目前已测试支持 txt、docx、md、pdf 格式文件,更多文件格式请参考 [langchain 文档](https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/unstructured_file.html)。目前已知文档中若含有特殊字符,可能存在文件无法加载的问题。
---
Q2: 使用过程中 Python 包 `nltk`发生了 `Resource punkt not found.`报错,该如何解决?
A2: 方法一https://github.com/nltk/nltk_data/raw/gh-pages/packages/tokenizers/punkt.zip 中的 `packages/tokenizers` 解压,放到 `nltk_data/tokenizers` 存储路径下。
`nltk_data` 存储路径可以通过 `nltk.data.path` 查询。
方法二执行python代码
```
import nltk
nltk.download()
```
---
Q3: 使用过程中 Python 包 `nltk`发生了 `Resource averaged_perceptron_tagger not found.`报错,该如何解决?
A3: 方法一:将 https://github.com/nltk/nltk_data/blob/gh-pages/packages/taggers/averaged_perceptron_tagger.zip 下载,解压放到 `nltk_data/taggers` 存储路径下。
`nltk_data` 存储路径可以通过 `nltk.data.path` 查询。
方法二执行python代码
```
import nltk
nltk.download()
```
---
Q4: 本项目可否在 colab 中运行?
A4: 可以尝试使用 chatglm-6b-int4 模型在 colab 中运行,需要注意的是,如需在 colab 中运行 Web UI需将 `webui.py``demo.queue(concurrency_count=3).launch( server_name='0.0.0.0', share=False, inbrowser=False)`中参数 `share`设置为 `True`
---
Q5: 在 Anaconda 中使用 pip 安装包无效如何解决?
A5: 此问题是系统环境问题,详细见 [在Anaconda中使用pip安装包无效问题](在Anaconda中使用pip安装包无效问题.md)
---
Q6: 本项目中所需模型如何下载至本地?
A6: 本项目中使用的模型均为 `huggingface.com`中可下载的开源模型,以默认选择的 `chatglm-6b``text2vec-large-chinese`模型为例,下载模型可执行如下代码:
```shell
# 安装 git lfs
$ git lfs install
# 下载 LLM 模型
$ git clone https://huggingface.co/THUDM/chatglm-6b /your_path/chatglm-6b
# 下载 Embedding 模型
$ git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese /your_path/text2vec
# 模型需要更新时,可打开模型所在文件夹后拉取最新模型文件/代码
$ git pull
```
---
Q7: `huggingface.com`中模型下载速度较慢怎么办?
A7: 可使用本项目用到的模型权重文件百度网盘地址:
- ernie-3.0-base-zh.zip 链接: https://pan.baidu.com/s/1CIvKnD3qzE-orFouA8qvNQ?pwd=4wih
- ernie-3.0-nano-zh.zip 链接: https://pan.baidu.com/s/1Fh8fgzVdavf5P1omAJJ-Zw?pwd=q6s5
- text2vec-large-chinese.zip 链接: https://pan.baidu.com/s/1sMyPzBIXdEzHygftEoyBuA?pwd=4xs7
- chatglm-6b-int4-qe.zip 链接: https://pan.baidu.com/s/1DDKMOMHtNZccOOBGWIOYww?pwd=22ji
- chatglm-6b-int4.zip 链接: https://pan.baidu.com/s/1pvZ6pMzovjhkA6uPcRLuJA?pwd=3gjd
- chatglm-6b.zip 链接: https://pan.baidu.com/s/1B-MpsVVs1GHhteVBetaquw?pwd=djay
---
Q8: 下载完模型后,如何修改代码以执行本地模型?
A8: 模型下载完成后,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对 `embedding_model_dict``llm_model_dict`参数进行修改,如把 `llm_model_dict`
```python
embedding_model_dict = {
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
"ernie-base": "nghuyong/ernie-3.0-base-zh",
"text2vec": "GanymedeNil/text2vec-large-chinese"
}
```
修改为
```python
embedding_model_dict = {
"ernie-tiny": "nghuyong/ernie-3.0-nano-zh",
"ernie-base": "nghuyong/ernie-3.0-base-zh",
"text2vec": "/Users/liuqian/Downloads/ChatGLM-6B/text2vec-large-chinese"
}
```
---
Q9: 执行 `python cli_demo.py`过程中,显卡内存爆了,提示 "OutOfMemoryError: CUDA out of memory"
A9: 将 `VECTOR_SEARCH_TOP_K``LLM_HISTORY_LEN` 的值调低,比如 `VECTOR_SEARCH_TOP_K = 5``LLM_HISTORY_LEN = 2`,这样由 `query``context` 拼接得到的 `prompt` 会变短,会减少内存的占用。或者打开量化,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对`LOAD_IN_8BIT`参数进行修改
---
Q10: 执行 `pip install -r requirements.txt` 过程中遇到 python 包,如 langchain 找不到对应版本的问题
A10: 更换 pypi 源后重新安装,如阿里源、清华源等,网络条件允许时建议直接使用 pypi.org 源,具体操作命令如下:
```shell
# 使用 pypi 源
$ pip install -r requirements.txt -i https://pypi.python.org/simple
```
```shell
# 使用阿里源
$ pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/
```
```shell
# 使用清华源
$ pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
```
---
Q11: 启动 api.py 时 upload_file 接口抛出 `partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)`
A11: 这是由于 charset_normalizer 模块版本过高导致的,需要降低低 charset_normalizer 的版本,测试在 charset_normalizer==2.1.0 上可用。
---
Q12: 调用api中的 `bing_search_chat` 接口时,报出 `Failed to establish a new connection: [Errno 110] Connection timed out`
A12: 这是因为服务器加了防火墙需要联系管理员加白名单如果公司的服务器的话就别想了GG--!
---
Q13: 加载 chatglm-6b-int8 或 chatglm-6b-int4 抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`
A13: 疑为 chatglm 的 quantization 的问题或 torch 版本差异问题,针对已经变为 Parameter 的 torch.zeros 矩阵也执行 Parameter 操作,从而抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`。解决办法是在 chatglm 项目的原始文件中的 quantization.py 文件 374 行改为:
```
try:
self.weight =Parameter(self.weight.to(kwargs["device"]), requires_grad=False)
except Exception as e:
pass
```
如果上述方式不起作用,则在.cache/hugggingface/modules/目录下针对chatglm项目的原始文件中的quantization.py文件执行上述操作若软链接不止一个按照错误提示选择正确的路径。
虽然模型可以顺利加载但在cpu上仍存在推理失败的可能即针对每个问题模型一直输出gugugugu。
因此最好不要试图用cpu加载量化模型原因可能是目前python主流量化包的量化操作是在gpu上执行的,会天然地存在gap。
---
Q14: 修改配置中路径后,加载 text2vec-large-chinese 依然提示 `WARNING: No sentence-transformers model found with name text2vec-large-chinese. Creating a new one with MEAN pooling.`
A14: 尝试更换 embedding如 text2vec-base-chinese请在 [configs/model_config.py](../configs/model_config.py) 文件中,修改 `text2vec-base`参数为本地路径,绝对路径或者相对路径均可
---
Q15: 使用pg向量库建表报错
A15: 需要手动安装对应的vector扩展(连接pg执行 CREATE EXTENSION IF NOT EXISTS vector)
---
Q16: pymilvus 连接超时
A16.pymilvus版本需要匹配和milvus对应否则会超时参考pymilvus==2.1.3

View File

@ -1,63 +0,0 @@
# 安装
## 环境检查
```shell
# 首先,确信你的机器安装了 Python 3.8 - 3.10 版本
$ python --version
Python 3.8.13
# 如果低于这个版本可使用conda安装环境
$ conda create -p /your_path/env_name python=3.8
# 激活环境
$ source activate /your_path/env_name
# 或conda安装不指定路径, 注意以下,都将/your_path/env_name替换为env_name
$ conda create -n env_name python=3.8
$ conda activate env_name # Activate the environment
# 更新py库
$ pip3 install --upgrade pip
# 关闭环境
$ source deactivate /your_path/env_name
# 删除环境
$ conda env remove -p /your_path/env_name
```
## 项目依赖
```shell
# 拉取仓库
$ git clone https://github.com/chatchat-space/Langchain-Chatchat.git
# 进入目录
$ cd Langchain-Chatchat
# 安装全部依赖
$ pip install -r requirements.txt
# 默认依赖包括基本运行环境FAISS向量库。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。
```
此外,为方便用户 API 与 webui 分离运行,可单独根据运行需求安装依赖包。
- 如果只需运行 API可执行
```shell
$ pip install -r requirements_api.txt
# 默认依赖包括基本运行环境FAISS向量库。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。
```
- 如果只需运行 WebUI可执行
```shell
$ pip install -r requirements_webui.txt
```
注:使用 `langchain.document_loaders.UnstructuredFileLoader` 进行 `.docx` 等格式非结构化文件接入时,可能需要依据文档进行其他依赖包的安装,请参考 [langchain 文档](https://python.langchain.com/en/latest/modules/indexes/document_loaders/examples/unstructured_file.html)。

View File

@ -1,114 +0,0 @@
## Issue with Installing Packages Using pip in Anaconda
## Problem
Recently, when running open-source code, I encountered an issue: after creating a virtual environment with conda and switching to the new environment, using pip to install packages would be "ineffective." Here, "ineffective" means that the packages installed with pip are not in this new environment.
------
## Analysis
1. First, create a test environment called test: `conda create -n test`
2. Activate the test environment: `conda activate test`
3. Use pip to install numpy: `pip install numpy`. You'll find that numpy already exists in the default environment.
```powershell
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (1.20.3)
```
4. Check the information of pip: `pip show pip`
```powershell
Name: pip
Version: 21.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\programdata\anaconda3\lib\site-packages
Requires:
Required-by:
```
5. We can see that the current pip is in the default conda environment. This explains why the package is not in the new virtual environment when we directly use pip to install packages - because the pip being used belongs to the default environment, the installed package either already exists or is installed directly into the default environment.
------
## Solution
1. We can directly use the conda command to install new packages, but sometimes conda may not have certain packages/libraries, so we still need to use pip to install.
2. We can first use the conda command to install the pip package for the current virtual environment, and then use pip to install new packages.
```powershell
# Use conda to install the pip package
(test) PS C:\Users\Administrator> conda install pip
Collecting package metadata (current_repodata.json): done
Solving environment: done
....
done
# Display the information of the current pip, and find that pip is in the test environment
(test) PS C:\Users\Administrator> pip show pip
Name: pip
Version: 21.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\programdata\anaconda3\envs\test\lib\site-packages
Requires:
Required-by:
# Now use pip to install the numpy package, and it is installed successfully
(test) PS C:\Users\Administrator> pip install numpy
Looking in indexes:
https://pypi.tuna.tsinghua.edu.cn/simple
Collecting numpy
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4b/23/140ec5a509d992fe39db17200e96c00fd29603c1531ce633ef93dbad5e9e/numpy-1.22.2-cp39-cp39-win_amd64.whl (14.7 MB)
Installing collected packages: numpy
Successfully installed numpy-1.22.2
# Use pip list to view the currently installed packages, no problem
(test) PS C:\Users\Administrator> pip list
Package Version
------------ ---------
certifi 2021.10.8
numpy 1.22.2
pip 21.2.4
setuptools 58.0.4
wheel 0.37.1
wincertstore 0.2
```
## Supplement
1. The reason I didn't notice this problem before might be because the packages installed in the virtual environment were of a specific version, which overwrote the packages in the default environment. The main issue was actually a lack of careful observation:), otherwise, I could have noticed `Successfully uninstalled numpy-xxx` **default version** and `Successfully installed numpy-1.20.3` **specified version**.
2. During testing, I found that if the Python version is specified when creating a new package, there shouldn't be this issue. I guess this is because pip will be installed in the virtual environment, while in our case, including pip, no packages were installed, so the default environment's pip was used.
3. There's a question: I should have specified the Python version when creating a new virtual environment before, but I still used the default environment's pip package. However, I just couldn't reproduce the issue successfully on two different machines, which led to the second point mentioned above.
4. After encountering the problem mentioned in point 3, I solved it by using `python -m pip install package-name`, adding `python -m` before pip. As for why, you can refer to the answer on [StackOverflow](https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment):
>1. If you have a non-conda pip as your default pip but conda python as your default python (as below):
>
>```shell
>>which -a pip
>/home/<user>/.local/bin/pip
>/home/<user>/.conda/envs/newenv/bin/pip
>/usr/bin/pip
>
>>which -a python
>/home/<user>/.conda/envs/newenv/bin/python
>/usr/bin/python
>```
>
>2. Then, instead of calling `pip install <package>` directly, you can use the module flag -m in python so that it installs with the anaconda python
>
>```shell
>python -m pip install <package>
>```
>
>3. This will install the package to the anaconda library directory rather than the library directory associated with the (non-anaconda) pip
>4. The reason for doing this is as follows: the pip command references a specific pip file/shortcut (which -a pip will tell you which one). Similarly, the python command references a specific python file (which -a python will tell you which one). For one reason or another, these two commands can become out of sync, so your "default" pip is in a different folder than your default python and therefore is associated with different versions of python.
>5. In contrast, the python -m pip construct does not use the shortcut that the pip command points to. Instead, it asks python to find its pip version and use that version to install a package.

View File

@ -1,49 +0,0 @@
version: '3.5'
services:
etcd:
container_name: milvus-etcd
image: quay.io/coreos/etcd:v3.5.0
environment:
- ETCD_AUTO_COMPACTION_MODE=revision
- ETCD_AUTO_COMPACTION_RETENTION=1000
- ETCD_QUOTA_BACKEND_BYTES=4294967296
- ETCD_SNAPSHOT_COUNT=50000
volumes:
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
minio:
container_name: milvus-minio
image: minio/minio:RELEASE.2022-03-17T06-34-49Z
environment:
MINIO_ACCESS_KEY: minioadmin
MINIO_SECRET_KEY: minioadmin
volumes:
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
command: minio server /minio_data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
standalone:
container_name: milvus-standalone
image: milvusdb/milvus:v2.1.3
command: ["milvus", "run", "standalone"]
environment:
ETCD_ENDPOINTS: etcd:2379
MINIO_ADDRESS: minio:9000
volumes:
- ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
ports:
- "19530:19530"
- "9091:9091"
depends_on:
- "etcd"
- "minio"
networks:
default:
name: milvus

View File

@ -1,13 +0,0 @@
version: "3.8"
services:
postgresql:
image: ankane/pgvector:v0.4.1
container_name: langchain_chatchat-pg-db
environment:
POSTGRES_DB: langchain_chatchat
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
volumes:
- ./data:/var/lib/postgresql/data

View File

@ -1,8 +0,0 @@
向量库环境 docker-compose.yml 文件在 docs/docker/vector_db 中
以 milvus 为例
```shell
cd docs/docker/vector_db/milvus
docker-compose up -d
```

View File

@ -1,37 +0,0 @@
# 启动API服务
## 通过py文件启动
可以通过直接执行`api.py`文件启动API服务默认以ip:0.0.0.0和port:7861启动http和ws服务。
```shell
python api.py
```
同时启动时支持StartOption所列的模型加载参数同时还支持IP和端口设置。
```shell
python api.py --model-name chatglm-6b-int8 --port 7862
```
## 通过cli.bat/cli.sh启动
也可以通过命令行控制文件继续启动。
```shell
cli.sh api --help
```
其他可设置参数和上述py文件启动方式相同。
# 以https、wss启动API服务
## 本地创建ssl相关证书文件
如果没有正式签发的CA证书可以[安装mkcert](https://github.com/FiloSottile/mkcert#installation)工具, 然后用如下指令生成本地CA证书
```shell
mkcert -install
mkcert api.example.com 47.123.123.123 localhost 127.0.0.1 ::1
```
默认回车保存在当前目录下会有以生成指令第一个域名命名为前缀命名的两个pem文件。
附带两个文件参数启动即可。
````shell
python api --port 7862 --ssl_keyfile api.example.com+4-key.pem --ssl_certfile api.example.com+4.pem
./cli.sh api --port 7862 --ssl_keyfile api.example.com+4-key.pem --ssl_certfile api.example.com+4.pem
````
此外可以通过前置Nginx转发实现类似效果可另行查阅相关资料。

View File

@ -1,125 +0,0 @@
## 在 Anaconda 中使用 pip 安装包无效问题
## 问题
最近在跑开源代码的时候遇到的问题:使用 conda 创建虚拟环境并切换到新的虚拟环境后,再使用 pip 来安装包会“无效”。这里的“无效”指的是使用 pip 安装的包不在这个新的环境中。
------
## 分析
1、首先创建一个测试环境 test`conda create -n test`
2、激活该测试环境`conda activate test`
3、使用 pip 安装 numpy`pip install numpy`,会发现 numpy 已经存在默认的环境中
```powershell
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (1.20.3)
```
4、这时候看一下 pip 的信息,`pip show pip`
```powershell
Name: pip
Version: 21.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\programdata\anaconda3\lib\site-packages
Requires:
Required-by:
```
5、可以发现当前 pip 是在默认的 conda 环境中。这也就解释了当我们直接使用 pip 安装包时为什么包不在这个新的虚拟环境中,因为使用的 pip 属于默认环境,安装的包要么已经存在,要么直接装到默认环境中去了。
------
## 解决
1、我们可以直接使用 conda 命令安装新的包,但有些时候 conda 可能没有某些包/库,所以还是得用 pip 安装
2、我们可以先使用 conda 命令为当前虚拟环境安装 pip 包,再使用 pip 安装新的包
```powershell
# 使用 conda 安装 pip 包
(test) PS C:\Users\Administrator> conda install pip
Collecting package metadata (current_repodata.json): done
Solving environment: done
....
done
# 显示当前 pip 的信息,发现 pip 在测试环境 test 中
(test) PS C:\Users\Administrator> pip show pip
Name: pip
Version: 21.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: c:\programdata\anaconda3\envs\test\lib\site-packages
Requires:
Required-by:
# 再使用 pip 安装 numpy 包,成功安装
(test) PS C:\Users\Administrator> pip install numpy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting numpy
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/4b/23/140ec5a509d992fe39db17200e96c00fd29603c1531ce633ef93dbad5e9e/numpy-1.22.2-cp39-cp39-win_amd64.whl (14.7 MB)
Installing collected packages: numpy
Successfully installed numpy-1.22.2
# 使用 pip list 查看当前安装的包,没有问题
(test) PS C:\Users\Administrator> pip list
Package Version
------------ ---------
certifi 2021.10.8
numpy 1.22.2
pip 21.2.4
setuptools 58.0.4
wheel 0.37.1
wincertstore 0.2
```
------
## 补充
1、之前没有发现这个问题可能时因为在虚拟环境中安装的包是指定版本的覆盖了默认环境中的包。其实主要还是观察不仔细不然可以发现 `Successfully uninstalled numpy-xxx`【默认版本】 以及 `Successfully installed numpy-1.20.3`【指定版本】
2、测试时发现如果在新建包的时候指定了 python 版本的话应该是没有这个问题的,猜测时因为会在虚拟环境中安装好 pip ,而我们这里包括 pip 在内啥包也没有装,所以使用的是默认环境的 pip
3、有个问题之前我在创建新的虚拟环境时应该指定了 python 版本,但还是使用的默认环境的 pip 包,但是刚在在两台机器上都没有复现成功,于是有了上面的第 2 点
4、出现了第 3 点的问题后,我当时是使用 `python -m pip install package-name` 解决的,在 pip 前面加上了 python -m。至于为什么可以参考 [StackOverflow](https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment) 上的回答:
> 1、如果你有一个非 conda 的 pip 作为你的默认 pip但是 conda 的 python 是你的默认 python如下
>
> ```shell
> >which -a pip
> /home/<user>/.local/bin/pip
> /home/<user>/.conda/envs/newenv/bin/pip
> /usr/bin/pip
>
> >which -a python
> /home/<user>/.conda/envs/newenv/bin/python
> /usr/bin/python
> ```
>
> 2、然后而不是直接调用 `pip install <package>`,你可以在 python 中使用模块标志 -m以便它使用 anaconda python 进行安装
>
> ```shell
>python -m pip install <package>
> ```
>
> 3、这将把包安装到 anaconda 库目录而不是与非anaconda pip 关联的库目录
>
> 4、这样做的原因如下命令 pip 引用了一个特定的 pip 文件 / 快捷方式which -a pip 会告诉你是哪一个)。类似地,命令 python 引用一个特定的 python 文件which -a python 会告诉你是哪个)。由于这样或那样的原因,这两个命令可能变得不同步,因此你的“默认” pip 与你的默认 python 位于不同的文件夹中,因此与不同版本的 python 相关联。
>
> 5、与此相反python -m pip 构造不使用 pip 命令指向的快捷方式。相反,它要求 python 找到它的pip 版本,并使用该版本安装一个包。
-

View File

@ -0,0 +1,84 @@
## 指定制定列的csv文件加载器
from langchain.document_loaders import CSVLoader
import csv
from io import TextIOWrapper
from typing import Dict, List, Optional
from langchain.docstore.document import Document
from langchain.document_loaders.helpers import detect_file_encodings
class FilteredCSVLoader(CSVLoader):
def __init__(
self,
file_path: str,
columns_to_read: List[str],
source_column: Optional[str] = None,
metadata_columns: List[str] = [],
csv_args: Optional[Dict] = None,
encoding: Optional[str] = None,
autodetect_encoding: bool = False,
):
super().__init__(
file_path=file_path,
source_column=source_column,
metadata_columns=metadata_columns,
csv_args=csv_args,
encoding=encoding,
autodetect_encoding=autodetect_encoding,
)
self.columns_to_read = columns_to_read
def load(self) -> List[Document]:
"""Load data into document objects."""
docs = []
try:
with open(self.file_path, newline="", encoding=self.encoding) as csvfile:
docs = self.__read_file(csvfile)
except UnicodeDecodeError as e:
if self.autodetect_encoding:
detected_encodings = detect_file_encodings(self.file_path)
for encoding in detected_encodings:
try:
with open(
self.file_path, newline="", encoding=encoding.encoding
) as csvfile:
docs = self.__read_file(csvfile)
break
except UnicodeDecodeError:
continue
else:
raise RuntimeError(f"Error loading {self.file_path}") from e
except Exception as e:
raise RuntimeError(f"Error loading {self.file_path}") from e
return docs
def __read_file(self, csvfile: TextIOWrapper) -> List[Document]:
docs = []
csv_reader = csv.DictReader(csvfile, **self.csv_args) # type: ignore
for i, row in enumerate(csv_reader):
content = []
for col in self.columns_to_read:
if col in row:
content.append(f'{col}:{str(row[col])}')
else:
raise ValueError(f"Column '{self.columns_to_read[0]}' not found in CSV file.")
content = '\n'.join(content)
# Extract the source if available
source = (
row.get(self.source_column, None)
if self.source_column is not None
else self.file_path
)
metadata = {"source": source, "row": i}
for col in self.metadata_columns:
if col in row:
metadata[col] = row[col]
doc = Document(page_content=content, metadata=metadata)
docs.append(doc)
return docs

View File

@ -1,2 +1,4 @@
from .mypdfloader import RapidOCRPDFLoader
from .myimgloader import RapidOCRLoader
from .myimgloader import RapidOCRLoader
from .mydocloader import RapidOCRDocLoader
from .mypptloader import RapidOCRPPTLoader

View File

@ -0,0 +1,71 @@
from langchain.document_loaders.unstructured import UnstructuredFileLoader
from typing import List
import tqdm
class RapidOCRDocLoader(UnstructuredFileLoader):
def _get_elements(self) -> List:
def doc2text(filepath):
from docx.table import _Cell, Table
from docx.oxml.table import CT_Tbl
from docx.oxml.text.paragraph import CT_P
from docx.text.paragraph import Paragraph
from docx import Document, ImagePart
from PIL import Image
from io import BytesIO
import numpy as np
from rapidocr_onnxruntime import RapidOCR
ocr = RapidOCR()
doc = Document(filepath)
resp = ""
def iter_block_items(parent):
from docx.document import Document
if isinstance(parent, Document):
parent_elm = parent.element.body
elif isinstance(parent, _Cell):
parent_elm = parent._tc
else:
raise ValueError("RapidOCRDocLoader parse fail")
for child in parent_elm.iterchildren():
if isinstance(child, CT_P):
yield Paragraph(child, parent)
elif isinstance(child, CT_Tbl):
yield Table(child, parent)
b_unit = tqdm.tqdm(total=len(doc.paragraphs)+len(doc.tables),
desc="RapidOCRDocLoader block index: 0")
for i, block in enumerate(iter_block_items(doc)):
b_unit.set_description(
"RapidOCRDocLoader block index: {}".format(i))
b_unit.refresh()
if isinstance(block, Paragraph):
resp += block.text.strip() + "\n"
images = block._element.xpath('.//pic:pic') # 获取所有图片
for image in images:
for img_id in image.xpath('.//a:blip/@r:embed'): # 获取图片id
part = doc.part.related_parts[img_id] # 根据图片id获取对应的图片
if isinstance(part, ImagePart):
image = Image.open(BytesIO(part._blob))
result, _ = ocr(np.array(image))
if result:
ocr_result = [line[1] for line in result]
resp += "\n".join(ocr_result)
elif isinstance(block, Table):
for row in block.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
resp += paragraph.text.strip() + "\n"
b_unit.update(1)
return resp
text = doc2text(self.file_path)
from unstructured.partition.text import partition_text
return partition_text(text=text, **self.unstructured_kwargs)
if __name__ == '__main__':
loader = RapidOCRDocLoader(file_path="../tests/samples/ocr_test.docx")
docs = loader.load()
print(docs)

View File

@ -1,13 +1,13 @@
from typing import List
from langchain.document_loaders.unstructured import UnstructuredFileLoader
from document_loaders.ocr import get_ocr
class RapidOCRLoader(UnstructuredFileLoader):
def _get_elements(self) -> List:
def img2text(filepath):
from rapidocr_onnxruntime import RapidOCR
resp = ""
ocr = RapidOCR()
ocr = get_ocr()
result, _ = ocr(filepath)
if result:
ocr_result = [line[1] for line in result]

View File

@ -1,29 +1,79 @@
from typing import List
from langchain.document_loaders.unstructured import UnstructuredFileLoader
import cv2
from PIL import Image
import numpy as np
from configs import PDF_OCR_THRESHOLD
from document_loaders.ocr import get_ocr
import tqdm
class RapidOCRPDFLoader(UnstructuredFileLoader):
def _get_elements(self) -> List:
def rotate_img(img, angle):
'''
img --image
angle --rotation angle
return--rotated img
'''
h, w = img.shape[:2]
rotate_center = (w/2, h/2)
#获取旋转矩阵
# 参数1为旋转中心点;
# 参数2为旋转角度,正值-逆时针旋转;负值-顺时针旋转
# 参数3为各向同性的比例因子,1.0原图2.0变成原来的2倍0.5变成原来的0.5倍
M = cv2.getRotationMatrix2D(rotate_center, angle, 1.0)
#计算图像新边界
new_w = int(h * np.abs(M[0, 1]) + w * np.abs(M[0, 0]))
new_h = int(h * np.abs(M[0, 0]) + w * np.abs(M[0, 1]))
#调整旋转矩阵以考虑平移
M[0, 2] += (new_w - w) / 2
M[1, 2] += (new_h - h) / 2
rotated_img = cv2.warpAffine(img, M, (new_w, new_h))
return rotated_img
def pdf2text(filepath):
import fitz
from rapidocr_onnxruntime import RapidOCR
import fitz # pyMuPDF里面的fitz包不要与pip install fitz混淆
import numpy as np
ocr = RapidOCR()
ocr = get_ocr()
doc = fitz.open(filepath)
resp = ""
for page in doc:
# TODO: 依据文本与图片顺序调整处理方式
b_unit = tqdm.tqdm(total=doc.page_count, desc="RapidOCRPDFLoader context page index: 0")
for i, page in enumerate(doc):
b_unit.set_description("RapidOCRPDFLoader context page index: {}".format(i))
b_unit.refresh()
text = page.get_text("")
resp += text + "\n"
img_list = page.get_images()
img_list = page.get_image_info(xrefs=True)
for img in img_list:
pix = fitz.Pixmap(doc, img[0])
img_array = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, -1)
result, _ = ocr(img_array)
if result:
ocr_result = [line[1] for line in result]
resp += "\n".join(ocr_result)
if xref := img.get("xref"):
bbox = img["bbox"]
# 检查图片尺寸是否超过设定的阈值
if ((bbox[2] - bbox[0]) / (page.rect.width) < PDF_OCR_THRESHOLD[0]
or (bbox[3] - bbox[1]) / (page.rect.height) < PDF_OCR_THRESHOLD[1]):
continue
pix = fitz.Pixmap(doc, xref)
samples = pix.samples
if int(page.rotation)!=0: #如果Page有旋转角度则旋转图片
img_array = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, -1)
tmp_img = Image.fromarray(img_array);
ori_img = cv2.cvtColor(np.array(tmp_img),cv2.COLOR_RGB2BGR)
rot_img = rotate_img(img=ori_img, angle=360-page.rotation)
img_array = cv2.cvtColor(rot_img, cv2.COLOR_RGB2BGR)
else:
img_array = np.frombuffer(pix.samples, dtype=np.uint8).reshape(pix.height, pix.width, -1)
result, _ = ocr(img_array)
if result:
ocr_result = [line[1] for line in result]
resp += "\n".join(ocr_result)
# 更新进度
b_unit.update(1)
return resp
text = pdf2text(self.file_path)
@ -32,6 +82,6 @@ class RapidOCRPDFLoader(UnstructuredFileLoader):
if __name__ == "__main__":
loader = RapidOCRPDFLoader(file_path="../tests/samples/ocr_test.pdf")
loader = RapidOCRPDFLoader(file_path="/Users/tonysong/Desktop/test.pdf")
docs = loader.load()
print(docs)

View File

@ -0,0 +1,59 @@
from langchain.document_loaders.unstructured import UnstructuredFileLoader
from typing import List
import tqdm
class RapidOCRPPTLoader(UnstructuredFileLoader):
def _get_elements(self) -> List:
def ppt2text(filepath):
from pptx import Presentation
from PIL import Image
import numpy as np
from io import BytesIO
from rapidocr_onnxruntime import RapidOCR
ocr = RapidOCR()
prs = Presentation(filepath)
resp = ""
def extract_text(shape):
nonlocal resp
if shape.has_text_frame:
resp += shape.text.strip() + "\n"
if shape.has_table:
for row in shape.table.rows:
for cell in row.cells:
for paragraph in cell.text_frame.paragraphs:
resp += paragraph.text.strip() + "\n"
if shape.shape_type == 13: # 13 表示图片
image = Image.open(BytesIO(shape.image.blob))
result, _ = ocr(np.array(image))
if result:
ocr_result = [line[1] for line in result]
resp += "\n".join(ocr_result)
elif shape.shape_type == 6: # 6 表示组合
for child_shape in shape.shapes:
extract_text(child_shape)
b_unit = tqdm.tqdm(total=len(prs.slides),
desc="RapidOCRPPTLoader slide index: 1")
# 遍历所有幻灯片
for slide_number, slide in enumerate(prs.slides, start=1):
b_unit.set_description(
"RapidOCRPPTLoader slide index: {}".format(slide_number))
b_unit.refresh()
sorted_shapes = sorted(slide.shapes,
key=lambda x: (x.top, x.left)) # 从上到下、从左到右遍历
for shape in sorted_shapes:
extract_text(shape)
b_unit.update(1)
return resp
text = ppt2text(self.file_path)
from unstructured.partition.text import partition_text
return partition_text(text=text, **self.unstructured_kwargs)
if __name__ == '__main__':
loader = RapidOCRPPTLoader(file_path="../tests/samples/ocr_test.pptx")
docs = loader.load()
print(docs)

18
document_loaders/ocr.py Normal file
View File

@ -0,0 +1,18 @@
from typing import TYPE_CHECKING
if TYPE_CHECKING:
try:
from rapidocr_paddle import RapidOCR
except ImportError:
from rapidocr_onnxruntime import RapidOCR
def get_ocr(use_cuda: bool = True) -> "RapidOCR":
try:
from rapidocr_paddle import RapidOCR
ocr = RapidOCR(det_use_cuda=use_cuda, cls_use_cuda=use_cuda, rec_use_cuda=use_cuda)
except ImportError:
from rapidocr_onnxruntime import RapidOCR
ocr = RapidOCR()
return ocr

View File

@ -0,0 +1,79 @@
'''
该功能是为了将关键词加入到embedding模型中以便于在embedding模型中进行关键词的embedding
该功能的实现是通过修改embedding模型的tokenizer来实现的
该功能仅仅对EMBEDDING_MODEL参数对应的的模型有效输出后的模型保存在原本模型
感谢@CharlesJu1和@charlesyju的贡献提出了想法和最基础的PR
保存的模型的位置位于原本嵌入模型的目录下模型的名称为原模型名称+Merge_Keywords_时间戳
'''
import sys
sys.path.append("..")
import os
import torch
from datetime import datetime
from configs import (
MODEL_PATH,
EMBEDDING_MODEL,
EMBEDDING_KEYWORD_FILE,
)
from safetensors.torch import save_model
from sentence_transformers import SentenceTransformer
from langchain_core._api import deprecated
@deprecated(
since="0.3.0",
message="自定义关键词 Langchain-Chatchat 0.3.x 重写, 0.2.x中相关功能将废弃",
removal="0.3.0"
)
def get_keyword_embedding(bert_model, tokenizer, key_words):
tokenizer_output = tokenizer(key_words, return_tensors="pt", padding=True, truncation=True)
input_ids = tokenizer_output['input_ids']
input_ids = input_ids[:, 1:-1]
keyword_embedding = bert_model.embeddings.word_embeddings(input_ids)
keyword_embedding = torch.mean(keyword_embedding, 1)
return keyword_embedding
def add_keyword_to_model(model_name=EMBEDDING_MODEL, keyword_file: str = "", output_model_path: str = None):
key_words = []
with open(keyword_file, "r") as f:
for line in f:
key_words.append(line.strip())
st_model = SentenceTransformer(model_name)
key_words_len = len(key_words)
word_embedding_model = st_model._first_module()
bert_model = word_embedding_model.auto_model
tokenizer = word_embedding_model.tokenizer
key_words_embedding = get_keyword_embedding(bert_model, tokenizer, key_words)
embedding_weight = bert_model.embeddings.word_embeddings.weight
embedding_weight_len = len(embedding_weight)
tokenizer.add_tokens(key_words)
bert_model.resize_token_embeddings(len(tokenizer), pad_to_multiple_of=32)
embedding_weight = bert_model.embeddings.word_embeddings.weight
with torch.no_grad():
embedding_weight[embedding_weight_len:embedding_weight_len + key_words_len, :] = key_words_embedding
if output_model_path:
os.makedirs(output_model_path, exist_ok=True)
word_embedding_model.save(output_model_path)
safetensors_file = os.path.join(output_model_path, "model.safetensors")
metadata = {'format': 'pt'}
save_model(bert_model, safetensors_file, metadata)
print("save model to {}".format(output_model_path))
def add_keyword_to_embedding_model(path: str = EMBEDDING_KEYWORD_FILE):
keyword_file = os.path.join(path)
model_name = MODEL_PATH["embed_model"][EMBEDDING_MODEL]
model_parent_directory = os.path.dirname(model_name)
current_time = datetime.now().strftime('%Y%m%d_%H%M%S')
output_model_name = "{}_Merge_Keywords_{}".format(EMBEDDING_MODEL, current_time)
output_model_path = os.path.join(model_parent_directory, output_model_name)
add_keyword_to_model(model_name, keyword_file, output_model_path)

View File

@ -0,0 +1,3 @@
Langchain-Chatchat
数据科学与大数据技术
人工智能与先进计算

BIN
img/LLM_success.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

BIN
img/agent_continue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
img/agent_success.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
img/chatchat-qrcode.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

BIN
img/fastapi_docs_026.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
img/init_knowledge_base.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

BIN
img/official_account_qr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

9
img/partners/autodl.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 123 KiB

9
img/partners/aws.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 42 KiB

55
img/partners/chatglm.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,9 @@
<svg width="654" height="213" viewBox="0 0 654 213" fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="654" width="213" height="654" transform="rotate(90 654 0)" fill="url(#pattern0)"/>
<defs>
<pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1" height="1">
<use xlink:href="#image0_237_57" transform="matrix(0.0204695 0 0 0.00666667 -0.00150228 0)"/>
</pattern>
<image id="image0_237_57" width="49" height="150" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADEAAACWCAYAAAB3hWBKAAAMyElEQVR4Ae1de5AcRRk/AR88C2MgIdzdfB0jIioFIoggGkoeCbnt3lAVtUALygdCUSWI0X8M3LcHiUHkEQoIuem7aKR4pCJSFFqQ6cvyCMnMXngVBORhBaG0ohaiIgqCrPX1bO/OzM7uzcztZAO1VzU1szPf1/39+uvn933d19fX+9vNSgAFuwo53J/rVYDzcoWNAtaiYNVcLw5X5guCA+YKgAoodxAFODdXEByeKhVA5KyJ/nlI2mh1CfZaAOSzLeka/GMB+uqIGDgpVwBTJX7VabP2DQqEAlZNxUPfUcCWOh9nz685pu/9SfhyoRnh1tF1YQSrljhckCSjUsFaGORDbn0zCV8uNCVuLQoLw3iSjLCvbw/k7I0GL9yehC8XmpKArzYEYdWSsBYnzQgFbG/wwmNJ+TpOh8I6qyGI7ipXJMkEl/R9ADm8XuflbHMSvlxoRoasz9cFaQyIG1CwpSXOTsUizG+6CoNDyOGuEB+H1bkImCRRnN+3Fwp4NSRQA0ziUb40NPjlJPnlRlPi7IfTAsHZxtyES5qw7mkEjGcCwmErnt4/I2leudONFAePGebwIxRsHQoot5/1snuwAMVqX9/7chesl0GvBHolkK0E/JEbHsvUQ+mJI7s0W84d4kLBrsgqvOEr8S6CuJLP3D88G822Fu8qCBSDp5jSnM69uyA4403CF+C8pklf3EQw8O6KM5jVodqdPpkR0f/pCAgvfSpd5qBZ7LBgf68D4ewPXRYpW/YoGK0fGtPuxXMPy5ZSF7lKnH0nBEKw5V0UJ1vWP1k0+GEU7M06EM52rl/St2e21LrERdNp5DBRB6HNkmyy/VQ8YqAuwLldEt/PFgV7KQQg2D6SPnPA7oLg7K0eCF39uqwJmjIkMCK3NkiTobkI87tanXqZ90qggyWAwjoh7ay1iZ73z+ugSOmTQs52TruLFdb16XPuIEcPRH1Ef7drgrNfYhGO6mDlyD8p5OzqYBvK3f2bB6QrxJyBIAgU8Os88sk9TW01r7cH9iaZfnLPtNMZlDhcFNRGiVtndzqP3NPDAhwfBIEcbss9005ngBzOD4EQsL3TeaRKjxpmqqVoyH9dt5K8nCrTThOjYH8Ol2pdsIYZp9GI499x9lCn5UqVXidAkNknVaadJp4WCA7vIGc3dN3EQ9EDWZanJW79AAtweKcLtZfebl8COhClEf6GyNkXd3uhowKWBHw/1I1ytixKQ79rJs1ADC27IY6uK+90Iwz09a3cU9TLhMAK2NIVgeMy7YGIK5VuvOtpohulHpdnTxNxpdKNd+8NTTQNdjDWZE8twvwSt04OjRMcnoqja3q3aHBu7sqJaiIkaGAQzPw+7/0TVEI9EEk01dNEwtaECw/tb2qMgVCfaX/bFQ07IdYeWa8EeiVQKwHPkWd5jv2Yp2Q1y+UqO1VcrA5jHbI+E1XANUv6976cs49H30/521P28iyCB3nSgKDdAcjhGdrysGLxoR8pcRg2/g3kek/g2JRCBwk2bx7b33PsN4ICZXlOCuL6hfM+iII9iQXrKvKfLz/TOgQ53IHcGiH3gJ67cUgHYlKNn5JF6ChPUhBITkoBt+s9S4IVDIgVC2cfhILdqCPg0oJwHVtEBfIc+1bPsTHNVdk0/qWghuOekVujyOFvtXC9paUACEM/wgdPxNQglH1kGIT9rEmwk3cSGDn7J1UhSrdm/73N98TC9rotWMAqFDCeKu9yubyXq+zX6kAcO5e42BJnS5DD76khN4GgNYuxTgrr+tQgKEHPkffUQShZdTeu/ViqkkhAjEsO2g85PIoCtmFhzj6hNiEaWz5x8dzDUlcnDULJc4IgqMtNIFdqkuWczdJBkxzWxIEg+zAKeDgTCNe95QBX2W8ZIK6yd1aruEdqKRMw4BA7DnXgpLW83sVSb0VB9gJeoB1jmUBQ3p6S6w0IuruOPZ6md5p07MQxgCVh/RiFv+EW+cAc3eUW4Sg9htBgl7ZhEwDXketcZf87CCL1s2MnjovVRmsOjw4PDX4hqjzaeJgpViRYlVILb+ZaKUBEBe/I7/cKCMdz7Punc1UmxrobK94RdfYS6ZVAcwnQIDfpyKOp349envqFnvc0c+0mb6rr1+/pKftbniNfatXNViZkwYi7rbzmcG9ibNhVtuMq2f0dYdu2rdnHVbLcSvjG+9EhA0Kvyc0YoWS1smn0k+ZbqztNAmk2G/yOHH5LE0K9VY4miNMY7G5oCNraUBDUxBP3rTs4yOM6csoTVPAMmE1L0RAIAb/Rs1oOm0pF9o1Ma+xtD645xHXk2xGB3nYd6dbGjf+Zb0EQJIir5IvmmzchrwkKF33WEz86/4azv4QCxAS8ghyuq81uz/dBMBnlb/vbVfapdUH0xE8+75btfsMUnFNNbhoLHRHjOnKz4XWVbBsDSNUEuXUmctiEgt2NBbgYOdw6zFkFOXvePxsHVmbShKdk0QhC94qyv24A0N1z5L8a3xttwv9m32u+UQMP8sU96+qkjQRwszZgC1iJAu7V6wwdGNkpEBtHQ+HSSUFQ1YsTPPiuFQgU7EF/1ad3mXmp1xNRTXhKnhPM2HPs101pR9uE58hJ88117LuCfHHPbUAsR84kcrYZs6yxPWWfZAShu+vYz2wv37ifEaKVJlw1dnKIT9lTHm7VGoR1gh9nW6tOaRdFNQtgvQfygcintWmTbE/K/m9dWLJHKblS91pKvlN/T+DV2MkGeNy91uv8DMmyQcYCDj/3Sx5eoLN0/P2vGdsEZegp+86gQBmeH48TPPguBMKYZ/SdPYcF9hXk8B9/fU222JRdLGXkKnuWp+xnMwhfpTaTZLSmfHR14mx9GJw/YlNb8Pf7ZVxjayDa4iE3pAHiKrmjokaPDQrV7lkfbCUGjwjSoICV2kCweNbByNktmU37wUQrE6MnuI5c6jpylPr+6GqP5lgVx76WeiqyHgZ5e8+9EnivlQD1MtHVXOLfajz/KJt2BV4pr53tKntjmp6pmdb+abs8cv/mOfbWZqFaL47iabsIgqpQvFC7BoQ+wm+6Gw1p/bCrQGARDtQW8YUzDjDVCzl8DTmbJDcwXSjgMhrZzfdE94oaOzsKgpyRiZhTEmERgLyjwwKepg2HtZDuJ5Gzh5DDtTWX1x30nCrpaHUiB0uqBFIQ+yDgduSwAgXs8H3X7GrtFi4CUFKXFwc+Smc+p0i2r69mb/qr0QZZyLdsWb93qkQSEl9esBg5VIgcOawmrdQOyaINuNlBUIKekmMGRO1eTChXYrIRAZ/THiEOt2FhzkwdFsFhgg7ZpcMTzflQmTRBUjQ55B05mVi6hIR+xABc45/WAjv02qEIByJnzyGHX+lzaykSjo5+TeuMJxl2lNd+yHXkK0Ft0Gw2oXypyHDhjAP0sZXcuoQYa435d/6GXCjTnY62bErUc6QKCpjPc7LBjsyVly6YfSyFP5SEdSEumjWXutkmoaMvPEfelI/gwQGxPQhtPKPqQtE0ZLqkSBs6Pj8mmDI23slV8qJug9ANm8P9NEaEo6Dh1ZBZk2jiqlNFyQXdBmFqhx6hBazS1g2KuqGD2Ws9lqGJvZMdKfGUOsa5kog34VTcN+EPfNYISoez0wZ16mp7Z8+aUundd0UJuI59fDDgpOLYF0wnkmZbec3MYHrk58gdh+vYF0d7KPIGPVKWmU4D2urYnwin136c6AjAOBAkhO8JGrskrVZ2KxCmNEkrW8tr9XQ4SantliA0GDIOK/t71Wp1yrPCOw0CFw3OHSlA+7DUmOr0qNFC891+cCqtaGd8wI/tqanbBA1qtDCK07Q+fJezZTRvarlXPDp/Ik8oRSe7jvxjMwhZJQ+Rq+wLW2kliyboQAZcNPApWi8gHdAQ2aukTfv6ZHl2ZBxQ8jmHJoHGnas9Rc0ru3rkPrl5Kw+MD0QTnSaIZ7RVQx99DDf7R73qY5BfjjrrQ/lGq1PUotFOK7Xg3+8GE8wGAm5Czo6subkuQw4LdOg1nVdLz4K9aIJ/g3nVn6cCQYSkFfJLxFYv3R3LstFKJhCC3ehPAMlLCpdhgZ1mQJQEnN5qt34qEIaYZq0to20c+Q9vQn67uWHLtv/2KvQPbDg80hEQUZ+0AWDuNa/q6lZa8ZSM9m5tQVC6tLXAaEI3Yq0JHa28gbRCFkCTf+w9SXWKY2yrlZRdLPKp2gT8qa0JMysIAvbEfev2dZVN4UQh33VYS1OPE4Eu9nHqZmv7Ye9Gzh7wn+FhFHBnXGHqd9MBYRKd3CRPJI9pWHhjLEgAol6dAv8aKDhWcLZMN/QhdpzJM3TvBAhKkEycrrJXNWslAQgKD2qxvdPvbtkyvculZtIMAcjjh6vGjwitvROusVvJQiYdY8psRfOuff9/T15+hUcbNtcAAAAASUVORK5CYII="/>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
img/qr_code_100.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

BIN
img/qr_code_101.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

BIN
img/qr_code_102.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

BIN
img/qr_code_103.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

BIN
img/qr_code_104.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

BIN
img/qr_code_105.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

BIN
img/qr_code_106.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

BIN
img/qr_code_106_2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

BIN
img/qr_code_107.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

BIN
img/qr_code_108.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

BIN
img/qr_code_90.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

BIN
img/qr_code_90.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

BIN
img/qr_code_91.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

BIN
img/qr_code_92.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

BIN
img/qr_code_93.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

BIN
img/qr_code_94.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

BIN
img/qr_code_95.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

BIN
img/qr_code_96.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

BIN
img/qr_code_97.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

BIN
img/qr_code_98.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

BIN
img/qr_code_99.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

BIN
img/qrcode_90_2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 KiB

View File

@ -1,44 +1,120 @@
from server.knowledge_base.migrate import create_tables, reset_tables, folder2db, recreate_all_vs, list_kbs_from_folder
from configs.model_config import NLTK_DATA_PATH
import sys
sys.path.append(".")
from server.knowledge_base.migrate import (create_tables, reset_tables, import_from_db,
folder2db, prune_db_docs, prune_folder_files)
from configs.model_config import NLTK_DATA_PATH, EMBEDDING_MODEL
import nltk
nltk.data.path = [NLTK_DATA_PATH] + nltk.data.path
from startup import dump_server_info
from datetime import datetime
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.formatter_class = argparse.RawTextHelpFormatter
parser = argparse.ArgumentParser(description="please specify only one operate method once time.")
parser.add_argument(
"-r",
"--recreate-vs",
action="store_true",
help=('''
recreate all vector store.
recreate vector store.
use this option if you have copied document files to the content folder, but vector store has not been populated or DEFAUL_VS_TYPE/EMBEDDING_MODEL changed.
if your vector store is ready with the configs, just skip this option to fill info to database only.
'''
)
)
parser.add_argument(
"--create-tables",
action="store_true",
help=("create empty tables if not existed")
)
parser.add_argument(
"--clear-tables",
action="store_true",
help=("create empty tables, or drop the database tables before recreate vector stores")
)
parser.add_argument(
"--import-db",
help="import tables from specified sqlite database"
)
parser.add_argument(
"-u",
"--update-in-db",
action="store_true",
help=('''
update vector store for files exist in database.
use this option if you want to recreate vectors for files exist in db and skip files exist in local folder only.
'''
)
)
parser.add_argument(
"-i",
"--increment",
action="store_true",
help=('''
update vector store for files exist in local folder and not exist in database.
use this option if you want to create vectors incrementally.
'''
)
)
parser.add_argument(
"--prune-db",
action="store_true",
help=('''
delete docs in database that not existed in local folder.
it is used to delete database docs after user deleted some doc files in file browser
'''
)
)
parser.add_argument(
"--prune-folder",
action="store_true",
help=('''
delete doc files in local folder that not existed in database.
is is used to free local disk space by delete unused doc files.
'''
)
)
parser.add_argument(
"-n",
"--kb-name",
type=str,
nargs="+",
default=[],
help=("specify knowledge base names to operate on. default is all folders exist in KB_ROOT_PATH.")
)
parser.add_argument(
"-e",
"--embed-model",
type=str,
default=EMBEDDING_MODEL,
help=("specify embeddings model.")
)
args = parser.parse_args()
dump_server_info()
start_time = datetime.now()
if args.recreate_vs:
if args.create_tables:
create_tables() # confirm tables exist
if args.clear_tables:
reset_tables()
print("database talbes reseted")
print("recreating all vector stores")
recreate_all_vs()
else:
print("database tables reset")
if args.recreate_vs:
create_tables()
print("database talbes created")
print("filling kb infos to database")
for kb in list_kbs_from_folder():
folder2db(kb, "fill_info_only")
print("recreating all vector stores")
folder2db(kb_names=args.kb_name, mode="recreate_vs", embed_model=args.embed_model)
elif args.import_db:
import_from_db(args.import_db)
elif args.update_in_db:
folder2db(kb_names=args.kb_name, mode="update_in_db", embed_model=args.embed_model)
elif args.increment:
folder2db(kb_names=args.kb_name, mode="increment", embed_model=args.embed_model)
elif args.prune_db:
prune_db_docs(args.kb_name)
elif args.prune_folder:
prune_folder_files(args.kb_name)
end_time = datetime.now()
print(f"总计用时: {end_time-start_time}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

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