mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-23 08:02:23 +02:00
docs: update pydantic comments -> callouts in tutorials (#1825)
This commit is contained in:
+13
-1
@@ -535,6 +535,19 @@
|
||||
"We will use an LLM to evaluate whether your assistant successfully resisted the red team attack."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "263fbc21-94bb-40ab-be43-92aa4c83fc50",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
@@ -546,7 +559,6 @@
|
||||
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -84,6 +84,19 @@
|
||||
"First, let's define the part of the graph that will gather user requirements. This will be an LLM call with a specific system message. It will have access to a tool that it can call when it is ready to generate the prompt."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0d731dcc-8295-498d-a95f-644ce24a717e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
@@ -96,7 +109,6 @@
|
||||
"from langchain_core.messages import SystemMessage\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -130,6 +130,19 @@
|
||||
"We will create a `code_gen_chain` w/ either OpenAI or Claude and test them here."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "95944645-35bc-4798-8a27-c262b245a74c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
@@ -150,7 +163,6 @@
|
||||
"source": [
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"### OpenAI\n",
|
||||
|
||||
@@ -3086,6 +3086,19 @@
|
||||
"Each *specialized* / delegated assistant additionally can call the `CompleteOrEscalate` tool to indicate that the control flow should be passed back to the primary assistant. This happens if it has successfully completed its work or if the user has changed their mind or needs assistance on something that beyond the scope of that particular workflow."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b46da448-a1fc-4309-80db-4b7feed9f96b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
@@ -3097,7 +3110,7 @@
|
||||
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.runnables import Runnable, RunnableConfig\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -387,6 +387,19 @@
|
||||
"Now we'll ask our model to call a function. We'll add a validator to illustrate how the LLM is able to use the validation error to fix its results."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0507df47-8780-4caf-863f-3d60bb165721",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
@@ -394,7 +407,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel, Field, field_validator\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -2039,6 +2039,19 @@
|
||||
"Next, define a schema to show the model to let it decide to request assistance."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7bd3d704-5bee-4872-8d12-992bc970c158",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
@@ -2046,7 +2059,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel\n",
|
||||
"\n",
|
||||
"class RequestAssistance(BaseModel):\n",
|
||||
|
||||
@@ -977,6 +977,19 @@
|
||||
"The paper refers to this as the \"joiner\". It's another LLM call. We are using function calling to improve parsing reliability."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ad4d2b50-5e10-4111-996f-e58c694d488f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
@@ -985,7 +998,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_core.messages import AIMessage\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -231,6 +231,19 @@
|
||||
"Let's now think about creating the planning step. This will use function calling to create a plan."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e12494fa-c6a2-4cfa-ae58-f72961437843",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
@@ -238,7 +251,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
},
|
||||
"cell_type": "markdown",
|
||||
"id": "5afcaed0-3d55-4e1f-95d3-c32c751c29d8",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Adaptive RAG\n",
|
||||
"\n",
|
||||
@@ -148,6 +146,19 @@
|
||||
"## LLMs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d28baefd-a961-49b0-8394-c5478dadda1c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
@@ -170,7 +181,7 @@
|
||||
"\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -189,6 +189,19 @@
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bd7a7843-2a4a-4de5-a211-ff2efe3aba47",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
@@ -217,7 +230,7 @@
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
"from langchain_core.prompts import PromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -139,6 +139,19 @@
|
||||
"## LLMs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c1da8975-f2c4-4584-a0f9-bd5af88983a3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
@@ -158,7 +171,7 @@
|
||||
"\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -150,6 +150,19 @@
|
||||
"## LLMs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6cf1011b-213c-45fd-9608-328fc6eea677",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
@@ -170,7 +183,7 @@
|
||||
"\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -140,6 +140,19 @@
|
||||
"#### Initial responder"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "afa7aa4f-279e-4562-b1b5-6ce8391ef853",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
@@ -151,7 +164,7 @@
|
||||
"from langchain_core.output_parsers.openai_tools import PydanticToolsParser\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
||||
"from pydantic import ValidationError\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -507,6 +507,19 @@
|
||||
"We will then define the workflow for the agent. The agent will first force-call the `list_tables_tool` to fetch the available tables from the database, then follow the steps mentioned at the beginning of the tutorial."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2fd9e41c-95c3-47aa-9a12-80b78cc7ac2d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
@@ -527,7 +540,7 @@
|
||||
"\n",
|
||||
"from langchain_core.messages import AIMessage\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"from typing_extensions import TypedDict\n",
|
||||
"\n",
|
||||
|
||||
@@ -132,6 +132,18 @@
|
||||
"outline to be refined after our research. Below, we will use our \"fast\" llm to generate the outline."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
@@ -141,7 +153,7 @@
|
||||
"from typing import List, Optional\n",
|
||||
"\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"direct_gen_outline_prompt = ChatPromptTemplate.from_messages(\n",
|
||||
|
||||
@@ -339,6 +339,19 @@
|
||||
"Create a `solver` node that prompts an LLM \"agent\" to use a [writePython tool](https://python.langchain.com/docs/integrations/chat/anthropic/#integration-details) to generate the submitted code."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7c1f057e-b2cb-4085-9f4b-54ef005df0c6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div class=\"admonition note\">\n",
|
||||
" <p class=\"admonition-title\">Using Pydantic with LangChain</p>\n",
|
||||
" <p>\n",
|
||||
" This notebook uses Pydantic v2 <code>BaseModel</code>, which requires <code>langchain-core >= 0.3</code>. Using <code>langchain-core < 0.3</code> will result in errors due to mixing of Pydantic v1 and v2 <code>BaseModels</code>.\n",
|
||||
" </p>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
@@ -348,7 +361,7 @@
|
||||
"source": [
|
||||
"from langchain_core.language_models import BaseChatModel\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
|
||||
"\n",
|
||||
"from pydantic import BaseModel, Field\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user