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
31.16k stars 5.44k forks source link

【bug】使用ollama,对话报错openai.InternalServerError: Internal Server Error #4494

Closed hzk866 closed 1 month ago

hzk866 commented 2 months ago

问题描述 / Problem Description 使用ollama qwen2:7b,对话后报错openai.InternalServerError: Internal Server Error。

配置信息一 \chatchat\configs_model_config.py

import logging
import os
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Dict, List, Optional

sys.path.append(str(Path(__file__).parent))
import _core_config as core_config

logger = logging.getLogger()

class ConfigModel(core_config.Config):
    DEFAULT_LLM_MODEL: Optional[str] = "qwen2:7b"
    """默认选用的 LLM 名称"""
    DEFAULT_EMBEDDING_MODEL: Optional[str] = "quentinz/bge-large-zh-v1.5:latest"
    """默认选用的 Embedding 名称"""
    Agent_MODEL: Optional[str] = None
    """AgentLM模型的名称 (可以不指定,指定之后就锁定进入Agent之后的Chain的模型,不指定就是LLM_MODELS[0])"""
    HISTORY_LEN: Optional[int] = None
    """历史对话轮数"""
    MAX_TOKENS: Optional[int] = None
    """大模型最长支持的长度,如果不填写,则使用模型默认的最大长度,如果填写,则为用户设定的最大长度"""
    TEMPERATURE: Optional[float] = None
    """LLM通用对话参数"""
    SUPPORT_AGENT_MODELS: Optional[List[str]] = None
    """支持的Agent模型"""
    LLM_MODEL_CONFIG: Optional[Dict[str, Dict[str, Any]]] = None
    """LLM模型配置,包括了不同模态初始化参数"""
    MODEL_PLATFORMS: Optional[List[Dict[str, Any]]] = None
    """模型平台配置"""
    TOOL_CONFIG: Optional[Dict[str, Any]] = None
    """工具配置项"""

    @classmethod
    def class_name(cls) -> str:
        return cls.__name__

    def __str__(self):
        return self.to_json()

