快速结论
1、用茴香豆快速搭建Dify问答助手,自带拒答、rerank、切片长度判断、阈值调节功能,回答还能带出图片,顶呱呱👍

2、茴香豆git仓地址:https://github.com/internlm/huixiangdou
遇到问题去翻这里会更多解释~
配置环境
按照教程配置环境,最好一条一条写cli,中间会有要手动输入“YES”的。
(注:1、教程里面写的BCEmbedding0.15错了,应该是BCEmbedding0.1.5
2、huixiangdou仓里的requirements.txt有好多好多依赖,重点记得transformers 要>=4.38就好)
cd /root
git clone https://github.com/internlm/huixiangdou && cd huixiangdou
git checkout 79fa810
apt update
apt install python-dev libxml2-dev libxslt1-dev antiword unrtf poppler-utils pstotext tesseract-ocr flac ffmpeg lame libmad0 libsox-fmt-mp3 sox libjpeg-dev swig libpulse-dev
# python requirements
pip install BCEmbedding==0.1.5 cmake==3.30.2 lit==18.1.8 sentencepiece==0.2.0 protobuf==5.27.3 accelerate==0.33.0
pip install -r requirements.txt
# python3.8 安装 faiss-gpu 而不是 faiss
创建知识库
用dify的的repo作为知识库文档:)
cd /root/huixiangdou && mkdir repodir
git clone https://github.com/internlm/huixiangdou --depth=1 repodir/huixiangdou
git clone https://github.com/open-mmlab/mmpose --depth=1 repodir/mmpose
# Save the features of repodir to workdir, and update the positive and negative example thresholds into `config.ini`
mkdir workdir
python3 -m huixiangdou.service.feature_store
/root/.conda/envs/xtuner/lib/python3.10/runpy.py:126: RuntimeWarning: 'huixiangdou.service.feature_store' found in sys.modules after import of package 'huixiangdou.service', but prior to execution of 'huixiangdou.service.feature_store'; this may result in unpredictable behaviour
warn(RuntimeWarning(msg))
2024-10-06 19:47:30.986 | INFO | huixiangdou.service.retriever:__init__:262 - loading test2vec and rerank models
/root/.conda/envs/xtuner/lib/python3.10/site-packages/torch/_utils.py:831: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
return self.fget.__get__(instance, owner)()
10/06/2024 19:48:24 - [INFO] -BCEmbedding.models.RerankerModel->>> Loading from `/root/models/bce-reranker-base_v1`.
10/06/2024 19:48:24 - [INFO] -BCEmbedding.models.RerankerModel->>> Execute device: cuda; gpu num: 1; use fp16: True
2024-10-06 19:48:25.063 | DEBUG | __main__:__init__:67 - loading text2vec model..
2024-10-06 19:48:25.064 | INFO | __main__:__init__:83 - init dense retrieval database with chunk_size 900
2024-10-06 19:48:50.761 | INFO | __main__:initialize:250 - initialize response and reject feature store, you only need call this once.
2024-10-06 19:48:55.795 | INFO | __main__:read_and_save:31 - reading repodir2/dify/api/templates/invite_member_mail_template_en-US.html, would save to workdir/preprocess/0059f8d4.text
2024-10-06 19:48:55.800 | INFO | __main__:read_and_save:31 - reading repodir2/dify/api/templates/invite_member_mail_template_zh-CN.html, would save to workdir/preprocess/1bfc6b42.text
2024-10-06 19:48:55.807 | INFO | __main__:read_and_save:31 - reading repodir2/dify/api/templates/reset_password_mail_template_en-US.html, would save to workdir/preprocess/56080a6a.text
2024-10-06 19:48:55.815 | INFO | __main__:read_and_save:31 - reading repodir2/dify/api/templates/reset_password_mail_template_zh-CN.html, would save to workdir/preprocess/04929e9e.text
2024-10-06 19:48:56.277 | DEBUG | __main__:preprocess:230 - waiting for file preprocess finish..
Token indices sequence length is longer than the specified maximum sequence length for this model (523 > 512). Running this sequence through the model will result in indexing errors
2024-10-06 19:48:57.267 | INFO | __main__:analyze:170 - text histogram, length count 1186, avg 664.15, median 870
0-94 5.73%
94-188 7.67%
188-282 6.24%
282-376 4.38%
376-470 3.71%
470-564 3.63%
564-658 3.79%
658-752 4.72%
752-846 7.34%
846-940 52.02%
940-1034 0.76%
2024-10-06 19:48:57.268 | INFO | __main__:analyze:171 - token histogram, length count 1186, avg 283.89, median 315
0-52 9.44%
52-104 11.21%
104-156 7.76%
156-208 6.49%
208-260 7.84%
260-312 7.17%
312-364 4.22%
364-416 8.01%
416-468 36.34%
468-520 1.43%
520-572 0.08%
10/06/2024 19:48:57 - [INFO] -faiss.loader->>> Loading faiss with AVX2 support.
10/06/2024 19:48:57 - [INFO] -faiss.loader->>> Could not load library with AVX2 support due to:
ModuleNotFoundError("No module named 'faiss.swigfaiss_avx2'")
10/06/2024 19:48:57 - [INFO] -faiss.loader->>> Loading faiss.
10/06/2024 19:48:57 - [INFO] -faiss.loader->>> Successfully loaded faiss.
0%| | 0/1186 [00:00<?, ?it/s]
0%| | 1/1186 [00:00<11:06, 1.78it/s]
1%| | 12/1186 [00:00<00:49, 23.65it/s]
2%|▏ | 26/1186 [00:00<00:23, 49.12it/s]
3%|▎ | 40/1186 [00:00<00:16, 69.66it/s]
5%|▍ | 54/1186 [00:00<00:13, 86.26it/s]
6%|▌ | 67/1186 [00:01<00:11, 97.72it/s]
7%|▋ | 81/1186 [00:01<00:10, 107.85it/s]
8%|▊ | 95/1186 [00:01<00:09, 115.14it/s]
9%|▉ | 108/1186 [00:01<00:09, 119.06it/s]
10%|█ | 121/1186 [00:01<00:08, 122.13it/s]
11%|█▏ | 135/1186 [00:01<00:08, 125.56it/s]
13%|█▎ | 149/1186 [00:01<00:08, 123.77it/s]
14%|█▎ | 163/1186 [00:01<00:08, 127.36it/s]
15%|█▍ | 176/1186 [00:01<00:07, 127.61it/s]
16%|█▌ | 189/1186 [00:02<00:07, 126.68it/s]
17%|█▋ | 203/1186 [00:02<00:07, 129.05it/s]
18%|█▊ | 217/1186 [00:02<00:07, 131.68it/s]
19%|█▉ | 231/1186 [00:02<00:07, 129.73it/s]
21%|██ | 245/1186 [00:02<00:08, 110.33it/s]
22%|██▏ | 259/1186 [00:02<00:07, 116.48it/s]
23%|██▎ | 273/1186 [00:02<00:07, 121.17it/s]
24%|██▍ | 286/1186 [00:02<00:07, 123.30it/s]
25%|██▌ | 300/1186 [00:02<00:07, 125.92it/s]
26%|██▋ | 314/1186 [00:03<00:06, 127.48it/s]
28%|██▊ | 327/1186 [00:03<00:06, 124.66it/s]
29%|██▉ | 341/1186 [00:03<00:06, 128.37it/s]
30%|██▉ | 354/1186 [00:03<00:06, 128.78it/s]
31%|███ | 368/1186 [00:03<00:06, 129.21it/s]
32%|███▏ | 382/1186 [00:03<00:06, 131.17it/s]
33%|███▎ | 396/1186 [00:03<00:06, 130.83it/s]
35%|███▍ | 410/1186 [00:03<00:06, 128.12it/s]
36%|███▌ | 424/1186 [00:03<00:05, 130.57it/s]
37%|███▋ | 438/1186 [00:03<00:05,
用茴香豆搭建Dify问答助手及效果测试

最低0.47元/天 解锁文章
5755

被折叠的 条评论
为什么被折叠?



