From f2af82058f4904b20ae95c6d17d2b65666bf882a Mon Sep 17 00:00:00 2001 From: ggeutzzang Date: Mon, 27 Nov 2023 11:21:13 +0900 Subject: [PATCH] DOCS: Fix Sample Code for Compatibility with Pydantic 2.0 (#13890) - **Description:** I encountered an issue while running the existing sample code on the page https://python.langchain.com/docs/modules/agents/how_to/agent_iter in an environment with Pydantic 2.0 installed. The following error was triggered: ```python ValidationError Traceback (most recent call last) in () 41 42 tools = [ ---> 43 Tool( 44 name="GetPrime", 45 func=get_prime, 2 frames /usr/local/lib/python3.10/dist-packages/pydantic/v1/main.py in __init__(__pydantic_self__, **data) 339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data) 340 if validation_error: --> 341 raise validation_error 342 try: 343 object_setattr(__pydantic_self__, '__dict__', values) ValidationError: 1 validation error for Tool args_schema subclass of BaseModel expected (type=type_error.subclass; expected_class=BaseModel) ``` I have made modifications to the example code to ensure it functions correctly in environments with Pydantic 2.0. --- docs/docs/modules/agents/how_to/agent_iter.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/modules/agents/how_to/agent_iter.ipynb b/docs/docs/modules/agents/how_to/agent_iter.ipynb index 618ed17e1e8..d1f7fe0fce5 100644 --- a/docs/docs/modules/agents/how_to/agent_iter.ipynb +++ b/docs/docs/modules/agents/how_to/agent_iter.ipynb @@ -22,7 +22,7 @@ "metadata": {}, "outputs": [], "source": [ - "import pydantic\n", + "from pydantic.v1 import BaseModel, Field\n", "from langchain.agents import AgentType, initialize_agent\n", "from langchain.agents.tools import Tool\n", "from langchain.chains import LLMMathChain\n", @@ -65,12 +65,12 @@ "primes = {998: 7901, 999: 7907, 1000: 7919}\n", "\n", "\n", - "class CalculatorInput(pydantic.BaseModel):\n", - " question: str = pydantic.Field()\n", + "class CalculatorInput(BaseModel):\n", + " question: str = Field()\n", "\n", "\n", - "class PrimeInput(pydantic.BaseModel):\n", - " n: int = pydantic.Field()\n", + "class PrimeInput(BaseModel):\n", + " n: int = Field()\n", "\n", "\n", "def is_prime(n: int) -> bool:\n",