@dataclass
class ConfigModelFactory(core_config.ConfigFactory[ConfigModel]):
    """ConfigModel工厂类"""

    def __init__(self):
        # 默认选用的 LLM 名称
        self.DEFAULT_LLM_MODEL = "qwen2:7b"

        # 默认选用的 Embedding 名称
        self.DEFAULT_EMBEDDING_MODEL = "quentinz/bge-large-zh-v1.5:latest"

        # AgentLM模型的名称 (可以不指定,指定之后就锁定进入Agent之后的Chain的模型,不指定就是LLM_MODELS[0])
        self.Agent_MODEL = None

        # 历史对话轮数
        self.HISTORY_LEN = 3

        # 大模型最长支持的长度,如果不填写,则使用模型默认的最大长度,如果填写,则为用户设定的最大长度
        self.MAX_TOKENS = None

        # LLM通用对话参数
        self.TEMPERATURE = 0.7
        # TOP_P = 0.95 # ChatOpenAI暂不支持该参数

        self.SUPPORT_AGENT_MODELS = [
            "qwen2:7b",
        ]

        #   ### 如果您已经有了一个openai endpoint的能力的地址,可以在这里直接配置
        #   - platform_name 可以任意填写,不要重复即可
        #   - platform_type 以后可能根据平台类型做一些功能区分,与platform_name一致即可
        #   - 将框架部署的模型填写到对应列表即可。不同框架可以加载同名模型,项目会自动做负载均衡。

        # 创建一个全局的共享字典
        self.MODEL_PLATFORMS = [
            {
                "platform_name": "ollama",
                "platform_type": "ollama",
                "api_base_url": "http://127.0.0.1:11434/v1",
                "api_key": "sk",
                "api_concurrencies": 5,
                "llm_models": [
                    "qwen2:7b",
                ],
                "embed_models": [
                    "quentinz/bge-large-zh-v1.5:latest",
                ],
                "image_models": [],
                "reranking_models": [],
                "speech2text_models": [],
                "tts_models": [],
            },
        ]
        # 工具配置项
        self.TOOL_CONFIG = {
            "search_local_knowledgebase": {
                "use": False,
                "top_k": 3,
                "score_threshold": 1.0,
                "conclude_prompt": {
                    "with_result": '<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 "根据已知信息无法回答该问题",'
                    "不允许在答案中添加编造成分,答案请使用中文。 </指令>\n"
                    "<已知信息>{{ context }}</已知信息>\n"
                    "<问题>{{ question }}</问题>\n",
                    "without_result": "请你根据我的提问回答我的问题:\n"
                    "{{ question }}\n"
                    "请注意,你必须在回答结束后强调,你的回答是根据你的经验回答而不是参考资料回答的。\n",
                },
            },
            "search_internet": {
                "use": False,
                "search_engine_name": "bing",
                "search_engine_config": {
                    "bing": {
                        "result_len": 3,
                        "bing_search_url": "https://api.bing.microsoft.com/v7.0/search",
                        "bing_key": "",
                    },
                    "metaphor": {
                        "result_len": 3,
                        "metaphor_api_key": "",
                        "split_result": False,
                        "chunk_size": 500,
                        "chunk_overlap": 0,
                    },
                    "duckduckgo": {"result_len": 3},
                },
                "top_k": 10,
                "verbose": "Origin",
                "conclude_prompt": "<指令>这是搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题。如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。 "
                "</指令>\n<已知信息>{{ context }}</已知信息>\n"
                "<问题>\n"
                "{{ question }}\n"
                "</问题>\n",
            },
            "arxiv": {
                "use": True,
            },
            "shell": {
                "use": True,
            },
            "weather_check": {
                "use": True,
                "api_key":"SUdWyvDuoxNN5Zp5W",
            },
            "search_youtube": {
                "use": False,
            },
            "wolfram": {
                "use": False,
                "appid": "",
            },
            "calculate": {
                "use": True,
            },
            "vqa_processor": {
                "use": False,
                "model_path": "your model path",
                "tokenizer_path": "your tokenizer path",
                "device": "cuda:1",
            },
            "aqa_processor": {
                "use": False,
                "model_path": "your model path",
                "tokenizer_path": "yout tokenizer path",
                "device": "cuda:2",
            },
            "text2images": {
                "use": False,
                "model": "sd-turbo",
                "size": "256*256",
            },
            # text2sql使用建议
            # 1、因大模型生成的sql可能与预期有偏差,请务必在测试环境中进行充分测试、评估;
            # 2、生产环境中,对于查询操作,由于不确定查询效率,推荐数据库采用主从数据库架构,让text2sql连接从数据库,防止可能的慢查询影响主业务;
            # 3、对于写操作应保持谨慎,如不需要写操作,设置read_only为True,最好再从数据库层面收回数据库用户的写权限,防止用户通过自然语言对数据库进行修改操作;
            # 4、text2sql与大模型在意图理解、sql转换等方面的能力有关,可切换不同大模型进行测试;
            # 5、数据库表名、字段名应与其实际作用保持一致、容易理解,且应对数据库表名、字段进行详细的备注说明,帮助大模型更好理解数据库结构;
            # 6、若现有数据库表名难于让大模型理解,可配置下面table_comments字段,补充说明某些表的作用。
            "text2sql": {
                "use": False,
                # SQLAlchemy连接字符串,支持的数据库有:
                # crate、duckdb、googlesql、mssql、mysql、mariadb、oracle、postgresql、sqlite、clickhouse、prestodb
                # 不同的数据库请查询SQLAlchemy,修改sqlalchemy_connect_str,配置对应的数据库连接,如sqlite为sqlite:///数据库文件路径,下面示例为mysql
                # 如提示缺少对应数据库的驱动,请自行通过poetry安装
                "sqlalchemy_connect_str": "mysql+pymysql://用户名:密码@主机地址/数据库名称e",
                # 务必评估是否需要开启read_only,开启后会对sql语句进行检查,请确认text2sql.py中的intercept_sql拦截器是否满足你使用的数据库只读要求
                # 优先推荐从数据库层面对用户权限进行限制
                "read_only": False,
                # 限定返回的行数
                "top_k": 50,
                # 是否返回中间步骤
                "return_intermediate_steps": True,
                # 如果想指定特定表,请填写表名称,如["sys_user","sys_dept"],不填写走智能判断应该使用哪些表
                "table_names": [],
                # 对表名进行额外说明,辅助大模型更好的判断应该使用哪些表,尤其是SQLDatabaseSequentialChain模式下,是根据表名做的预测,很容易误判。
                "table_comments": {
                    # 如果出现大模型选错表的情况,可尝试根据实际情况填写表名和说明
                    # "tableA":"这是一个用户表,存储了用户的基本信息",
                    # "tanleB":"角色表",
                },
            },
        }
        self._init_llm_work_config()

    def _init_llm_work_config(self):
        """初始化知识库runtime的一些配置"""

        self.LLM_MODEL_CONFIG = {
            # 意图识别不需要输出,模型后台知道就行
            "preprocess_model": {
                self.DEFAULT_LLM_MODEL: {
                    "temperature": 0.05,
                    "max_tokens": 4096,
                    "history_len": 100,
                    "prompt_name": "default",
                    "callbacks": False,
                },
            },
            "llm_model": {
                self.DEFAULT_LLM_MODEL: {
                    "temperature": 0.9,
                    "max_tokens": 4096,
                    "history_len": 10,
                    "prompt_name": "default",
                    "callbacks": True,
                },
            },
            "action_model": {
                self.DEFAULT_LLM_MODEL: {
                    "temperature": 0.01,
                    "max_tokens": 4096,
                    "prompt_name": "ChatGLM3",
                    "callbacks": True,
                },
            },
            "postprocess_model": {
                self.DEFAULT_LLM_MODEL: {
                    "temperature": 0.01,
                    "max_tokens": 4096,
                    "prompt_name": "default",
                    "callbacks": True,
                }
            },
            "image_model": {
                "sd-turbo": {
                    "size": "256*256",
                }
            },
        }

    def default_llm_model(self, llm_model: str):
        self.DEFAULT_LLM_MODEL = llm_model

    def default_embedding_model(self, embedding_model: str):
        self.DEFAULT_EMBEDDING_MODEL = embedding_model

    def agent_model(self, agent_model: str):
        self.Agent_MODEL = agent_model

    def history_len(self, history_len: int):
        self.HISTORY_LEN = history_len

    def max_tokens(self, max_tokens: int):
        self.MAX_TOKENS = max_tokens

    def temperature(self, temperature: float):
        self.TEMPERATURE = temperature

    def support_agent_models(self, support_agent_models: List[str]):
        self.SUPPORT_AGENT_MODELS = support_agent_models

    def model_platforms(self, model_platforms: List[Dict[str, Any]]):
        self.MODEL_PLATFORMS = model_platforms

    def tool_config(self, tool_config: Dict[str, Any]):
        self.TOOL_CONFIG = tool_config

    def get_config(self) -> ConfigModel:
        config = ConfigModel()
        config.DEFAULT_LLM_MODEL = self.DEFAULT_LLM_MODEL
        config.DEFAULT_EMBEDDING_MODEL = self.DEFAULT_EMBEDDING_MODEL
        config.Agent_MODEL = self.Agent_MODEL
        config.HISTORY_LEN = self.HISTORY_LEN
        config.MAX_TOKENS = self.MAX_TOKENS
        config.TEMPERATURE = self.TEMPERATURE
        config.SUPPORT_AGENT_MODELS = self.SUPPORT_AGENT_MODELS
        config.LLM_MODEL_CONFIG = self.LLM_MODEL_CONFIG
        config.MODEL_PLATFORMS = self.MODEL_PLATFORMS
        config.TOOL_CONFIG = self.TOOL_CONFIG

        return config

