Skip to content

Commit

Permalink
docs: update pydantic comments -> callouts in tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
vbarda committed Sep 24, 2024
1 parent d2d5e9f commit 1b1b1cd
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion docs/docs/tutorials/chatbots/information-gather-prompting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/customer-support/customer-support.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion docs/docs/tutorials/extraction/retries.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,26 @@
"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,
"id": "5df33c17-ee1a-409e-b5ec-f24e116da7d1",
"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",
Expand Down
14 changes: 13 additions & 1 deletion docs/docs/tutorials/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,26 @@
"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,
"id": "e5192e54-6a28-42fe-a8a7-62d45d61f994",
"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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/llm-compiler/LLMCompiler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,26 @@
"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,
"id": "4a88626d-6dfd-4488-87f0-a9a0dd6da44c",
"metadata": {},
"outputs": [],
"source": [
"# NOTE: you must use langchain-core >= 0.3 with Pydantic v2\n",
"from pydantic import BaseModel, Field\n",
"\n",
"\n",
Expand Down
19 changes: 15 additions & 4 deletions docs/docs/tutorials/rag/langgraph_adaptive_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
},
"cell_type": "markdown",
"id": "5afcaed0-3d55-4e1f-95d3-c32c751c29d8",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"metadata": {},
"source": [
"# Adaptive RAG\n",
"\n",
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/rag/langgraph_agentic_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@
"![Screenshot 2024-02-14 at 3.43.58 PM.png](attachment:7ad1a116-28d7-473f-8cff-5f2efd0bf118.png)"
]
},
{
"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,
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/rag/langgraph_crag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/rag/langgraph_self_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion docs/docs/tutorials/reflexion/reflexion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 1b1b1cd

Please sign in to comment.