From 1b1b1cd9a9cfacc636cd7568d0998bf1a96072bb Mon Sep 17 00:00:00 2001 From: vbarda Date: Tue, 24 Sep 2024 09:02:43 -0400 Subject: [PATCH] docs: update pydantic comments -> callouts in tutorials --- ...angsmith-agent-simulation-evaluation.ipynb | 14 +++++++++++++- .../information-gather-prompting.ipynb | 14 +++++++++++++- .../langgraph_code_assistant.ipynb | 14 +++++++++++++- .../customer-support/customer-support.ipynb | 15 ++++++++++++++- docs/docs/tutorials/extraction/retries.ipynb | 14 +++++++++++++- docs/docs/tutorials/introduction.ipynb | 14 +++++++++++++- .../tutorials/llm-compiler/LLMCompiler.ipynb | 15 ++++++++++++++- .../plan-and-execute/plan-and-execute.ipynb | 14 +++++++++++++- .../rag/langgraph_adaptive_rag.ipynb | 19 +++++++++++++++---- .../tutorials/rag/langgraph_agentic_rag.ipynb | 15 ++++++++++++++- docs/docs/tutorials/rag/langgraph_crag.ipynb | 15 ++++++++++++++- .../tutorials/rag/langgraph_self_rag.ipynb | 15 ++++++++++++++- docs/docs/tutorials/reflexion/reflexion.ipynb | 15 ++++++++++++++- docs/docs/tutorials/sql-agent.ipynb | 15 ++++++++++++++- docs/docs/tutorials/storm/storm.ipynb | 14 +++++++++++++- docs/docs/tutorials/usaco/usaco.ipynb | 15 ++++++++++++++- 16 files changed, 218 insertions(+), 19 deletions(-) diff --git a/docs/docs/tutorials/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb b/docs/docs/tutorials/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb index 56cf008e7..8bd724a7f 100644 --- a/docs/docs/tutorials/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb +++ b/docs/docs/tutorials/chatbot-simulation-evaluation/langsmith-agent-simulation-evaluation.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb b/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb index 67b2e7046..e3cf715a5 100644 --- a/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb +++ b/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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" ] }, diff --git a/docs/docs/tutorials/code_assistant/langgraph_code_assistant.ipynb b/docs/docs/tutorials/code_assistant/langgraph_code_assistant.ipynb index 9db776443..816943202 100644 --- a/docs/docs/tutorials/code_assistant/langgraph_code_assistant.ipynb +++ b/docs/docs/tutorials/code_assistant/langgraph_code_assistant.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/customer-support/customer-support.ipynb b/docs/docs/tutorials/customer-support/customer-support.ipynb index 0e4ab07b7..dff032e51 100644 --- a/docs/docs/tutorials/customer-support/customer-support.ipynb +++ b/docs/docs/tutorials/customer-support/customer-support.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/extraction/retries.ipynb b/docs/docs/tutorials/extraction/retries.ipynb index 7cc088469..847473701 100644 --- a/docs/docs/tutorials/extraction/retries.ipynb +++ b/docs/docs/tutorials/extraction/retries.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/introduction.ipynb b/docs/docs/tutorials/introduction.ipynb index 67cec9de3..41c897589 100644 --- a/docs/docs/tutorials/introduction.ipynb +++ b/docs/docs/tutorials/introduction.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/llm-compiler/LLMCompiler.ipynb b/docs/docs/tutorials/llm-compiler/LLMCompiler.ipynb index 33855834c..cc57cdc3a 100644 --- a/docs/docs/tutorials/llm-compiler/LLMCompiler.ipynb +++ b/docs/docs/tutorials/llm-compiler/LLMCompiler.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb b/docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb index bb383477e..cdb2995c8 100644 --- a/docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb +++ b/docs/docs/tutorials/plan-and-execute/plan-and-execute.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/rag/langgraph_adaptive_rag.ipynb b/docs/docs/tutorials/rag/langgraph_adaptive_rag.ipynb index 3daa2ae79..894897982 100644 --- a/docs/docs/tutorials/rag/langgraph_adaptive_rag.ipynb +++ b/docs/docs/tutorials/rag/langgraph_adaptive_rag.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/rag/langgraph_agentic_rag.ipynb b/docs/docs/tutorials/rag/langgraph_agentic_rag.ipynb index 060c230ef..393014cdd 100644 --- a/docs/docs/tutorials/rag/langgraph_agentic_rag.ipynb +++ b/docs/docs/tutorials/rag/langgraph_agentic_rag.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/rag/langgraph_crag.ipynb b/docs/docs/tutorials/rag/langgraph_crag.ipynb index 6010035d6..8a332b821 100644 --- a/docs/docs/tutorials/rag/langgraph_crag.ipynb +++ b/docs/docs/tutorials/rag/langgraph_crag.ipynb @@ -139,6 +139,19 @@ "## LLMs" ] }, + { + "cell_type": "markdown", + "id": "c1da8975-f2c4-4584-a0f9-bd5af88983a3", + "metadata": {}, + "source": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/rag/langgraph_self_rag.ipynb b/docs/docs/tutorials/rag/langgraph_self_rag.ipynb index 29d2cb5a1..12453b474 100644 --- a/docs/docs/tutorials/rag/langgraph_self_rag.ipynb +++ b/docs/docs/tutorials/rag/langgraph_self_rag.ipynb @@ -150,6 +150,19 @@ "## LLMs" ] }, + { + "cell_type": "markdown", + "id": "6cf1011b-213c-45fd-9608-328fc6eea677", + "metadata": {}, + "source": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/reflexion/reflexion.ipynb b/docs/docs/tutorials/reflexion/reflexion.ipynb index 28274f15d..d715555af 100644 --- a/docs/docs/tutorials/reflexion/reflexion.ipynb +++ b/docs/docs/tutorials/reflexion/reflexion.ipynb @@ -140,6 +140,19 @@ "#### Initial responder" ] }, + { + "cell_type": "markdown", + "id": "afa7aa4f-279e-4562-b1b5-6ce8391ef853", + "metadata": {}, + "source": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/sql-agent.ipynb b/docs/docs/tutorials/sql-agent.ipynb index a8c4bb969..e560d8550 100644 --- a/docs/docs/tutorials/sql-agent.ipynb +++ b/docs/docs/tutorials/sql-agent.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/storm/storm.ipynb b/docs/docs/tutorials/storm/storm.ipynb index 9faae128d..2e2575ecc 100644 --- a/docs/docs/tutorials/storm/storm.ipynb +++ b/docs/docs/tutorials/storm/storm.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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", diff --git a/docs/docs/tutorials/usaco/usaco.ipynb b/docs/docs/tutorials/usaco/usaco.ipynb index 49b3a6e72..0c5faec02 100644 --- a/docs/docs/tutorials/usaco/usaco.ipynb +++ b/docs/docs/tutorials/usaco/usaco.ipynb @@ -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": [ + "
\n", + "

Using Pydantic with LangChain

\n", + "

\n", + " This notebook uses Pydantic v2 BaseModel, which requires langchain-core >= 0.3. Using langchain-core < 0.3 will result in errors due to mixing of Pydantic v1 and v2 BaseModels.\n", + "

\n", + "
" + ] + }, { "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",