class ConfigModelWorkSpace(
    core_config.ConfigWorkSpace[ConfigModelFactory, ConfigModel]
):
    """
    工作空间的配置预设, 提供ConfigModel建造方法产生实例。
    """

    config_factory_cls = ConfigModelFactory

    def __init__(self):
        super().__init__()

    def _build_config_factory(self, config_json: Any) -> ConfigModelFactory:
        _config_factory = self.config_factory_cls()
        if config_json.get("DEFAULT_LLM_MODEL"):
            _config_factory.default_llm_model(config_json.get("DEFAULT_LLM_MODEL"))
        if config_json.get("DEFAULT_EMBEDDING_MODEL"):
            _config_factory.default_embedding_model(
                config_json.get("DEFAULT_EMBEDDING_MODEL")
            )
        if config_json.get("Agent_MODEL"):
            _config_factory.agent_model(config_json.get("Agent_MODEL"))
        if config_json.get("HISTORY_LEN"):
            _config_factory.history_len(config_json.get("HISTORY_LEN"))
        if config_json.get("MAX_TOKENS"):
            _config_factory.max_tokens(config_json.get("MAX_TOKENS"))
        if config_json.get("TEMPERATURE"):
            _config_factory.temperature(config_json.get("TEMPERATURE"))
        if config_json.get("SUPPORT_AGENT_MODELS"):
            _config_factory.support_agent_models(
                config_json.get("SUPPORT_AGENT_MODELS")
            )
        if config_json.get("MODEL_PLATFORMS"):
            _config_factory.model_platforms(config_json.get("MODEL_PLATFORMS"))
        if config_json.get("TOOL_CONFIG"):
            _config_factory.tool_config(config_json.get("TOOL_CONFIG"))

        return _config_factory

    @classmethod
    def get_type(cls) -> str:
        return ConfigModel.class_name()

    def get_config(self) -> ConfigModel:
        return self._config_factory.get_config()

    def set_default_llm_model(self, llm_model: str):
        self._config_factory.default_llm_model(llm_model)
        self.store_config()

    def set_default_embedding_model(self, embedding_model: str):
        self._config_factory.default_embedding_model(embedding_model)
        self.store_config()

    def set_agent_model(self, agent_model: str):
        self._config_factory.agent_model(agent_model)
        self.store_config()

    def set_history_len(self, history_len: int):
        self._config_factory.history_len(history_len)
        self.store_config()

    def set_max_tokens(self, max_tokens: int):
        self._config_factory.max_tokens(max_tokens)
        self.store_config()

    def set_temperature(self, temperature: float):
        self._config_factory.temperature(temperature)
        self.store_config()

    def set_support_agent_models(self, support_agent_models: List[str]):
        self._config_factory.support_agent_models(support_agent_models)
        self.store_config()

    def set_model_platforms(self, model_platforms: List[Dict[str, Any]]):
        self._config_factory.model_platforms(model_platforms=model_platforms)
        self.store_config()

    def set_tool_config(self, tool_config: Dict[str, Any]):
        self._config_factory.tool_config(tool_config=tool_config)
        self.store_config()

