mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-07 10:17:50 +02:00
fixed some (#1784)
This commit is contained in:
@@ -869,7 +869,7 @@
|
||||
"id": "cb4072c9-775e-4bf5-8a1a-fb822e6de9d7",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"For streaming events, in LangGraph you need to use `.astream_events` method on the `CompiledGraph`. In LangGraph Cloud this is done via passing `stream_mode=\"events\"`"
|
||||
"For streaming events, in LangGraph you need to use `.astream` method on the `CompiledGraph`. In LangGraph Cloud this is done via passing `stream_mode=\"events\"`"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -882,89 +882,42 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "94b815e4-1dd2-4999-9e73-6e29836d9160",
|
||||
"execution_count": 22,
|
||||
"id": "fc692060",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Tool Calls:\n",
|
||||
" get_weather (call_UPFCSk4cQTFAuET2WgAzq0el)\n",
|
||||
" Call ID: call_UPFCSk4cQTFAuET2WgAzq0el\n",
|
||||
" Args:\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Tool Calls:\n",
|
||||
" (None)\n",
|
||||
" Call ID: None\n",
|
||||
" Args:\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Invalid Tool Calls:\n",
|
||||
" None (None)\n",
|
||||
" Call ID: None\n",
|
||||
" Args:\n",
|
||||
" city\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Invalid Tool Calls:\n",
|
||||
" None (None)\n",
|
||||
" Call ID: None\n",
|
||||
" Args:\n",
|
||||
" \":\"\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Invalid Tool Calls:\n",
|
||||
" None (None)\n",
|
||||
" Call ID: None\n",
|
||||
" Args:\n",
|
||||
" sf\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Invalid Tool Calls:\n",
|
||||
" None (None)\n",
|
||||
" Call ID: None\n",
|
||||
" Args:\n",
|
||||
" \"}\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
"The\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" weather\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" in\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" San\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" Francisco\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" is\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" sunny\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
"!\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" ☀\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
"️\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n"
|
||||
"[{'name': 'get_weather', 'args': {}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"[{'name': 'get_weather', 'args': {}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"[{'name': 'get_weather', 'args': {}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"[{'name': 'get_weather', 'args': {'city': ''}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"[{'name': 'get_weather', 'args': {'city': 'sf'}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"[{'name': 'get_weather', 'args': {'city': 'sf'}, 'id': 'call_G6boP6Hj21glqPTqtFdTllUd', 'type': 'tool_call'}]\n",
|
||||
"It's always sunny in sf|The| weather| in| San| Francisco| is| currently| sunny|.|"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_core.messages import AIMessageChunk\n",
|
||||
"\n",
|
||||
"inputs = {\"messages\": [(\"human\", \"what's the weather in sf\")]}\n",
|
||||
"async for chunk in graph.astream_events(inputs, version=\"v2\"):\n",
|
||||
" if chunk[\"event\"] == \"on_chat_model_stream\":\n",
|
||||
" chunk[\"data\"][\"chunk\"].pretty_print()"
|
||||
"first = True\n",
|
||||
"async for msg, metadata in graph.astream(inputs, stream_mode=\"messages\"):\n",
|
||||
" if msg.content:\n",
|
||||
" print(msg.content, end=\"|\", flush=True)\n",
|
||||
"\n",
|
||||
" if isinstance(msg, AIMessageChunk):\n",
|
||||
" if first:\n",
|
||||
" gathered = msg\n",
|
||||
" first = False\n",
|
||||
" else:\n",
|
||||
" gathered = gathered + msg\n",
|
||||
"\n",
|
||||
" if msg.tool_call_chunks:\n",
|
||||
" print(gathered.tool_calls)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user