From e7fbdeeb136bfd720a0be947b14b9ca8bba14f56 Mon Sep 17 00:00:00 2001 From: Vadym Barda Date: Tue, 18 Mar 2025 13:00:36 -0400 Subject: [PATCH] docs: fix formatting (#3901) --- docs/docs/how-tos/state-model.ipynb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/docs/how-tos/state-model.ipynb b/docs/docs/how-tos/state-model.ipynb index 4448170cf..c4fb12041 100644 --- a/docs/docs/how-tos/state-model.ipynb +++ b/docs/docs/how-tos/state-model.ipynb @@ -353,22 +353,26 @@ "from langgraph.graph import StateGraph, START, END\n", "from pydantic import BaseModel\n", "\n", + "\n", "class NestedModel(BaseModel):\n", " value: str\n", "\n", + "\n", "class ComplexState(BaseModel):\n", " text: str\n", " count: int\n", " nested: NestedModel\n", "\n", + "\n", "def process_node(state: ComplexState):\n", " # Node receives a validated Pydantic object\n", " print(f\"Input state type: {type(state)}\")\n", " print(f\"Nested type: {type(state.nested)}\")\n", - " \n", + "\n", " # Return a dictionary update\n", " return {\"text\": state.text + \" processed\", \"count\": state.count + 1}\n", "\n", + "\n", "# Build the graph\n", "builder = StateGraph(ComplexState)\n", "builder.add_node(\"process\", process_node)\n", @@ -410,17 +414,20 @@ "from langgraph.graph import StateGraph, START, END\n", "from pydantic import BaseModel\n", "\n", + "\n", "class CoercionExample(BaseModel):\n", " # Pydantic will coerce string numbers to integers\n", " number: int\n", " # Pydantic will parse string booleans to bool\n", " flag: bool\n", "\n", + "\n", "def inspect_node(state: CoercionExample):\n", " print(f\"number: {state.number} (type: {type(state.number)})\")\n", " print(f\"flag: {state.flag} (type: {type(state.flag)})\")\n", " return {}\n", "\n", + "\n", "builder = StateGraph(CoercionExample)\n", "builder.add_node(\"inspect\", inspect_node)\n", "builder.add_edge(START, \"inspect\")\n", @@ -459,13 +466,16 @@ "from langchain_core.messages import HumanMessage, AIMessage, BaseMessage\n", "from typing import List\n", "\n", + "\n", "class ChatState(BaseModel):\n", - " messages: List[BaseMessage] \n", + " messages: List[BaseMessage]\n", " context: str\n", "\n", + "\n", "def add_message(state: ChatState):\n", " return {\"messages\": state.messages + [AIMessage(content=\"Hello there!\")]}\n", "\n", + "\n", "builder = StateGraph(ChatState)\n", "builder.add_node(\"add_message\", add_message)\n", "builder.add_edge(START, \"add_message\")\n", @@ -474,8 +484,7 @@ "\n", "# Create input with a message\n", "initial_state = ChatState(\n", - " messages=[HumanMessage(content=\"Hi\")],\n", - " context=\"Customer support chat\"\n", + " messages=[HumanMessage(content=\"Hi\")], context=\"Customer support chat\"\n", ")\n", "\n", "result = graph.invoke(initial_state)\n",