chatchat-space / Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain
Apache License 2.0
30.02k stars 5.25k forks source link

创建知识库错误 chatchat-kb -r #4429

Closed zhaozhizhuo closed 1 week ago

zhaozhizhuo commented 2 weeks ago

详细报错 recreating all vector stores /home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following: from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser warnings.warn( 2024-07-05 17:03:45,456 - utils.py[line:260] - ERROR: failed to create Embeddings for model: custom. Traceback (most recent call last): File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/utils.py", line 258, in get_Embeddings return LocalAIEmbeddings(params) File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/pydantic/v1/main.py", line 341, in init raise validation_error pydantic.v1.error_wrappers.ValidationError: 1 validation error for LocalAIEmbeddings root Did not find openai_api_key, please add an environment variable OPENAI_API_KEY which contains it, or pass openai_api_key as a named parameter. (type=value_error) 2024-07-05 17:03:45,457 - faiss_cache.py[line:140] - ERROR: 'NoneType' object has no attribute 'embed_documents' Traceback (most recent call last): File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 126, in load_vector_store vector_store = self.new_vector_store( File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 63, in new_vector_store vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True) File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/langchain_core/vectorstores.py", line 550, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, kwargs) File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 930, in from_texts embeddings = embedding.embed_documents(texts) AttributeError: 'NoneType' object has no attribute 'embed_documents' 2024-07-05 17:03:45,458 - init_database.py[line:150] - ERROR: 向量库 samples 加载失败。 Traceback (most recent call last): File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 126, in load_vector_store vector_store = self.new_vector_store( File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 63, in new_vector_store vector_store = FAISS.from_documents([doc], embeddings, normalize_L2=True) File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/langchain_core/vectorstores.py", line 550, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 930, in from_texts embeddings = embedding.embed_documents(texts) AttributeError: 'NoneType' object has no attribute 'embed_documents'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/init_database.py", line 129, in main folder2db( File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/migrate.py", line 157, in folder2db kb.create_kb() File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_service/base.py", line 102, in create_kb self.do_create_kb() File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 57, in do_create_kb self.load_vector_store() File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_service/faiss_kb_service.py", line 32, in load_vector_store return kb_faiss_pool.load_vector_store( File "/home/zhaozhizhuo22/.conda/envs/llm_tl/lib/python3.10/site-packages/chatchat/server/knowledge_base/kb_cache/faiss_cache.py", line 141, in load_vector_store raise RuntimeError(f"向量库 {kb_name} 加载失败。") RuntimeError: 向量库 samples 加载失败。 2024-07-05 17:03:45,459 - init_database.py[line:151] - WARNING: Caught KeyboardInterrupt! Setting stop event...

annsshadow commented 1 week ago

请问解决了吗?

zhaozhizhuo commented 1 week ago

如果你自定义了模型的uid你需要更改一下在langchain环境下的xinference的默认参数:对应的命令是:chatchat-config model --set_model_platforms "[{ \"platform_name\": \"xinference\", \"platform_type\": \"xinference\", \"api_base_url\": \"http://127.0.0.1:9997/v1\", \"api_key\": \"EMPT\", \"api_concurrencies\": 5, \"llm_models\": [ \"qwen2-7b-langchain\",\"chatglm4-9b-chat\",\"qwen1.5-14b-langchain\" ], \"embed_models\": [ \"bge-embedding-model\" ], \"image_models\": [], \"reranking_models\": [], \"speech2text_models\": [], \"tts_models\": [] }]"

871052165 commented 1 week ago

如果你自定义了模型的uid你需要更改一下在langchain环境下的xinference的默认参数:对应的命令是:chatchat-config model --set_model_platforms "[{ "platform_name": "xinference", "platform_type": "xinference", "api_base_url": "http://127.0.0.1:9997/v1", "api_key": "EMPT", "api_concurrencies": 5, "llm_models": [ "qwen2-7b-langchain","chatglm4-9b-chat","qwen1.5-14b-langchain" ], "embed_models": [ "bge-embedding-model" ], "image_models": [], "reranking_models": [], "speech2text_models": [], "tts_models": [] }]"

按照你的设置也不对,报错如下:(langchain0.3.0) PS H:> chatchat-config model --set_model_platforms "[{

"platform_name": "xinference", "platform_type": "xinference", "api_base_url": "http://127.0.0.1:9997/v1", "api_key": "EMPT", "api_concurrencies": 5, "llm_models": [ "qwen2-7b-langchain","chatglm4-9b-chat","qwen1.5-14b-langchain" ], "embed_models": [ "bge-embedding-model" ], "image_models": [], "reranking_models": [], "speech2text_models": [], "tts_models": [] }]" Usage: chatchat-config model [OPTIONS] Try 'chatchat-config model --help' for help.

