Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

[BUG] pydantic.v1.error_wrappers.ValidationError: 1 validation error for Tool

Open XksA-me opened this issue 10 months ago • 3 comments

启动运行:

python startup.py -a

出错:

2024-04-12 10:08:16,837 - startup.py[line:655] - INFO: 正在启动服务:
2024-04-12 10:08:16,837 - startup.py[line:656] - INFO: 如需查看 llm_api 日志,请前往 /Langchain-Chatchat/logs
/root/miniconda3/envs/myconda/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: 模型启动功能将于 Langchain-Chatchat 0.3.x重写,支持更多模式和加速启动,0.2.x中相关功能将废弃
  warn_deprecated(
2024-04-12 10:08:25 | INFO | model_worker | Register to controller
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Started server process [1431]
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Waiting for application startup.
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Application startup complete.
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Uvicorn running on http://0.0.0.0:20000 (Press CTRL+C to quit)
2024-04-12 10:08:26 | INFO | model_worker | Loading the model ['chatglm3-6b'] on worker c5aa7426 ...
Loading checkpoint shards:   0%|                                                                                                      | 0/7 [00:00<?, ?it/s]
2024-04-12 10:08:27 | ERROR | stderr | /root/miniconda3/envs/myconda/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()
2024-04-12 10:08:27 | ERROR | stderr |   return self.fget.__get__(instance, owner)()
Loading checkpoint shards:  14%|█████████████▍                                                                                | 1/7 [00:00<00:02,  2.90it/s]
Loading checkpoint shards:  29%|██████████████████████████▊                                                                   | 2/7 [00:00<00:01,  2.82it/s]
Loading checkpoint shards:  43%|████████████████████████████████████████▎                                                     | 3/7 [00:01<00:01,  2.77it/s]
Loading checkpoint shards:  57%|█████████████████████████████████████████████████████▋                                        | 4/7 [00:01<00:01,  2.83it/s]
Loading checkpoint shards:  71%|███████████████████████████████████████████████████████████████████▏                          | 5/7 [00:01<00:00,  2.63it/s]
Loading checkpoint shards:  86%|████████████████████████████████████████████████████████████████████████████████▌             | 6/7 [00:02<00:00,  2.60it/s]
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00,  2.86it/s]
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:02<00:00,  2.78it/s]
2024-04-12 10:08:29 | ERROR | stderr | 
2024-04-12 10:08:33 | INFO | model_worker | Register to controller
Process API Server:
Traceback (most recent call last):
  File "/root/miniconda3/envs/myconda/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/root/miniconda3/envs/myconda/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Langchain-Chatchat/startup.py", line 438, in run_api_server
    app = create_app(run_mode=run_mode)
  File "/Langchain-Chatchat/server/api.py", line 51, in create_app
    mount_app_routes(app, run_mode=run_mode)
  File "/Langchain-Chatchat/server/api.py", line 77, in mount_app_routes
    mount_knowledge_routes(app)
  File "/Langchain-Chatchat/server/api.py", line 142, in mount_knowledge_routes
    from server.chat.agent_chat import agent_chat
  File "/Langchain-Chatchat/server/chat/agent_chat.py", line 16, in <module>
    from server.agent.tools_select import tools, tool_names
  File "/Langchain-Chatchat/server/agent/tools_select.py", line 5, in <module>
    Tool.from_function(
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/langchain_core/tools.py", line 624, in from_function
    return cls(
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/langchain_core/tools.py", line 604, in __init__
    super(Tool, self).__init__(
  File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/langchain_core/load/serializable.py", line 107, in __init__
    super().__init__(**kwargs)
  File "/root/miniconda3/envs/myconda/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 Tool
args_schema
  subclass of BaseModel expected (type=type_error.subclass; expected_class=BaseModel)

想问两个问题: 1、这些 log ERROR 是什么含义,之前启动成功的时候也有这个

2024-04-12 10:08:25 | ERROR | stderr | INFO:     Started server process [1431]
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Waiting for application startup.
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Application startup complete.
2024-04-12 10:08:25 | ERROR | stderr | INFO:     Uvicorn running on http://0.0.0.0:20000 (Press CTRL+C to quit)

2、有时候会遇到pydantic.v1.error_wrappers.ValidationError: 1 validation error for Tool 看其他issue 卸载重装 pydantic 后有一次好了,后面启动有出错了

我的系统信息:

Ubuntu 20.04
Python 3.10.12

部分包版本:
pydantic                      1.10.13
pydantic_core                 2.16.3
langchain                     0.0.354
langchain-community           0.0.20
langchain-core                0.1.23
langchain-experimental        0.0.47
langcodes                     3.3.0
langdetect                    1.0.9
langsmith                     0.0.87
torch                         2.1.2+cu118
torchaudio                    2.1.2+cu118
torchvision                   0.16.2+cu118

XksA-me avatar Apr 12 '24 10:04 XksA-me

The issues you're encountering can be addressed as follows:

  1. Log Errors Showing as ERROR for Informational Messages: This might be due to the log level being set incorrectly in your application. Ensure the log level is set appropriately in your configuration. For instance, setting logger.setLevel(logging.INFO) should display informational messages correctly without marking them as errors. Adjusting the log level in your configs/basic_config.py.example or wherever your logging configuration is defined should resolve this. More details on Python's logging levels can be found in the Python documentation.

  2. pydantic.v1.error_wrappers.ValidationError: This error typically indicates a mismatch between expected and provided data structures, particularly with Pydantic models. The error message suggests that args_schema expects a subclass of BaseModel, which means wherever you're defining or using args_schema, you need to ensure it's correctly implemented as a Pydantic model. For example, if you're validating inputs or configurations, define a Pydantic model that matches the expected structure and validate your inputs against this model:

from pydantic import BaseModel, ValidationError

class ArgsSchema(BaseModel):
    # Define expected fields and types
    host: str
    port: int
    model_names: List[str]
    # Add other fields as needed

try:
    validated_args = ArgsSchema(**kwargs)  # Assuming kwargs is what you're validating
except ValidationError as e:
    print("Validation error:", e.json())

This ensures your inputs adhere to the expected schema, preventing ValidationError.

If you've previously resolved a similar issue by reinstalling pydantic, it might be worth trying again. However, if the problem persists, consider experimenting with different versions of pydantic to find one that doesn't produce this error.

Let me know if you need further assistance or clarification on these solutions!

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 12 '24 10:04 dosubot[bot]

注释掉 server/api.py 第 142、158-160 行代码后我的问题解决了(agent chat 相关代码) image

XksA-me avatar Apr 19 '24 09:04 XksA-me

这个问题已经被标记为 stale ,因为它已经超过 30 天没有任何活动。

github-actions[bot] avatar May 19 '24 21:05 github-actions[bot]

这个问题已经被自动关闭,因为它被标为 stale 后超过 14 天没有任何活动。

github-actions[bot] avatar Jun 03 '24 21:06 github-actions[bot]