This commit is contained in:
Eugene Yurtsev
2024-12-04 22:38:55 -05:00
parent 3d3647cd85
commit e80098e297
@@ -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",