config_model_workspace: ConfigModelWorkSpace = ConfigModelWorkSpace()

配置信息二 \chatchat\configs\model_providers.yaml

ollama:
  model_credential:
    - model: 'qwen2:7b'
      model_type: 'llm'
      model_credentials:
        base_url: 'http://127.0.0.1:11434'

环境信息 / Environment Information

实际结果 / Actual Result image

完整报错信息

INFO:     127.0.0.1:51724 - "POST /chat/chat/completions HTTP/1.1" 500 Internal Server Error
2024-07-13 12:02:11,517 httpx        11788 INFO     HTTP Request: POST http://127.0.0.1:7861/chat/chat/completions "HTTP/1.1 500 Internal Server Error"
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\fastapi\applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\middleware\errors.py", line 186, in __call__
    raise exc
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\middleware\errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\middleware\cors.py", line 83, in __call__
    await self.app(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\middleware\exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\starlette\routing.py", line 74, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\fastapi\routing.py", line 299, in app
    raise e
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\fastapi\routing.py", line 294, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\fastapi\routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\server\api_server\chat_routes.py", line 58, in chat_completions
    client = get_OpenAIClient(model_name=body.model, is_async=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\server\utils.py", line 295, in get_OpenAIClient
    assert platform_info, f"cannot find configured platform: {platform_name}"
           ^^^^^^^^^^^^^
AssertionError: cannot find configured platform: None
2024-07-13 12:02:11.521 Uncaught app exception
Traceback (most recent call last):
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\webui.py", line 69, in <module>
    dialogue_page(api=api, is_lite=is_lite)
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\webui_pages\dialogue\dialogue.py", line 361, in dialogue_page
    for d in client.chat.completions.create(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\resources\chat\completions.py", line 581, in create
    return self._post(
           ^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 1233, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 922, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 998, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 1046, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 998, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 1046, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\openai\_base_client.py", line 1013, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.InternalServerError: Internal Server Error
liunux4odoo commented 2 months ago

AssertionError: cannot find configured platform: None

你请求的模型在 MODEL_PLATFORMS 里没有正确配置。0.3.0版本改代码里的值不一定好使,你要去看看 ~/.chatchat 下面的 json 文件里是什么样的配置。

hzk866 commented 1 month ago

十分感谢!~/.chatchat 下面的 json 文件确实没有修改,调整完之后可以正常调用了。

AssertionError:找不到配置的平台:无

你请求的模型在 MODEL_PLATFORMS 里没有正确配置。0.3.0版本改代码里的值不一定好使,你要去看看 ~/.chatchat 下面的 json 文件里是什么样的配置。

UtOpiiAa commented 1 month ago

你好我也遇到了相同的问题,请问需要修改json文件的哪些内呀

hzk866 commented 1 month ago

你好我也遇到了相同的问题,请问需要修改json文件的哪些内呀

修改了上方"DEFAULT_LLM_MODEL": "qwen2:7b","DEFAULT_EMBEDDING_MODEL": "quentinz/bge-large-zh-v1.5"

以及下方MODELPLATFORMS中的配置,可以对话正常。但目前本地知识库问答使用Embedding 模型这边又出现了问题…… ><

"MODEL_PLATFORMS": [
                {
                    "platform_name": "ollama",
                    "platform_type": "ollama",
                    "api_base_url": "http://127.0.0.1:11434/v1",
                    "api_key": "EMPT",
                    "api_concurrencies": 5,
                    "llm_models": [
            "qwen2:7b"
                    ],
                    "embed_models": [
            "quentinz/bge-large-zh-v1.5"
                    ],
                    "image_models": [],
                    "reranking_models": [],
                    "speech2text_models": [],
                    "tts_models": []
                }
            ],
hzk866 commented 1 month ago

使用本地知识库问答会报以下错误。

2024-07-15 11:29:21,223 root         11960 ERROR    failed to create Embeddings for model: bge-large-zh-v1.5.
Traceback (most recent call last):
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\server\utils.py", line 258, in get_Embeddings
    return LocalAIEmbeddings(**params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\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-15 11:29:21,225 root         11960 ERROR    failed to access embed model 'bge-large-zh-v1.5': 'NoneType' object has no attribute 'embed_query'
Traceback (most recent call last):
  File "E:\Langchain-Chatchat2\Langchain-Chatchat\Chatchat\env\Lib\site-packages\chatchat\server\utils.py", line 268, in check_embed_model
    embeddings.embed_query("this is a test")
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'embed_query'
2024-07-15 11:29:21,226 root         11960 ERROR    could not search docs because failed to access embed model.
NoneType: None