Error: Got unexpected extra argument (platform_name: xinference, platform_type: xinference, api_base_url: http://127.0.0.1:9997/v1, api_key: EMPT, api_concurrencies: 5, llm_models: [ qwen2-7b-langchain,chatglm4-9b-chat,qwen1.5-14b-langchain ], embed_models: [ bge-embedding-model ], image_models: [], reranking_models: [], speech2text_models: [], tts_models: [] }])

zhaozhizhuo commented 1 week ago

你的llm_models跟我设置的uid一样?你需要换成你自己的id,我是挂载了三个模型,如果你只有一个模型,你需要删除掉哪些跟你没有关系的参数

misaka100001 commented 1 week ago

如果你自定义了模型的uid你需要更改一下在langchain环境下的xinference的默认参数:对应的命令是:chatchat-config model --set_model_platforms "[{ "platform_name": "xinference", "platform_type": "xinference", "api_base_url": "http://127.0.0.1:9997/v1", "api_key": "EMPT", "api_concurrencies": 5, "llm_models": [ "qwen2-7b-langchain","chatglm4-9b-chat","qwen1.5-14b-langchain" ], "embed_models": [ "bge-embedding-model" ], "image_models": [], "reranking_models": [], "speech2text_models": [], "tts_models": [] }]"

这个配置模型平台的命令应该放在哪边执行啊?在cmd命令行里似乎无法执行吧

zhaozhizhuo commented 1 week ago

这个是在你安装chat模型的环境里边运行,我是linux系统

misaka100001 commented 1 week ago

这个是在你安装chat模型的环境里边运行,我是linux系统

那在windows系统中无法修改配置吗?我现在执行chatchat-kb -r会报错说向量库sample加载失败,是不是因为我没有修改配置的原因啊?

zhaozhizhuo commented 1 week ago

我也不清楚win系统是什么样的,如果你在加载模型的json文件的时候更改了模型的uid,感觉你需要想办法改一下你环境里边的配置

misaka100001 commented 1 week ago

我也不清楚win系统是什么样的,如果你在加载模型的json文件的时候更改了模型的uid,感觉你需要想办法改一下你环境里边的配置

额,加载模型的json文件是哪一步啊,我就是按照readme里面执行的,就是到修改配置这一步卡住了

zhaozhizhuo commented 1 week ago

你没有用xinference挂载模型?xinference register --model-type LLM --file Qwen1.5-7B-Chat.json --persis

misaka100001 commented 1 week ago

你没有用xinference挂载模型?xinference register --model-type LLM --file Qwen1.5-7B-Chat.json --persis

用了啊,xinference我是按照https://blog.csdn.net/python123456_/article/details/140065474 这篇帖子里面来配置的,Language Models用的chatglm3,Embedding Models用的bge-large-zh-v1.5

misaka100001 commented 1 week ago

你没有用xinference挂载模型?xinference register --model-type LLM --file Qwen1.5-7B-Chat.json --persis

我试着直接修改anaconda虚拟环境中chatchat\configs_model_config.py文件, 修改了以下代码:

创建一个全局的共享字典

    self.MODEL_PLATFORMS = [
        {
            "platform_name": "oneapi",
            "platform_type": "oneapi",
            "api_base_url": "http://127.0.0.1:3000/v1",
            "api_key": "sk-",
            "api_concurrencies": 5,
            "llm_models": [
                # 智谱 API
                "chatglm_pro",
                "chatglm_turbo",
                "chatglm_std",
                "chatglm_lite",
                # 千问 API
                "qwen-turbo",
                "qwen-plus",
                "qwen-max",
                "qwen-max-longcontext",
                # 千帆 API
                "ERNIE-Bot",
                "ERNIE-Bot-turbo",
                "ERNIE-Bot-4",
                # 星火 API
                "SparkDesk",
            ],
            "embed_models": [
                # 千问 API
                "text-embedding-v1",
                # 千帆 API
                "Embedding-V1",
            ],
            "image_models": [],
            "reranking_models": [],
            "speech2text_models": [],
            "tts_models": [],
        },
        {
            "platform_name": "xinference",
            "platform_type": "xinference",
            "api_base_url": "http://127.0.0.1:9997/v1",
            "api_key": "EMPT",
            "api_concurrencies": 5,
            "llm_models": [
                "chatglm3",
            ],
            "embed_models": [
                "bge-large-zh-v1.5",
            ],
            "image_models": [],
            "reranking_models": [],
            "speech2text_models": [],
            "tts_models": [],
        },
    ]

我感觉这段代码似乎就是修改xinference参数的,但是修改完之后执行初始化知识库时依然会报错说向量库sample加载失败

liunux4odoo commented 1 week ago

0.3.1 版已经发布,优化了配置方式,修改配置项无需重启服务器,可以更新尝试。