[Docs] use END instead of set_finish_point (#903)

This commit is contained in:
William FH
2024-07-01 21:56:10 -07:00
committed by GitHub
parent 727e63c01e
commit 320a87e1b9
31 changed files with 4189 additions and 389 deletions
@@ -44,9 +44,10 @@
"outputs": [],
"source": [
"from langgraph_sdk import get_client\n",
"\n",
"client = get_client()\n",
"assistants = await client.assistants.search()\n",
"assistants = [a for a in assistants if not a['config']]\n",
"assistants = [a for a in assistants if not a[\"config\"]]\n",
"assistant = assistants[0]\n",
"thread = await client.threads.create()"
]
@@ -76,11 +77,18 @@
}
],
"source": [
"input = {'messages':[{\"role\":\"user\",\"content\":\"Use the search tool to ask the user where they are, then look up the weather there\"}]}\n",
"input = {\n",
" \"messages\": [\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"Use the search tool to ask the user where they are, then look up the weather there\",\n",
" }\n",
" ]\n",
"}\n",
"\n",
"async for chunk in client.runs.stream(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"], # graph_id\n",
" assistant[\"assistant_id\"], # graph_id\n",
" input=input,\n",
" stream_mode=\"updates\",\n",
" interrupt_before=[\"ask_human\"],\n",
@@ -118,13 +126,17 @@
}
],
"source": [
"state = await client.threads.get_state(thread['thread_id'])\n",
"tool_call_id = state['values']['messages'][-1]['tool_calls'][0]['id']\n",
"state = await client.threads.get_state(thread[\"thread_id\"])\n",
"tool_call_id = state[\"values\"][\"messages\"][-1][\"tool_calls\"][0][\"id\"]\n",
"\n",
"# We now create the tool call with the id and the response we want\n",
"tool_message = [{\"tool_call_id\": tool_call_id, \"type\": \"tool\", \"content\": \"san francisco\"}]\n",
"tool_message = [\n",
" {\"tool_call_id\": tool_call_id, \"type\": \"tool\", \"content\": \"san francisco\"}\n",
"]\n",
"\n",
"await client.threads.update_state(thread['thread_id'], {\"messages\": tool_message}, as_node=\"ask_human\")\n"
"await client.threads.update_state(\n",
" thread[\"thread_id\"], {\"messages\": tool_message}, as_node=\"ask_human\"\n",
")"
]
},
{
@@ -154,7 +166,7 @@
"source": [
"async for chunk in client.runs.stream(\n",
" thread[\"thread_id\"],\n",
" assistant[\"assistant_id\"], # graph_id\n",
" assistant[\"assistant_id\"], # graph_id\n",
" input=None,\n",
" stream_mode=\"updates\",\n",
"):\n",