mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-10-01 22:15:11 +02:00
fmt
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
"source": [
|
||||
"# There should always be a default assistant with no configuration\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",
|
||||
"assistants"
|
||||
]
|
||||
},
|
||||
@@ -142,7 +142,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"runs = await client.runs.list(thread['thread_id'])\n",
|
||||
"runs = await client.runs.list(thread[\"thread_id\"])\n",
|
||||
"runs"
|
||||
]
|
||||
},
|
||||
@@ -188,7 +188,11 @@
|
||||
"source": [
|
||||
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"whats the weather in sf\"}]}\n",
|
||||
"async for chunk in client.runs.stream(\n",
|
||||
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
|
||||
" thread[\"thread_id\"],\n",
|
||||
" assistant[\"assistant_id\"],\n",
|
||||
" input=input,\n",
|
||||
" stream_mode=\"updates\",\n",
|
||||
" interrupt_before=[\"action\"],\n",
|
||||
"):\n",
|
||||
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
|
||||
" print(chunk.data)\n",
|
||||
@@ -239,7 +243,11 @@
|
||||
"source": [
|
||||
"input = None\n",
|
||||
"async for chunk in client.runs.stream(\n",
|
||||
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
|
||||
" thread[\"thread_id\"],\n",
|
||||
" assistant[\"assistant_id\"],\n",
|
||||
" input=input,\n",
|
||||
" stream_mode=\"updates\",\n",
|
||||
" interrupt_before=[\"action\"],\n",
|
||||
"):\n",
|
||||
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
|
||||
" print(chunk.data)\n",
|
||||
@@ -289,7 +297,11 @@
|
||||
"source": [
|
||||
"input = {\"messages\": [{\"role\": \"human\", \"content\": \"whats the weather in la?\"}]}\n",
|
||||
"async for chunk in client.runs.stream(\n",
|
||||
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
|
||||
" thread[\"thread_id\"],\n",
|
||||
" assistant[\"assistant_id\"],\n",
|
||||
" input=input,\n",
|
||||
" stream_mode=\"updates\",\n",
|
||||
" interrupt_before=[\"action\"],\n",
|
||||
"):\n",
|
||||
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
|
||||
" print(chunk.data)\n",
|
||||
@@ -311,7 +323,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"thread_state = await client.threads.get_state(thread['thread_id'])"
|
||||
"thread_state = await client.threads.get_state(thread[\"thread_id\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -329,7 +341,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"last_message = thread_state['values']['messages'][-1]"
|
||||
"last_message = thread_state[\"values\"][\"messages\"][-1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -353,7 +365,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"last_message['content']"
|
||||
"last_message[\"content\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -371,12 +383,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"last_message['tool_calls'] = [{\n",
|
||||
" 'id': last_message['tool_calls'][0]['id'],\n",
|
||||
" 'name': 'tavily_search_results_json',\n",
|
||||
" # We change the query to say temperature\n",
|
||||
" 'args': {'query': 'weather in Louisiana'}\n",
|
||||
"}]\n",
|
||||
"last_message[\"tool_calls\"] = [\n",
|
||||
" {\n",
|
||||
" \"id\": last_message[\"tool_calls\"][0][\"id\"],\n",
|
||||
" \"name\": \"tavily_search_results_json\",\n",
|
||||
" # We change the query to say temperature\n",
|
||||
" \"args\": {\"query\": \"weather in Louisiana\"},\n",
|
||||
" }\n",
|
||||
"]\n",
|
||||
"# last_message['content'] = [{\n",
|
||||
"# 'id': last_message['content'][0]['id'],\n",
|
||||
"# 'name': 'tavily_search_results_json',\n",
|
||||
@@ -413,7 +427,9 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"await client.threads.update_state(thread['thread_id'], values={\"messages\": [last_message]})"
|
||||
"await client.threads.update_state(\n",
|
||||
" thread[\"thread_id\"], values={\"messages\": [last_message]}\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -444,8 +460,8 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"thread_state = await client.threads.get_state(thread['thread_id'])\n",
|
||||
"thread_state['values']['messages'][-1]['tool_calls']"
|
||||
"thread_state = await client.threads.get_state(thread[\"thread_id\"])\n",
|
||||
"thread_state[\"values\"][\"messages\"][-1][\"tool_calls\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -492,7 +508,11 @@
|
||||
"source": [
|
||||
"input = None\n",
|
||||
"async for chunk in client.runs.stream(\n",
|
||||
" thread['thread_id'], assistant['assistant_id'], input=input, stream_mode=\"updates\", interrupt_before=['action']\n",
|
||||
" thread[\"thread_id\"],\n",
|
||||
" assistant[\"assistant_id\"],\n",
|
||||
" input=input,\n",
|
||||
" stream_mode=\"updates\",\n",
|
||||
" interrupt_before=[\"action\"],\n",
|
||||
"):\n",
|
||||
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
|
||||
" print(chunk.data)\n",
|
||||
@@ -517,7 +537,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"thread_history = await client.threads.get_history(thread['thread_id'], limit=100)"
|
||||
"thread_history = await client.threads.get_history(thread[\"thread_id\"], limit=100)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -571,7 +591,7 @@
|
||||
],
|
||||
"source": [
|
||||
"rewind_state = thread_history[3]\n",
|
||||
"rewind_state['values']['messages'][-1]['tool_calls']"
|
||||
"rewind_state[\"values\"][\"messages\"][-1][\"tool_calls\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -593,7 +613,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"rewind_state['config']"
|
||||
"rewind_state[\"config\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -640,12 +660,12 @@
|
||||
"source": [
|
||||
"input = None\n",
|
||||
"async for chunk in client.runs.stream(\n",
|
||||
" thread['thread_id'], \n",
|
||||
" assistant['assistant_id'], \n",
|
||||
" input=input, \n",
|
||||
" stream_mode=\"updates\", \n",
|
||||
" interrupt_before=['action'],\n",
|
||||
" config=rewind_state['config']\n",
|
||||
" thread[\"thread_id\"],\n",
|
||||
" assistant[\"assistant_id\"],\n",
|
||||
" input=input,\n",
|
||||
" stream_mode=\"updates\",\n",
|
||||
" interrupt_before=[\"action\"],\n",
|
||||
" config=rewind_state[\"config\"],\n",
|
||||
"):\n",
|
||||
" print(f\"Receiving new event of type: {chunk.event}...\")\n",
|
||||
" print(chunk.data)\n",
|
||||
|
||||
Reference in New Issue
Block a user