Giter Club home page Giter Club logo

chinese-langchain's Introduction

license title sdk emoji colorFrom colorTo pinned app_file
openrail
Chinese-LangChain
gradio
🚀
yellow
yellow
true
app.py

Chinese-LangChain

Chinese-LangChain:中文langchain项目,基于ChatGLM-6b+langchain实现本地化知识库检索与智能答案生成

https://github.com/yanqiangmiffy/Chinese-LangChain

俗称:小必应,Q.Talk,强聊,QiangTalk

🔥 效果演示

🚋 使用教程

  • 选择知识库询问相关领域的问题

🏗️ 部署教程

运行配置

  • 显存:12g,实际运行9g够了
  • 运行内存:32g

运行环境

langchain
gradio
transformers
sentence_transformers
faiss-cpu
unstructured
duckduckgo_search
mdtex2html
chardet
cchardet

启动Gradio

python main.py

🚀 特性

  • 🚀 2023/05/19 yanlijun573提供streamlit分支
  • 🚀 2023/04/22 支持模型多机多卡推理
  • 🔭 2023/04/20 支持模型问答与检索问答模式切换
  • 💻 2023/04/20 感谢HF官方提供免费算力,添加HuggingFace Spaces在线体验[🤗 DEMO
  • 🧫 2023/04/19 发布45万Wikipedia的文本预处理语料以及FAISS索引向量
  • 🐯 2023/04/19 引入ChuanhuChatGPT皮肤
  • 📱 2023/04/19 增加web search功能,需要确保网络畅通!(感谢@wanghao07456,提供的idea)
  • 📚 2023/04/18 webui增加知识库选择功能
  • 🚀 2023/04/18 修复推理预测超时5s报错问题
  • 🎉 2023/04/17 支持多种文档上传与内容解析:pdf、docx,ppt等
  • 🎉 2023/04/17 支持知识增量更新

🧰 知识库

构建知识库

  • Wikipedia-zh

详情见:corpus/zh_wikipedia/README.md

知识库向量索引

知识库数据 FAISS向量
中文维基百科截止4月份数据,45万 链接:https://pan.baidu.com/s/1VQeA_dq92fxKOtLL3u3Zpg?pwd=l3pn 提取码:l3pn
截止去年九月的130w条中文维基百科处理结果和对应faiss向量文件 @yubuyuabc 链接:https://pan.baidu.com/s/1Yls_Qtg15W1gneNuFP9O_w?pwd=exij 提取码:exij
💹 大规模金融研报知识图谱 链接:https://pan.baidu.com/s/1FcIH5Fi3EfpS346DnDu51Q?pwd=ujjv 提取码:ujjv

🔨 TODO

  • 支持上下文
  • 支持知识增量更新
  • 支持加载不同知识库
  • 支持检索结果与LLM生成结果对比
  • 支持检索生成结果与原始LLM生成结果对比
  • 支持模型问答与检索问答
  • 检索结果过滤与排序
  • 互联网检索结果接入
  • 模型初始化有问题
  • 增加非LangChain策略
  • 显示当前对话策略
  • 构建一个垂直业务场景知识库,非通用性

交流

欢迎多提建议、Bad cases,目前尚不完善,欢迎进群及时交流,也欢迎大家多提PR

合作交流可以联系:

❤️引用

⭐️ Star History

Star History Chart

chinese-langchain's People

Contributors

yanqiangmiffy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chinese-langchain's Issues

多GPU运行的问题

可否实现将两个模型(chatglm和text2vec)加载到不同的GPU上呢,我发现自己的GPU(12G显存,实际可用11G多点)运行时显存会溢出,想问下将两个模型加载到不同GPU上是否可以实现

cache/financial_research_reports/index.faiss for reading: No such file or directory

2023-04-20 13:34:51,654 [INFO] [loader.py:54] Loading faiss with AVX2 support.
2023-04-20 13:34:52,051 [INFO] [loader.py:56] Successfully loaded faiss with AVX2 support.
Error in faiss::FileIOReader::FileIOReader(const char*) at /project/faiss/faiss/impl/io.cpp:67: Error: 'f' failed: could not open cache/financial_research_reports/index.faiss for reading: No such file or directory

python main.py nltk错误

Resource [93mpunkt[om not found.Please use the NLTK Downloader to obtain theresource:
[31m>>> import nltk>>> nltk.download(' punkt')[omFor more information see: https://www.nltk.org/data.html
NLTK's dat
all"), or just tra and no gra
Attempted to load [93mtokenizers/punkt/PY3/english.pickle[om
Searched in:/home/horace/nltk data!/home/horace/.conda/envs/chatglm/nltk data!- '/home/horace/.conda/envs/chatglm/share/nltk data'/home/horace/.conda/envs/chatglm/lib/nltk data'
'/usr/share/nltk data'
'/usr/local/share/nltk data
‘/usr/lib/nltk data’
‘/usr/local/lib/nltk data’

终端中提示我import nltk后使用nltk.download('punkt'),但执行这条命令会失败。查询资料后去官网下载,解压后放到上述提到的指定位置,再运行main.py,发现还是出现这个错误。不知道怎么解决

无法使用“加载知识库”功能。

无法使用“加载知识库”功能

启动服务后只能使用模型推理;

尝试点击:“加载知识库”,报错:”初始化知识库未成功加载“

报错代码:

Error in faiss::FileIOReader::FileIOReader(const char*) at /project/faiss/faiss/impl/io.cpp:67: Error: 'f' failed: could not open cache/index.faiss for reading: No such file or directory

查看源码,并没有发现cache目录;

文件上传功能

左下角的“上传文件到知识库”,文件上传后会保存到docs目录下,但如果是中文名的文件,上传到linux上会乱码;

文件上传后不知道如何使用,仍然是无法加载知识库;

'utf-8' codec can't encode characters in position 1-2: surrogates not allowed

Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
No compiled kernel found.
Compiling kernels : /root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int8/2cc27c946766f6ebd1504001b5d776a27c4d0d0b/quantization_kernels_parallel.c
Compiling gcc -O3 -fPIC -pthread -fopenmp -std=c99 /root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int8/2cc27c946766f6ebd1504001b5d776a27c4d0d0b/quantization_kernels_parallel.c -shared -o /root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int8/2cc27c946766f6ebd1504001b5d776a27c4d0d0b/quantization_kernels_parallel.so
Load kernel : /root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int8/2cc27c946766f6ebd1504001b5d776a27c4d0d0b/quantization_kernels_parallel.so
Setting CPU quantization kernel threads to 6
Using quantization cache
Applying quantization to glm layers
2023-04-20 17:41:52,801 [WARNING] [SentenceTransformer.py:805] No sentence-transformers model found with name /root/.cache/torch/sentence_transformers/GanymedeNil_text2vec-large-chinese. Creating a new one with MEAN pooling.
Traceback (most recent call last):
  File "/home/heyiheng/work/Chinese-LangChain/main.py", line 27, in <module>
    application.source_service.init_source_vector()
  File "/home/heyiheng/work/Chinese-LangChain/clc/source_service.py", line 37, in init_source_vector
    print(doc)
UnicodeEncodeError: `'utf-8' codec can't encode characters in position 1-2: surrogates not allowed`

一个我无法解决的报错,有空的话请帮忙看一下

faiss知识库缺文件?

两个 中文维基百科 的网盘链接里都缺少 index.pkl呀?
如果要自己重新生成的话。。那提供index.faiss有什么意义?

python main.py报错,请问如何解决

Traceback (most recent call last):
File "/root/Chinese-LangChain/main.py", line 26, in
application = LangChainApplication(config)
File "/root/Chinese-LangChain/clc/langchain_application.py", line 24, in init
self.llm_service.load_model(model_name_or_path=self.config.llm_model_name)
File "/root/Chinese-LangChain/clc/gpt_service.py", line 55, in load_model
self.tokenizer = AutoTokenizer.from_pretrained(
File "/root/anaconda3/envs/langchain/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 721, in from_pretrained
raise ValueError(
ValueError: Unrecognized configuration class <class 'transformers_modules.THUDM.chatglm-6b-int4-qe.977d9df4cfae6b7a756e07698483872c5c070eee.configuration_chatglm.ChatGLMConfig'> to build an AutoTokenizer.
Model type should be one of AlbertConfig, AlignConfig, BartConfig, BertConfig, BertGenerationConfig, BigBirdConfig, BigBirdPegasusConfig, BioGptConfig, BlenderbotConfig, BlenderbotSmallConfig, BlipConfig, Blip2Config, BloomConfig, BridgeTowerConfig, CamembertConfig, CanineConfig, ChineseCLIPConfig, ClapConfig, CLIPConfig, CLIPSegConfig, CodeGenConfig, ConvBertConfig, CpmAntConfig, CTRLConfig, Data2VecTextConfig, DebertaConfig, DebertaV2Config, DistilBertConfig, DPRConfig, ElectraConfig, ErnieConfig, ErnieMConfig, EsmConfig, FlaubertConfig, FNetConfig, FSMTConfig, FunnelConfig, GitConfig, GPT2Config, GPT2Config, GPTBigCodeConfig, GPTNeoConfig, GPTNeoXConfig, GPTNeoXJapaneseConfig, GPTJConfig, GPTSanJapaneseConfig, GroupViTConfig, HubertConfig, IBertConfig, JukeboxConfig, LayoutLMConfig, LayoutLMv2Config, LayoutLMv3Config, LEDConfig, LiltConfig, LlamaConfig, LongformerConfig, LongT5Config, LukeConfig, LxmertConfig, M2M100Config, MarianConfig, MBartConfig, MegaConfig, MegatronBertConfig, MgpstrConfig, MobileBertConfig, MPNetConfig, MT5Config, MvpConfig, NezhaConfig, NllbMoeConfig, NystromformerConfig, OneFormerConfig, OpenAIGPTConfig, OPTConfig, OwlViTConfig, PegasusConfig, PegasusXConfig, PerceiverConfig, Pix2StructConfig, PLBartConfig, ProphetNetConfig, QDQBertConfig, RagConfig, RealmConfig, ReformerConfig, RemBertConfig, RetriBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoCBertConfig, RoFormerConfig, RwkvConfig, Speech2TextConfig, Speech2Text2Config, SpeechT5Config, SplinterConfig, SqueezeBertConfig, SwitchTransformersConfig, T5Config, TapasConfig, TransfoXLConfig, ViltConfig, VisualBertConfig, Wav2Vec2Config, Wav2Vec2ConformerConfig, WhisperConfig, XCLIPConfig, XGLMConfig, XLMConfig, XLMProphetNetConfig, XLMRobertaConfig, XLMRobertaXLConfig, XLNetConfig, XmodConfig, YosoConfig.

运行报错

cannot import name 'RetrievalQA' from 'langchain.chains'

CUDA Error: no kernel image is available for execution on the device

当在页面上提问时发生CUDA运行期错误。我的环境:CentOS 7.9+P100单卡+NVIDIA-SMI 460.91.03 Driver Version: 460.91.03 CUDA Version: 11.2+Python 3.10.9,Torch试过了2.0.1和1.8.0都是同样的错。

2023-05-21 23:08:31,755 [WARNING] [logging.py:295] The dtype of attention mask (torch.int64) is not bool
Traceback (most recent call last):
File "/opt/Python/lib/python3.10/site-packages/gradio/routes.py", line 422, in run_predict
output = await app.get_blocks().process_api(
File "/opt/Python/lib/python3.10/site-packages/gradio/blocks.py", line 1323, in process_api
result = await self.call_function(
File "/opt/Python/lib/python3.10/site-packages/gradio/blocks.py", line 1051, in call_function
prediction = await anyio.to_thread.run_sync(
File "/opt/Python/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/opt/Python/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/opt/Python/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/root/Chinese-LangChain/main.py", line 82, in predict
result = application.get_llm_answer(query=input, web_content=web_content)
File "/root/Chinese-LangChain/clc/langchain_application.py", line 85, in get_llm_answer
result = self.llm_service._call(prompt)
File "/root/Chinese-LangChain/clc/gpt_service.py", line 41, in _call
response, _ = self.model.chat(
File "/opt/Python/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a756e07698483872c5c070eee/modeling_chatglm.py", line 1253, in chat
outputs = self.generate(**inputs, **gen_kwargs)
File "/opt/Python/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/opt/Python/lib/python3.10/site-packages/transformers/generation/utils.py", line 1565, in generate
return self.sample(
File "/opt/Python/lib/python3.10/site-packages/transformers/generation/utils.py", line 2612, in sample
outputs = self(
File "/opt/Python/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a756e07698483872c5c070eee/modeling_chatglm.py", line 1158, in forward
transformer_outputs = self.transformer(
File "/opt/Python/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a756e07698483872c5c070eee/modeling_chatglm.py", line 905, in forward
inputs_embeds = self.word_embeddings(input_ids)
File "/opt/Python/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "/root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a756e07698483872c5c070eee/quantization.py", line 384, in forward
original_weight = extract_weight_to_half(weight=self.weight, scale_list=self.weight_scale, source_bit_width=self.weight_bit_width)
File "/root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a756e07698483872c5c070eee/quantization.py", line 239, in extract_weight_to_half
func(
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/kernels/base.py", line 48, in call
func = self._prepare_func()
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/kernels/base.py", line 40, in _prepare_func
self._module.get_module(), self._func_name
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/kernels/base.py", line 24, in get_module
self._module[curr_device] = cuda.cuModuleLoadData(self._code)
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/library/base.py", line 94, in wrapper
return f(*args, **kwargs)
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/library/cuda.py", line 233, in cuModuleLoadData
checkCUStatus(cuda.cuModuleLoadData(ctypes.byref(module), data))
File "/opt/Python/lib/python3.10/site-packages/cpm_kernels/library/cuda.py", line 216, in checkCUStatus
raise RuntimeError("CUDA Error: %s" % cuGetErrorString(error))
RuntimeError: CUDA Error: no kernel image is available for execution on the device

执行python main.py的时候提示:No module named 'transformers.generation'

操作系统版本:Ubuntu 20.04 LTS
python版本:3.10.9
transformers安装的时候没有指定版本,安装的是最新4.24.0版
(base) root@st-desktop:~/xxy/Chinese-LangChain# python -m pip list |grep transformers
sentence-transformers 2.2.2
transformers 4.24.0

部分报错信息如下:
│ │
│ /root/anaconda3/lib/python3.10/importlib/init.py:126 in import_module │
│ │
│ 123 │ │ │ if character != '.': │
│ 124 │ │ │ │ break │
│ 125 │ │ │ level += 1 │
│ ❱ 126 │ return _bootstrap._gcd_import(name[level:], package, level) │
│ 127 │
│ 128 │
│ 129 _RELOADING = {} │
│ :1050 in _gcd_import │
│ :1027 in _find_and_load │
│ :1006 in _find_and_load_unlocked │
│ :688 in _load_unlocked │
│ :883 in exec_module │
│ :241 in _call_with_frames_removed │
│ │
│ /root/.cache/huggingface/modules/transformers_modules/THUDM/chatglm-6b-int4-qe/977d9df4cfae6b7a7 │
│ 56e07698483872c5c070eee/modeling_chatglm.py:30 in │
│ │
│ 27 ) │
│ 28 from transformers.modeling_utils import PreTrainedModel │
│ 29 from transformers.utils import logging │
│ ❱ 30 from transformers.generation.logits_process import LogitsProcessor │
│ 31 from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, Gen │
│ 32 │
│ 33 from .configuration_chatglm import ChatGLMConfig │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'transformers.generation'

请教大家

requirements.txt

python main.py时报错:
│ D:\miniconda3\envs\langcn\lib\site-packages\unstructured\partition\pdf.py:5 in │
│ │
│ 2 from io import StringIO │
│ 3 from typing import BinaryIO, List, Optional, cast │
│ 4 │
│ ❱ 5 from pdfminer.pdfpage import PDFPage, PDFTextExtractionNotAllowed │
│ 6 from pdfminer.utils import open_filename │
│ 7 │
│ 8 from unstructured.documents.elements import Element, ElementMetadata, PageBreak │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ModuleNotFoundError: No module named 'pdfminer'

库文件调整为
unstructured[local-inference]
不报错了

ModuleNotFoundError: No module named 'mdtex2html'

C:\Users\admin\Desktop\Chinese-LangChain-master>py main.py
Traceback (most recent call last):
File "C:\Users\admin\Desktop\Chinese-LangChain-master\main.py", line 4, in
from app_modules.overwrites import postprocess
File "C:\Users\admin\Desktop\Chinese-LangChain-master\app_modules\overwrites.py", line 5, in
from app_modules.utils import *
File "C:\Users\admin\Desktop\Chinese-LangChain-master\app_modules\utils.py", line 8, in
import mdtex2html
ModuleNotFoundError: No module named 'mdtex2html'

如何生成index.faiss和index.pkl文件

谢谢作者的工作。
看文件说明是看corpus下中文wiki下的readme文件,但readme文件中是指数据清洗,没有提到如何生成index.faiss文件。
想请教下,如何生成index.faiss和index.pkl文件呢?(初始化后.cache文件夹下的index.pkl)

langchain+zapier

这个项目是否能实现langchain+zapier那样强大的功能呢?国内现在有没有zapier natural language api这样强大的工具呢?

ModuleNotFoundError: No module named 'transformers_modules.'

Traceback (most recent call last):
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\main.py", line 26, in
application = LangChainApplication(config)
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\clc\langchain_application.py", line 24, in init
self.llm_service.load_model(model_name_or_path=self.config.llm_model_name)
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\clc\gpt_service.py", line 55, in load_model
self.tokenizer = AutoTokenizer.from_pretrained(
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\venv\lib\site-packages\transformers\models\auto\tokenization_auto.py", line 663, in from_pretrained
tokenizer_class = get_class_from_dynamic_module(
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 399, in get_class_from_dynamic_module
return get_class_in_module(class_name, final_module.replace(".py", ""))
File "C:\Users\86152\PycharmProjects\new\Chinese-LangChain-master\venv\lib\site-packages\transformers\dynamic_module_utils.py", line 177, in get_class_in_module
module = importlib.import_module(module_path)
File "D:\Ksoftware\python39\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 972, in _find_and_load_unlocked
File "", line 228, in _call_with_frames_removed
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 972, in _find_and_load_unlocked
File "", line 228, in _call_with_frames_removed
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'transformers_modules.'
运行python main.py发生这样的错误,应该怎么解决

langchain-serve 集成

Hey 我是来自 langchain-serve 的dev!

请问你们在langchain部分的集成有线上的场景吗?

如果有可以考虑了解下我们的产品,方便把langchain部署在云端:

  • Exposes APIs from function definitions locally as well as on the cloud.
  • Very few lines of code changes, ease of development remains the same as local.
  • Supports both REST & Websocket endpoints
  • Serverless/autoscaling endpoints with automatic tls certs.
  • Real-time streaming, human-in-the-loop support

谢谢

希望取得联系

尊敬的Chinese-LangChain 应用开发者,我是 InternLM 社区开发者&志愿者尖米, 大佬开源的工作对我的启发很大,希望可以探讨使用 InternLM 实现Chinese-LangChain 的可能性和实现路径,我的微信是mzm312,希望可以取得联系进行更深度的交流;

RuntimeError: Internal: src/sentencepiece_processor.cc(1101) [model_proto->ParseFromArray(serialized.data(), serialized.size())]

环境:
Python 3.10.8
cat /proc/version
Linux version 5.4.0-99-generic (buildd@lgw01-amd64-007) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu120.04)) #112-Ubuntu SMP Thu Feb 3 13:50:55 UTC 2022
root@autodl-container-28d9119efa-9edf73a5:
/autodl-tmp/Chinese-LangChain# cat /etc/issue
Ubuntu 22.04.1 LTS \n \l

我自己下载了模型
/root/autodl-tmp/THUDM/chatglm-6b-int4
/root/autodl-tmp/GanymedeNil/text2vec-large-chinese

做了如下修改:

llm_model_name = '/root/autodl-tmp/THUDM/chatglm-6b-int4'  # 本地模型文件 or huggingface远程仓库
embedding_model_name = '/root/autodl-tmp/GanymedeNil/text2vec-large-chinese'  # 检索模型文件 or huggingface远程仓库

运行:
python main.py
报错:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /root/autodl-tmp/Chinese-LangChain/main.py:26 in │
│ │
│ 23 │
│ 24 │
│ 25 config = LangChainCFG() │
│ ❱ 26 application = LangChainApplication(config) │
│ 27 │
│ 28 application.source_service.init_source_vector() │
│ 29 │
│ │
│ /root/autodl-tmp/Chinese-LangChain/clc/langchain_application.py:24 in init
│ │
│ 21 │ def init(self, config): │
│ 22 │ │ self.config = config │
│ 23 │ │ self.llm_service = ChatGLMService() │
│ ❱ 24 │ │ self.llm_service.load_model(model_name_or_path=self.config.llm_model_name) │
│ 25 │ │ # self.llm_service.load_model_on_gpus(model_name_or_path=self.config.llm_model_n │
│ 26 │ │ self.source_service = SourceService(config) │
│ 27 │
│ │
│ /root/autodl-tmp/Chinese-LangChain/clc/gpt_service.py:55 in load_model │
│ │
│ 52 │ │
│ 53 │ def load_model(self, │
│ 54 │ │ │ │ model_name_or_path: str = "THUDM/chatglm-6b"): │
│ ❱ 55 │ │ self.tokenizer = AutoTokenizer.from_pretrained( │
│ 56 │ │ │ model_name_or_path, │
│ 57 │ │ │ trust_remote_code=True │
│ 58 │ │ ) │
│ │
│ /root/miniconda3/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py:693 │
│ in from_pretrained │
│ │
│ 690 │ │ │ │ raise ValueError( │
│ 691 │ │ │ │ │ f"Tokenizer class {tokenizer_class_candidate} does not exist or is n │
│ 692 │ │ │ │ ) │
│ ❱ 693 │ │ │ return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *input │
│ 694 │ │ │
│ 695 │ │ # Otherwise we have to be creative. │
│ 696 │ │ # if model is an encoder decoder, the encoder tokenizer class is used by default │
│ │
│ /root/miniconda3/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1812 in │
│ from_pretrained │
│ │
│ 1809 │ │ │ else: │
│ 1810 │ │ │ │ logger.info(f"loading file {file_path} from cache at {resolved_vocab_fil │
│ 1811 │ │ │
│ ❱ 1812 │ │ return cls._from_pretrained( │
│ 1813 │ │ │ resolved_vocab_files, │
│ 1814 │ │ │ pretrained_model_name_or_path, │
│ 1815 │ │ │ init_configuration, │
│ │
│ /root/miniconda3/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1975 in │
│ _from_pretrained │
│ │
│ 1972 │ │ │
│ 1973 │ │ # Instantiate tokenizer. │
│ 1974 │ │ try: │
│ ❱ 1975 │ │ │ tokenizer = cls(*init_inputs, **init_kwargs) │
│ 1976 │ │ except OSError: │
│ 1977 │ │ │ raise OSError( │
│ 1978 │ │ │ │ "Unable to load vocabulary from file. " │
│ │
│ /root/.cache/huggingface/modules/transformers_modules/chatglm-6b-int4/tokenization_chatglm.py:22 │
│ 1 in init
│ │
│ 218 │ │ self.mask_token = mask_token │
│ 219 │ │ self.gmask_token = gmask_token │
│ 220 │ │ │
│ ❱ 221 │ │ self.sp_tokenizer = SPTokenizer(vocab_file, num_image_tokens=num_image_tokens) │
│ 222 │ │ │
│ 223 │ │ """ Initialisation """ │
│ 224 │
│ │
│ /root/.cache/huggingface/modules/transformers_modules/chatglm-6b-int4/tokenization_chatglm.py:64 │
│ in init
│ │
│ 61 │ │ self.special_tokens = ["[MASK]", "[gMASK]", "[sMASK]", "<unused_0>", "", "< │
│ 62 │ │ self.max_blank_length = max_blank_length │
│ 63 │ │ self.byte_fallback = byte_fallback │
│ ❱ 64 │ │ self.text_tokenizer = TextTokenizer(vocab_file) │
│ 65 │ │
│ 66 │ def _get_text_tokenizer(self): │
│ 67 │ │ return self.text_tokenizer │
│ │
│ /root/.cache/huggingface/modules/transformers_modules/chatglm-6b-int4/tokenization_chatglm.py:22 │
│ in init
│ │
│ 19 class TextTokenizer: │
│ 20 │ def init(self, model_path): │
│ 21 │ │ self.sp = spm.SentencePieceProcessor() │
│ ❱ 22 │ │ self.sp.Load(model_path) │
│ 23 │ │ self.num_tokens = self.sp.vocab_size() │
│ 24 │ │
│ 25 │ def encode(self, text): │
│ │
│ /root/miniconda3/lib/python3.10/site-packages/sentencepiece/init.py:905 in Load │
│ │
│ 902 │ │ raise RuntimeError('model_file and model_proto must be exclusive.') │
│ 903 │ if model_proto: │
│ 904 │ │ return self.LoadFromSerializedProto(model_proto) │
│ ❱ 905 │ return self.LoadFromFile(model_file) │
│ 906 │
│ 907 │
│ 908 # Register SentencePieceProcessor in _sentencepiece: │
│ │
│ /root/miniconda3/lib/python3.10/site-packages/sentencepiece/init.py:310 in LoadFromFile │
│ │
│ 307 │ │ return _sentencepiece.SentencePieceProcessor_serialized_model_proto(self) │
│ 308 │ │
│ 309 │ def LoadFromFile(self, arg): │
│ ❱ 310 │ │ return _sentencepiece.SentencePieceProcessor_LoadFromFile(self, arg) │
│ 311 │ │
│ 312 │ def _EncodeAsIds(self, text, enable_sampling, nbest_size, alpha, add_bos, add_eos, r │
│ 313 │ │ return _sentencepiece.SentencePieceProcessor__EncodeAsIds(self, text, enable_sam │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: Internal: src/sentencepiece_processor.cc(1101) [model_proto->ParseFromArray(serialized.data(), serialized.size())]

上传文档,文档内容有什么要求吗

请问下,如果我想加载自己的数据库文档,txt格式。文档里面的内容应该用什么样的格式,才能使模型的效果更好呢?这方便有什么要求吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.