From e80098e297d951221c3fe79cddcaf92747d9104b Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Wed, 4 Dec 2024 22:38:55 -0500 Subject: [PATCH] x --- .../how-tos/human_in_the_loop/interrupt.ipynb | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/docs/how-tos/human_in_the_loop/interrupt.ipynb b/docs/docs/how-tos/human_in_the_loop/interrupt.ipynb index 4f7ecdd25..f063a07fc 100644 --- a/docs/docs/how-tos/human_in_the_loop/interrupt.ipynb +++ b/docs/docs/how-tos/human_in_the_loop/interrupt.ipynb @@ -139,26 +139,31 @@ "from langgraph.types import interrupt, Command\n", "from langgraph.checkpoint.memory import MemorySaver\n", "\n", + "\n", "class State(TypedDict):\n", " \"\"\"The graph state.\"\"\"\n", + "\n", " foo: str\n", " human_value: Optional[str]\n", " \"\"\"Human value will be updated using an interrupt.\"\"\"\n", - " \n", + "\n", + "\n", "counter = 0\n", "\n", + "\n", "def node(state: State):\n", " global counter\n", - " counter +=1 \n", - " print(f'> Entered the node: {counter} # of times')\n", + " counter += 1\n", + " print(f\"> Entered the node: {counter} # of times\")\n", " answer = interrupt(\n", " # This value will be sent to the client\n", " # as part of the interrupt information.\n", - " 'what is your age?'\n", + " \"what is your age?\"\n", " )\n", - " print(f'> Received an input from the interrupt: {answer}')\n", + " print(f\"> Received an input from the interrupt: {answer}\")\n", " return {\"human_value\": answer}\n", "\n", + "\n", "builder = StateGraph(State)\n", "builder.add_node(\"node\", node)\n", "builder.add_edge(START, \"node\")\n", @@ -290,25 +295,25 @@ "\n", "class State(TypedDict):\n", " \"\"\"The graph state.\"\"\"\n", + "\n", " foo: str\n", " human_value: Optional[str]\n", " \"\"\"Human value will be updated using an interrupt.\"\"\"\n", - " \n", + "\n", "\n", "counter = 0\n", "\n", + "\n", "def node(state: State):\n", " global counter\n", - " counter +=1 \n", - " print(f'> Entered the node: {counter} # of times')\n", + " counter += 1\n", + " print(f\"> Entered the node: {counter} # of times\")\n", "\n", " answer = None\n", " question = \"What is your age?\"\n", "\n", " while answer is None:\n", - " answer = interrupt(\n", - " question\n", - " )\n", + " answer = interrupt(question)\n", "\n", " if not isinstance(answer, int) or answer < 0:\n", " question = f\"'{answer} is not a valid age. What is your age?\"\n", @@ -317,11 +322,8 @@ " else:\n", " break\n", "\n", - " return {\n", - " \"human_value\": f\"The human is {answer} years old.\"\n", - " }\n", + " return {\"human_value\": f\"The human is {answer} years old.\"}\n", "\n", - " \n", "\n", "builder = StateGraph(State)\n", "builder.add_node(\"node\", node)\n", @@ -377,7 +379,7 @@ } ], "source": [ - "bad_input = -20 # Negative number!\n", + "bad_input = -20 # Negative number!\n", "for chunk in graph.stream(Command(resume=bad_input), config):\n", " print(chunk)" ] @@ -398,7 +400,7 @@ } ], "source": [ - "bad_input = {\"foo\": \"bar\"} # Not a number!\n", + "bad_input = {\"foo\": \"bar\"} # Not a number!\n", "for chunk in graph.stream(Command(resume=bad_input), config):\n", " print(chunk)" ] @@ -476,26 +478,31 @@ "from langgraph.types import interrupt, Command\n", "from langgraph.checkpoint.memory import MemorySaver\n", "\n", + "\n", "class State(TypedDict):\n", " \"\"\"The graph state.\"\"\"\n", + "\n", " foo: str\n", " human_value: Optional[str]\n", " \"\"\"Human value will be updated using an interrupt.\"\"\"\n", - " \n", + "\n", + "\n", "counter = 0\n", "\n", + "\n", "def node(state: State):\n", " global counter\n", - " counter +=1 \n", - " print(f'> Entered the node: {counter} # of times')\n", + " counter += 1\n", + " print(f\"> Entered the node: {counter} # of times\")\n", " answer = interrupt(\n", " # This value will be sent to the client\n", " # as part of the interrupt information.\n", - " 'what is your age?'\n", + " \"what is your age?\"\n", " )\n", - " print(f'> Received an input from the interrupt: {answer}')\n", + " print(f\"> Received an input from the interrupt: {answer}\")\n", " return {\"human_value\": answer}\n", "\n", + "\n", "builder = StateGraph(State)\n", "builder.add_node(\"node\", node)\n", "builder.add_edge(START, \"node\")\n",