From c62772885a30879ec9c594b8f6c51bcc42421c32 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:06:58 -0700 Subject: [PATCH] docs: migrate pydantic imports (#26266) --- docs/docs/concepts.mdx | 4 +-- docs/docs/how_to/MultiQueryRetriever.ipynb | 2 +- .../how_to/chat_models_universal_init.ipynb | 2 +- .../how_to/chat_token_usage_tracking.ipynb | 2 +- .../how_to/convert_runnable_to_tool.ipynb | 2 +- docs/docs/how_to/custom_tools.ipynb | 6 ++--- docs/docs/how_to/extraction_examples.ipynb | 4 +-- docs/docs/how_to/extraction_long_text.ipynb | 2 +- docs/docs/how_to/extraction_parse.ipynb | 4 +-- docs/docs/how_to/function_calling.ipynb | 2 +- docs/docs/how_to/graph_mapping.ipynb | 2 +- docs/docs/how_to/graph_semantic.ipynb | 10 ++++--- docs/docs/how_to/multi_vector.ipynb | 2 +- docs/docs/how_to/output_parser_fixing.ipynb | 4 +-- docs/docs/how_to/output_parser_json.ipynb | 2 +- docs/docs/how_to/output_parser_retry.ipynb | 4 +-- .../how_to/output_parser_structured.ipynb | 24 +++++++++-------- docs/docs/how_to/output_parser_yaml.ipynb | 2 +- docs/docs/how_to/qa_citations.ipynb | 2 +- .../how_to/query_constructing_filters.ipynb | 2 +- docs/docs/how_to/query_few_shot.ipynb | 2 +- docs/docs/how_to/query_high_cardinality.ipynb | 27 ++++++++++--------- docs/docs/how_to/query_multiple_queries.ipynb | 2 +- .../how_to/query_multiple_retrievers.ipynb | 2 +- docs/docs/how_to/query_no_queries.ipynb | 2 +- docs/docs/how_to/sql_large_db.ipynb | 2 +- docs/docs/how_to/structured_output.ipynb | 6 ++--- docs/docs/how_to/tool_calling.ipynb | 4 +-- docs/docs/how_to/tool_runtime.ipynb | 2 +- docs/docs/how_to/tools_builtin.ipynb | 2 +- docs/docs/integrations/chat/anthropic.ipynb | 2 +- .../chat/anthropic_functions.ipynb | 2 +- docs/docs/integrations/chat/deepinfra.ipynb | 2 +- docs/docs/integrations/chat/edenai.ipynb | 2 +- docs/docs/integrations/chat/ibm_watsonx.ipynb | 2 +- docs/docs/integrations/chat/llamacpp.ipynb | 4 +-- .../chat/nvidia_ai_endpoints.ipynb | 2 +- docs/docs/integrations/chat/premai.ipynb | 2 +- .../chat_loaders/langsmith_llm_runs.ipynb | 4 +-- docs/docs/integrations/providers/premai.md | 2 +- docs/docs/integrations/tools/infobip.ipynb | 2 +- docs/docs/tutorials/classification.ipynb | 2 +- docs/docs/tutorials/data_generation.ipynb | 4 +-- docs/docs/tutorials/extraction.ipynb | 6 ++--- docs/docs/tutorials/query_analysis.ipynb | 2 +- 45 files changed, 91 insertions(+), 84 deletions(-) diff --git a/docs/docs/concepts.mdx b/docs/docs/concepts.mdx index af2ac5fbb59..0c5987229e2 100644 --- a/docs/docs/concepts.mdx +++ b/docs/docs/concepts.mdx @@ -945,7 +945,7 @@ Here's an example: ```python from typing import Optional -from langchain_core.pydantic_v1 import BaseModel, Field +from pydantic import BaseModel, Field class Joke(BaseModel): @@ -1062,7 +1062,7 @@ a `tool_calls` field containing `args` that match the desired shape. There are several acceptable formats you can use to bind tools to a model in LangChain. Here's one example: ```python -from langchain_core.pydantic_v1 import BaseModel, Field +from pydantic import BaseModel, Field from langchain_openai import ChatOpenAI class ResponseFormatter(BaseModel): diff --git a/docs/docs/how_to/MultiQueryRetriever.ipynb b/docs/docs/how_to/MultiQueryRetriever.ipynb index 6a0abf20f1c..e30ff4e285a 100644 --- a/docs/docs/how_to/MultiQueryRetriever.ipynb +++ b/docs/docs/how_to/MultiQueryRetriever.ipynb @@ -144,7 +144,7 @@ "\n", "from langchain_core.output_parsers import BaseOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "# Output parser will split the LLM result into a list of queries\n", diff --git a/docs/docs/how_to/chat_models_universal_init.ipynb b/docs/docs/how_to/chat_models_universal_init.ipynb index 71af6a8e02c..d424c773930 100644 --- a/docs/docs/how_to/chat_models_universal_init.ipynb +++ b/docs/docs/how_to/chat_models_universal_init.ipynb @@ -263,7 +263,7 @@ } ], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class GetWeather(BaseModel):\n", diff --git a/docs/docs/how_to/chat_token_usage_tracking.ipynb b/docs/docs/how_to/chat_token_usage_tracking.ipynb index 8ba8b9b9b43..1624ecf3713 100644 --- a/docs/docs/how_to/chat_token_usage_tracking.ipynb +++ b/docs/docs/how_to/chat_token_usage_tracking.ipynb @@ -289,7 +289,7 @@ } ], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Joke(BaseModel):\n", diff --git a/docs/docs/how_to/convert_runnable_to_tool.ipynb b/docs/docs/how_to/convert_runnable_to_tool.ipynb index fa122809874..f087f1b5923 100644 --- a/docs/docs/how_to/convert_runnable_to_tool.ipynb +++ b/docs/docs/how_to/convert_runnable_to_tool.ipynb @@ -190,7 +190,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class GSchema(BaseModel):\n", diff --git a/docs/docs/how_to/custom_tools.ipynb b/docs/docs/how_to/custom_tools.ipynb index 11668c31918..488ff6911b8 100644 --- a/docs/docs/how_to/custom_tools.ipynb +++ b/docs/docs/how_to/custom_tools.ipynb @@ -13,7 +13,7 @@ "|---------------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n", "| name | str | Must be unique within a set of tools provided to an LLM or agent. |\n", "| description | str | Describes what the tool does. Used as context by the LLM or agent. |\n", - "| args_schema | langchain.pydantic_v1.BaseModel | Optional but recommended, and required if using callback handlers. It can be used to provide more information (e.g., few-shot examples) or validation for expected parameters. |\n", + "| args_schema | pydantic.BaseModel | Optional but recommended, and required if using callback handlers. It can be used to provide more information (e.g., few-shot examples) or validation for expected parameters. |\n", "| return_direct | boolean | Only relevant for agents. When True, after invoking the given tool, the agent will stop and return the result direcly to the user. |\n", "\n", "LangChain supports the creation of tools from:\n", @@ -177,7 +177,7 @@ } ], "source": [ - "from langchain.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class CalculatorInput(BaseModel):\n", @@ -435,12 +435,12 @@ "source": [ "from typing import Optional, Type\n", "\n", - "from langchain.pydantic_v1 import BaseModel\n", "from langchain_core.callbacks import (\n", " AsyncCallbackManagerForToolRun,\n", " CallbackManagerForToolRun,\n", ")\n", "from langchain_core.tools import BaseTool\n", + "from pydantic import BaseModel\n", "\n", "\n", "class CalculatorInput(BaseModel):\n", diff --git a/docs/docs/how_to/extraction_examples.ipynb b/docs/docs/how_to/extraction_examples.ipynb index 6d119b83590..9cb3e83ca7a 100644 --- a/docs/docs/how_to/extraction_examples.ipynb +++ b/docs/docs/how_to/extraction_examples.ipynb @@ -111,8 +111,8 @@ "source": [ "from typing import List, Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", @@ -177,7 +177,7 @@ " SystemMessage,\n", " ToolMessage,\n", ")\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Example(TypedDict):\n", diff --git a/docs/docs/how_to/extraction_long_text.ipynb b/docs/docs/how_to/extraction_long_text.ipynb index 97b86ffad8c..d09c5c60e87 100644 --- a/docs/docs/how_to/extraction_long_text.ipynb +++ b/docs/docs/how_to/extraction_long_text.ipynb @@ -93,7 +93,7 @@ "from typing import List, Optional\n", "\n", "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class KeyDevelopment(BaseModel):\n", diff --git a/docs/docs/how_to/extraction_parse.ipynb b/docs/docs/how_to/extraction_parse.ipynb index 351cbf9c316..b678f175edf 100644 --- a/docs/docs/how_to/extraction_parse.ipynb +++ b/docs/docs/how_to/extraction_parse.ipynb @@ -71,7 +71,7 @@ "\n", "from langchain_core.output_parsers import PydanticOutputParser\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field, validator\n", + "from pydantic import BaseModel, Field, validator\n", "\n", "\n", "class Person(BaseModel):\n", @@ -221,7 +221,7 @@ "from langchain_anthropic.chat_models import ChatAnthropic\n", "from langchain_core.messages import AIMessage\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field, validator\n", + "from pydantic import BaseModel, Field, validator\n", "\n", "\n", "class Person(BaseModel):\n", diff --git a/docs/docs/how_to/function_calling.ipynb b/docs/docs/how_to/function_calling.ipynb index b42c119cf14..2b0f485053f 100644 --- a/docs/docs/how_to/function_calling.ipynb +++ b/docs/docs/how_to/function_calling.ipynb @@ -136,7 +136,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "# Note that the docstrings here are crucial, as they will be passed along\n", diff --git a/docs/docs/how_to/graph_mapping.ipynb b/docs/docs/how_to/graph_mapping.ipynb index 688621fa73a..cd98ca00b67 100644 --- a/docs/docs/how_to/graph_mapping.ipynb +++ b/docs/docs/how_to/graph_mapping.ipynb @@ -163,8 +163,8 @@ "from typing import List, Optional\n", "\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n", "\n", diff --git a/docs/docs/how_to/graph_semantic.ipynb b/docs/docs/how_to/graph_semantic.ipynb index 42367e3d333..94578939d7b 100644 --- a/docs/docs/how_to/graph_semantic.ipynb +++ b/docs/docs/how_to/graph_semantic.ipynb @@ -177,14 +177,15 @@ "source": [ "from typing import Optional, Type\n", "\n", - "# Import things that are needed generically\n", - "from langchain.pydantic_v1 import BaseModel, Field\n", "from langchain_core.callbacks import (\n", " AsyncCallbackManagerForToolRun,\n", " CallbackManagerForToolRun,\n", ")\n", "from langchain_core.tools import BaseTool\n", "\n", + "# Import things that are needed generically\n", + "from pydantic import BaseModel, Field\n", + "\n", "description_query = \"\"\"\n", "MATCH (m:Movie|Person)\n", "WHERE m.title CONTAINS $candidate OR m.name CONTAINS $candidate\n", @@ -226,14 +227,15 @@ "source": [ "from typing import Optional, Type\n", "\n", - "# Import things that are needed generically\n", - "from langchain.pydantic_v1 import BaseModel, Field\n", "from langchain_core.callbacks import (\n", " AsyncCallbackManagerForToolRun,\n", " CallbackManagerForToolRun,\n", ")\n", "from langchain_core.tools import BaseTool\n", "\n", + "# Import things that are needed generically\n", + "from pydantic import BaseModel, Field\n", + "\n", "\n", "class InformationInput(BaseModel):\n", " entity: str = Field(description=\"movie or a person mentioned in the question\")\n", diff --git a/docs/docs/how_to/multi_vector.ipynb b/docs/docs/how_to/multi_vector.ipynb index 7e8a86744bf..0ba3ec5c227 100644 --- a/docs/docs/how_to/multi_vector.ipynb +++ b/docs/docs/how_to/multi_vector.ipynb @@ -440,7 +440,7 @@ "source": [ "from typing import List\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class HypotheticalQuestions(BaseModel):\n", diff --git a/docs/docs/how_to/output_parser_fixing.ipynb b/docs/docs/how_to/output_parser_fixing.ipynb index c4875ee91da..a227f6d0698 100644 --- a/docs/docs/how_to/output_parser_fixing.ipynb +++ b/docs/docs/how_to/output_parser_fixing.ipynb @@ -24,8 +24,8 @@ "from typing import List\n", "\n", "from langchain_core.output_parsers import PydanticOutputParser\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", - "from langchain_openai import ChatOpenAI" + "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field" ] }, { diff --git a/docs/docs/how_to/output_parser_json.ipynb b/docs/docs/how_to/output_parser_json.ipynb index cbad65c07b4..718f3b2f70b 100644 --- a/docs/docs/how_to/output_parser_json.ipynb +++ b/docs/docs/how_to/output_parser_json.ipynb @@ -71,8 +71,8 @@ "source": [ "from langchain_core.output_parsers import JsonOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "model = ChatOpenAI(temperature=0)\n", "\n", diff --git a/docs/docs/how_to/output_parser_retry.ipynb b/docs/docs/how_to/output_parser_retry.ipynb index 5e6b5e471f3..2ca4be59c78 100644 --- a/docs/docs/how_to/output_parser_retry.ipynb +++ b/docs/docs/how_to/output_parser_retry.ipynb @@ -20,8 +20,8 @@ "from langchain.output_parsers import OutputFixingParser\n", "from langchain_core.output_parsers import PydanticOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", - "from langchain_openai import ChatOpenAI, OpenAI" + "from langchain_openai import ChatOpenAI, OpenAI\n", + "from pydantic import BaseModel, Field" ] }, { diff --git a/docs/docs/how_to/output_parser_structured.ipynb b/docs/docs/how_to/output_parser_structured.ipynb index edbf8cf21c7..aaff800f954 100644 --- a/docs/docs/how_to/output_parser_structured.ipynb +++ b/docs/docs/how_to/output_parser_structured.ipynb @@ -35,17 +35,17 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "id": "1594b2bf-2a6f-47bb-9a81-38930f8e606b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Joke(setup='Why did the chicken cross the road?', punchline='To get to the other side!')" + "Joke(setup='Why did the tomato turn red?', punchline='Because it saw the salad dressing!')" ] }, - "execution_count": 6, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -53,8 +53,8 @@ "source": [ "from langchain_core.output_parsers import PydanticOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field, validator\n", "from langchain_openai import OpenAI\n", + "from pydantic import BaseModel, Field, model_validator\n", "\n", "model = OpenAI(model_name=\"gpt-3.5-turbo-instruct\", temperature=0.0)\n", "\n", @@ -65,11 +65,13 @@ " punchline: str = Field(description=\"answer to resolve the joke\")\n", "\n", " # You can add custom validation logic easily with Pydantic.\n", - " @validator(\"setup\")\n", - " def question_ends_with_question_mark(cls, field):\n", - " if field[-1] != \"?\":\n", + " @model_validator(mode=\"before\")\n", + " @classmethod\n", + " def question_ends_with_question_mark(cls, values: dict) -> dict:\n", + " setup = values[\"setup\"]\n", + " if setup[-1] != \"?\":\n", " raise ValueError(\"Badly formed question!\")\n", - " return field\n", + " return values\n", "\n", "\n", "# Set up a parser + inject instructions into the prompt template.\n", @@ -239,9 +241,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "poetry-venv-311", "language": "python", - "name": "python3" + "name": "poetry-venv-311" }, "language_info": { "codemirror_mode": { @@ -253,7 +255,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.1" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/docs/docs/how_to/output_parser_yaml.ipynb b/docs/docs/how_to/output_parser_yaml.ipynb index 1f34a8840e3..48abc351b8f 100644 --- a/docs/docs/how_to/output_parser_yaml.ipynb +++ b/docs/docs/how_to/output_parser_yaml.ipynb @@ -70,8 +70,8 @@ "source": [ "from langchain.output_parsers import YamlOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "# Define your desired data structure.\n", diff --git a/docs/docs/how_to/qa_citations.ipynb b/docs/docs/how_to/qa_citations.ipynb index f026910d8d0..7dc28ac350e 100644 --- a/docs/docs/how_to/qa_citations.ipynb +++ b/docs/docs/how_to/qa_citations.ipynb @@ -269,7 +269,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class CitedAnswer(BaseModel):\n", diff --git a/docs/docs/how_to/query_constructing_filters.ipynb b/docs/docs/how_to/query_constructing_filters.ipynb index 118f7a0c8a3..33e798784b3 100644 --- a/docs/docs/how_to/query_constructing_filters.ipynb +++ b/docs/docs/how_to/query_constructing_filters.ipynb @@ -40,7 +40,7 @@ ")\n", "from langchain_community.query_constructors.chroma import ChromaTranslator\n", "from langchain_community.query_constructors.elasticsearch import ElasticsearchTranslator\n", - "from langchain_core.pydantic_v1 import BaseModel" + "from pydantic import BaseModel" ] }, { diff --git a/docs/docs/how_to/query_few_shot.ipynb b/docs/docs/how_to/query_few_shot.ipynb index 70dc9a01634..7a175cf222d 100644 --- a/docs/docs/how_to/query_few_shot.ipynb +++ b/docs/docs/how_to/query_few_shot.ipynb @@ -87,7 +87,7 @@ "source": [ "from typing import List, Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "sub_queries_description = \"\"\"\\\n", "If the original question contains multiple distinct sub-questions, \\\n", diff --git a/docs/docs/how_to/query_high_cardinality.ipynb b/docs/docs/how_to/query_high_cardinality.ipynb index 75c00dbc4ce..447a5fa3aca 100644 --- a/docs/docs/how_to/query_high_cardinality.ipynb +++ b/docs/docs/how_to/query_high_cardinality.ipynb @@ -154,12 +154,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "id": "0ae69afc", "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field" + "from pydantic import BaseModel, Field, model_validator" ] }, { @@ -492,21 +492,24 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 3, "id": "a2e8b434", "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import validator\n", - "\n", - "\n", "class Search(BaseModel):\n", " query: str\n", " author: str\n", "\n", - " @validator(\"author\")\n", - " def double(cls, v: str) -> str:\n", - " return vectorstore.similarity_search(v, k=1)[0].page_content" + " @model_validator(mode=\"before\")\n", + " @classmethod\n", + " def double(cls, values: dict) -> dict:\n", + " author = values[\"author\"]\n", + " closest_valid_author = vectorstore.similarity_search(author, k=1)[\n", + " 0\n", + " ].page_content\n", + " values[\"author\"] = closest_valid_author\n", + " return values" ] }, { @@ -563,9 +566,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "poetry-venv-311", "language": "python", - "name": "python3" + "name": "poetry-venv-311" }, "language_info": { "codemirror_mode": { @@ -577,7 +580,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.1" + "version": "3.11.9" } }, "nbformat": 4, diff --git a/docs/docs/how_to/query_multiple_queries.ipynb b/docs/docs/how_to/query_multiple_queries.ipynb index 242d28a4d31..223f7ebbb3e 100644 --- a/docs/docs/how_to/query_multiple_queries.ipynb +++ b/docs/docs/how_to/query_multiple_queries.ipynb @@ -115,7 +115,7 @@ "source": [ "from typing import List, Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Search(BaseModel):\n", diff --git a/docs/docs/how_to/query_multiple_retrievers.ipynb b/docs/docs/how_to/query_multiple_retrievers.ipynb index c5ed5d80eb8..0000cda5f01 100644 --- a/docs/docs/how_to/query_multiple_retrievers.ipynb +++ b/docs/docs/how_to/query_multiple_retrievers.ipynb @@ -117,7 +117,7 @@ "source": [ "from typing import List, Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Search(BaseModel):\n", diff --git a/docs/docs/how_to/query_no_queries.ipynb b/docs/docs/how_to/query_no_queries.ipynb index 5d3b93ccff5..53d34d94eb6 100644 --- a/docs/docs/how_to/query_no_queries.ipynb +++ b/docs/docs/how_to/query_no_queries.ipynb @@ -117,7 +117,7 @@ "source": [ "from typing import Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Search(BaseModel):\n", diff --git a/docs/docs/how_to/sql_large_db.ipynb b/docs/docs/how_to/sql_large_db.ipynb index 33d919b52ec..7fcc94cf2a5 100644 --- a/docs/docs/how_to/sql_large_db.ipynb +++ b/docs/docs/how_to/sql_large_db.ipynb @@ -136,7 +136,7 @@ "source": [ "from langchain_core.output_parsers.openai_tools import PydanticToolsParser\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Table(BaseModel):\n", diff --git a/docs/docs/how_to/structured_output.ipynb b/docs/docs/how_to/structured_output.ipynb index 152eef991af..29cd6da7a4f 100644 --- a/docs/docs/how_to/structured_output.ipynb +++ b/docs/docs/how_to/structured_output.ipynb @@ -101,7 +101,7 @@ "source": [ "from typing import Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "# Pydantic\n", @@ -667,7 +667,7 @@ "\n", "from langchain_core.output_parsers import PydanticOutputParser\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", @@ -794,7 +794,7 @@ "\n", "from langchain_core.messages import AIMessage\n", "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", diff --git a/docs/docs/how_to/tool_calling.ipynb b/docs/docs/how_to/tool_calling.ipynb index 029f673d500..38e4aee0b49 100644 --- a/docs/docs/how_to/tool_calling.ipynb +++ b/docs/docs/how_to/tool_calling.ipynb @@ -112,7 +112,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class add(BaseModel):\n", @@ -321,7 +321,7 @@ ], "source": [ "from langchain_core.output_parsers import PydanticToolsParser\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class add(BaseModel):\n", diff --git a/docs/docs/how_to/tool_runtime.ipynb b/docs/docs/how_to/tool_runtime.ipynb index ac831761749..61b1ecd2f58 100644 --- a/docs/docs/how_to/tool_runtime.ipynb +++ b/docs/docs/how_to/tool_runtime.ipynb @@ -418,8 +418,8 @@ } ], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_core.tools import BaseTool\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class UpdateFavoritePetsSchema(BaseModel):\n", diff --git a/docs/docs/how_to/tools_builtin.ipynb b/docs/docs/how_to/tools_builtin.ipynb index 3276a62961a..03e596e4315 100644 --- a/docs/docs/how_to/tools_builtin.ipynb +++ b/docs/docs/how_to/tools_builtin.ipynb @@ -140,7 +140,7 @@ "source": [ "from langchain_community.tools import WikipediaQueryRun\n", "from langchain_community.utilities import WikipediaAPIWrapper\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class WikiInputs(BaseModel):\n", diff --git a/docs/docs/integrations/chat/anthropic.ipynb b/docs/docs/integrations/chat/anthropic.ipynb index da0bf99b5a8..7167600b9ba 100644 --- a/docs/docs/integrations/chat/anthropic.ipynb +++ b/docs/docs/integrations/chat/anthropic.ipynb @@ -274,7 +274,7 @@ } ], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class GetWeather(BaseModel):\n", diff --git a/docs/docs/integrations/chat/anthropic_functions.ipynb b/docs/docs/integrations/chat/anthropic_functions.ipynb index 7a33a5c986d..f18ec195fbc 100644 --- a/docs/docs/integrations/chat/anthropic_functions.ipynb +++ b/docs/docs/integrations/chat/anthropic_functions.ipynb @@ -69,7 +69,7 @@ } ], "source": [ - "from langchain_core.pydantic_v1 import BaseModel\n", + "from pydantic import BaseModel\n", "\n", "\n", "class Person(BaseModel):\n", diff --git a/docs/docs/integrations/chat/deepinfra.ipynb b/docs/docs/integrations/chat/deepinfra.ipynb index e8d6d3465a9..2c5eddd6b83 100644 --- a/docs/docs/integrations/chat/deepinfra.ipynb +++ b/docs/docs/integrations/chat/deepinfra.ipynb @@ -123,8 +123,8 @@ "from dotenv import find_dotenv, load_dotenv\n", "from langchain_community.chat_models import ChatDeepInfra\n", "from langchain_core.messages import HumanMessage\n", - "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain_core.tools import tool\n", + "from pydantic import BaseModel\n", "\n", "model_name = \"meta-llama/Meta-Llama-3-70B-Instruct\"\n", "\n", diff --git a/docs/docs/integrations/chat/edenai.ipynb b/docs/docs/integrations/chat/edenai.ipynb index 2c8f96aed2c..80dfbb5b7c0 100644 --- a/docs/docs/integrations/chat/edenai.ipynb +++ b/docs/docs/integrations/chat/edenai.ipynb @@ -264,7 +264,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "llm = ChatEdenAI(provider=\"openai\", temperature=0.2, max_tokens=500)\n", "\n", diff --git a/docs/docs/integrations/chat/ibm_watsonx.ipynb b/docs/docs/integrations/chat/ibm_watsonx.ipynb index b2fd921937f..c0556454771 100644 --- a/docs/docs/integrations/chat/ibm_watsonx.ipynb +++ b/docs/docs/integrations/chat/ibm_watsonx.ipynb @@ -483,7 +483,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class GetWeather(BaseModel):\n", diff --git a/docs/docs/integrations/chat/llamacpp.ipynb b/docs/docs/integrations/chat/llamacpp.ipynb index d34a0f65fca..97a12133046 100644 --- a/docs/docs/integrations/chat/llamacpp.ipynb +++ b/docs/docs/integrations/chat/llamacpp.ipynb @@ -226,8 +226,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_core.tools import tool\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class WeatherInput(BaseModel):\n", @@ -343,8 +343,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain_core.utils.function_calling import convert_to_openai_tool\n", + "from pydantic import BaseModel\n", "\n", "\n", "class Joke(BaseModel):\n", diff --git a/docs/docs/integrations/chat/nvidia_ai_endpoints.ipynb b/docs/docs/integrations/chat/nvidia_ai_endpoints.ipynb index 474821a88b3..0149c7c463a 100644 --- a/docs/docs/integrations/chat/nvidia_ai_endpoints.ipynb +++ b/docs/docs/integrations/chat/nvidia_ai_endpoints.ipynb @@ -658,8 +658,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import Field\n", "from langchain_core.tools import tool\n", + "from pydantic import Field\n", "\n", "\n", "@tool\n", diff --git a/docs/docs/integrations/chat/premai.ipynb b/docs/docs/integrations/chat/premai.ipynb index 5a7b8f2bde4..61c44eb490a 100644 --- a/docs/docs/integrations/chat/premai.ipynb +++ b/docs/docs/integrations/chat/premai.ipynb @@ -426,8 +426,8 @@ "metadata": {}, "outputs": [], "source": [ - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_core.tools import tool\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "# Define the schema for function arguments\n", diff --git a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb index d5b1968d16d..ca0dadd3a2c 100644 --- a/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb +++ b/docs/docs/integrations/chat_loaders/langsmith_llm_runs.ipynb @@ -72,7 +72,7 @@ "source": [ "from enum import Enum\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Operation(Enum):\n", @@ -135,8 +135,8 @@ "source": [ "from pprint import pprint\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain_core.utils.function_calling import convert_pydantic_to_openai_function\n", + "from pydantic import BaseModel\n", "\n", "openai_function_def = convert_pydantic_to_openai_function(Calculator)\n", "pprint(openai_function_def)" diff --git a/docs/docs/integrations/providers/premai.md b/docs/docs/integrations/providers/premai.md index 4dc66d80881..609eeb63bac 100644 --- a/docs/docs/integrations/providers/premai.md +++ b/docs/docs/integrations/providers/premai.md @@ -286,7 +286,7 @@ In order to pass tools and let the LLM choose the tool it needs to call, we need ```python from langchain_core.tools import tool -from langchain_core.pydantic_v1 import BaseModel, Field +from pydantic import BaseModel, Field # Define the schema for function arguments class OperationInput(BaseModel): diff --git a/docs/docs/integrations/tools/infobip.ipynb b/docs/docs/integrations/tools/infobip.ipynb index 9ee4855e2a8..41e1b6fd3c5 100644 --- a/docs/docs/integrations/tools/infobip.ipynb +++ b/docs/docs/integrations/tools/infobip.ipynb @@ -106,9 +106,9 @@ "from langchain import hub\n", "from langchain.agents import AgentExecutor, create_openai_functions_agent\n", "from langchain_community.utilities.infobip import InfobipAPIWrapper\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_core.tools import StructuredTool\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "instructions = \"You are a coding teacher. You are teaching a student how to code. The student asks you a question. You answer the question.\"\n", "base_prompt = hub.pull(\"langchain-ai/openai-functions-template\")\n", diff --git a/docs/docs/tutorials/classification.ipynb b/docs/docs/tutorials/classification.ipynb index f59c4973858..9493e04f80f 100644 --- a/docs/docs/tutorials/classification.ipynb +++ b/docs/docs/tutorials/classification.ipynb @@ -72,8 +72,8 @@ "outputs": [], "source": [ "from langchain_core.prompts import ChatPromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel, Field\n", "\n", "tagging_prompt = ChatPromptTemplate.from_template(\n", " \"\"\"\n", diff --git a/docs/docs/tutorials/data_generation.ipynb b/docs/docs/tutorials/data_generation.ipynb index c73f3f35839..606ed357610 100644 --- a/docs/docs/tutorials/data_generation.ipynb +++ b/docs/docs/tutorials/data_generation.ipynb @@ -62,7 +62,6 @@ "# dotenv.load_dotenv()\n", "\n", "from langchain.prompts import FewShotPromptTemplate, PromptTemplate\n", - "from langchain_core.pydantic_v1 import BaseModel\n", "from langchain_experimental.tabular_synthetic_data.openai import (\n", " OPENAI_TEMPLATE,\n", " create_openai_data_generator,\n", @@ -71,7 +70,8 @@ " SYNTHETIC_FEW_SHOT_PREFIX,\n", " SYNTHETIC_FEW_SHOT_SUFFIX,\n", ")\n", - "from langchain_openai import ChatOpenAI" + "from langchain_openai import ChatOpenAI\n", + "from pydantic import BaseModel" ] }, { diff --git a/docs/docs/tutorials/extraction.ipynb b/docs/docs/tutorials/extraction.ipynb index 099f3e514e0..f99034d358d 100644 --- a/docs/docs/tutorials/extraction.ipynb +++ b/docs/docs/tutorials/extraction.ipynb @@ -115,7 +115,7 @@ "source": [ "from typing import Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", @@ -167,7 +167,7 @@ "from typing import Optional\n", "\n", "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "# Define a custom prompt to provide instructions and any additional context.\n", "# 1) You can add examples into the prompt template to improve extraction quality\n", @@ -290,7 +290,7 @@ "source": [ "from typing import List, Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Person(BaseModel):\n", diff --git a/docs/docs/tutorials/query_analysis.ipynb b/docs/docs/tutorials/query_analysis.ipynb index eaf4310fa76..2345f33cbe0 100644 --- a/docs/docs/tutorials/query_analysis.ipynb +++ b/docs/docs/tutorials/query_analysis.ipynb @@ -376,7 +376,7 @@ "source": [ "from typing import Optional\n", "\n", - "from langchain_core.pydantic_v1 import BaseModel, Field\n", + "from pydantic import BaseModel, Field\n", "\n", "\n", "class Search(BaseModel):\n",