mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-06 09:47:51 +02:00
docs: update HITL how-tos (#875)
This commit is contained in:
@@ -50,7 +50,15 @@
|
||||
"execution_count": 2,
|
||||
"id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ANTHROPIC_API_KEY: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
@@ -100,12 +108,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set up the state\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"\n",
|
||||
"# Set up the tool\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langgraph.prebuilt import ToolExecutor\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"from langgraph.prebuilt import ToolNode\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def search(query: str):\n",
|
||||
@@ -116,22 +126,17 @@
|
||||
" \"It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"\n",
|
||||
" ]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"tools = [search]\n",
|
||||
"tool_executor = ToolExecutor(tools)\n",
|
||||
"tool_node = ToolNode(tools)\n",
|
||||
"\n",
|
||||
"# Set up the model\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"\n",
|
||||
"model = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
|
||||
"model = model.bind_tools(tools)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define nodes and conditional edges\n",
|
||||
"\n",
|
||||
"from langchain_core.messages import ToolMessage\n",
|
||||
"\n",
|
||||
"from langgraph.prebuilt import ToolInvocation\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function that determines whether to continue or not\n",
|
||||
"def should_continue(state):\n",
|
||||
@@ -152,38 +157,12 @@
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [response]}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function to execute tools\n",
|
||||
"def call_tool(state):\n",
|
||||
" messages = state[\"messages\"]\n",
|
||||
" # Based on the continue condition\n",
|
||||
" # we know the last message involves a function call\n",
|
||||
" last_message = messages[-1]\n",
|
||||
" # We construct an ToolInvocation from the function_call\n",
|
||||
" tool_call = last_message.tool_calls[0]\n",
|
||||
" action = ToolInvocation(\n",
|
||||
" tool=tool_call[\"name\"],\n",
|
||||
" tool_input=tool_call[\"args\"],\n",
|
||||
" )\n",
|
||||
" # We call the tool_executor and get back a response\n",
|
||||
" response = tool_executor.invoke(action)\n",
|
||||
" # We use the response to create a ToolMessage\n",
|
||||
" tool_message = ToolMessage(\n",
|
||||
" content=str(response), name=action.tool, tool_call_id=tool_call[\"id\"]\n",
|
||||
" )\n",
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [tool_message]}\n",
|
||||
"\n",
|
||||
"# Build the graph\n",
|
||||
"\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"\n",
|
||||
"# Define a new graph\n",
|
||||
"workflow = StateGraph(MessagesState)\n",
|
||||
"\n",
|
||||
"# Define the two nodes we will cycle between\n",
|
||||
"workflow.add_node(\"agent\", call_model)\n",
|
||||
"workflow.add_node(\"action\", call_tool)\n",
|
||||
"workflow.add_node(\"action\", tool_node)\n",
|
||||
"\n",
|
||||
"# Set the entrypoint as `agent`\n",
|
||||
"# This means that this node is the first one called\n",
|
||||
@@ -215,8 +194,6 @@
|
||||
"workflow.add_edge(\"action\", \"agent\")\n",
|
||||
"\n",
|
||||
"# Set up memory\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"memory = MemorySaver()\n",
|
||||
"\n",
|
||||
"# Finally, we compile it!\n",
|
||||
@@ -240,7 +217,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 5,
|
||||
"id": "cfd140f0-a5a6-4697-8115-322242f197b5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -253,10 +230,10 @@
|
||||
"search for the weather in sf now\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"[{'text': \"Certainly! I'll search for the current weather in San Francisco for you. Let me use the search function to find this information.\", 'type': 'text'}, {'id': 'toolu_017HamT7ubS5RXGCL7CS3t7F', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"[{'text': \"Certainly! I'll search for the current weather in San Francisco for you. Let me use the search function to find this information.\", 'type': 'text'}, {'id': 'toolu_014E4227Tpw958rhbUeJTWXz', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"Tool Calls:\n",
|
||||
" search (toolu_017HamT7ubS5RXGCL7CS3t7F)\n",
|
||||
" Call ID: toolu_017HamT7ubS5RXGCL7CS3t7F\n",
|
||||
" search (toolu_014E4227Tpw958rhbUeJTWXz)\n",
|
||||
" Call ID: toolu_014E4227Tpw958rhbUeJTWXz\n",
|
||||
" Args:\n",
|
||||
" query: current weather in San Francisco\n"
|
||||
]
|
||||
@@ -285,7 +262,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 6,
|
||||
"id": "51923913-20f7-4ee1-b9ba-d01f5fb2869b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -296,16 +273,16 @@
|
||||
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
||||
"Name: search\n",
|
||||
"\n",
|
||||
"[\"It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"]\n",
|
||||
"[\"It's sunny in San Francisco, but you better look out if you're a Gemini \\ud83d\\ude08.\"]\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Based on the search results, I can provide you with information about the current weather in San Francisco:\n",
|
||||
"\n",
|
||||
"The weather in San Francisco right now is sunny. It's a beautiful day in the city!\n",
|
||||
"The weather in San Francisco right now is sunny. \n",
|
||||
"\n",
|
||||
"It's worth noting that the search result included an unusual comment about Gemini, which isn't directly related to the weather. This appears to be an unrelated piece of information or possibly part of a horoscope that was included in the search results.\n",
|
||||
"It's worth noting that the search result includes a playful reference to astrology, suggesting that Geminis should \"look out.\" However, this is likely just a humorous addition and not related to the actual weather conditions.\n",
|
||||
"\n",
|
||||
"If you'd like more specific details about the temperature, wind conditions, or forecast for the coming days, please let me know, and I'd be happy to search for that additional information for you.\n"
|
||||
"Is there anything else you'd like to know about the weather in San Francisco or any other location?\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -331,7 +308,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -50,7 +50,15 @@
|
||||
"execution_count": 2,
|
||||
"id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ANTHROPIC_API_KEY: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
@@ -95,17 +103,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 4,
|
||||
"id": "6098e5cb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set up the state\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"\n",
|
||||
"# Set up the tool\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langgraph.prebuilt import ToolExecutor\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"from langgraph.prebuilt import ToolNode\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def search(query: str):\n",
|
||||
@@ -113,25 +123,20 @@
|
||||
" # This is a placeholder for the actual implementation\n",
|
||||
" # Don't let the LLM know this though 😊\n",
|
||||
" return [\n",
|
||||
" f\"I looked up: {query}. Result: It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"\n",
|
||||
" \"It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"\n",
|
||||
" ]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"tools = [search]\n",
|
||||
"tool_executor = ToolExecutor(tools)\n",
|
||||
"tool_node = ToolNode(tools)\n",
|
||||
"\n",
|
||||
"# Set up the model\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"\n",
|
||||
"model = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
|
||||
"model = model.bind_tools(tools)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define nodes and conditional edges\n",
|
||||
"\n",
|
||||
"from langchain_core.messages import ToolMessage\n",
|
||||
"\n",
|
||||
"from langgraph.prebuilt import ToolInvocation\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function that determines whether to continue or not\n",
|
||||
"def should_continue(state):\n",
|
||||
@@ -152,38 +157,12 @@
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [response]}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function to execute tools\n",
|
||||
"def call_tool(state):\n",
|
||||
" messages = state[\"messages\"]\n",
|
||||
" # Based on the continue condition\n",
|
||||
" # we know the last message involves a function call\n",
|
||||
" last_message = messages[-1]\n",
|
||||
" # We construct an ToolInvocation from the function_call\n",
|
||||
" tool_call = last_message.tool_calls[0]\n",
|
||||
" action = ToolInvocation(\n",
|
||||
" tool=tool_call[\"name\"],\n",
|
||||
" tool_input=tool_call[\"args\"],\n",
|
||||
" )\n",
|
||||
" # We call the tool_executor and get back a response\n",
|
||||
" response = tool_executor.invoke(action)\n",
|
||||
" # We use the response to create a ToolMessage\n",
|
||||
" tool_message = ToolMessage(\n",
|
||||
" content=str(response), name=action.tool, tool_call_id=tool_call[\"id\"]\n",
|
||||
" )\n",
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [tool_message]}\n",
|
||||
"\n",
|
||||
"# Build the graph\n",
|
||||
"\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"\n",
|
||||
"# Define a new graph\n",
|
||||
"workflow = StateGraph(MessagesState)\n",
|
||||
"\n",
|
||||
"# Define the two nodes we will cycle between\n",
|
||||
"workflow.add_node(\"agent\", call_model)\n",
|
||||
"workflow.add_node(\"action\", call_tool)\n",
|
||||
"workflow.add_node(\"action\", tool_node)\n",
|
||||
"\n",
|
||||
"# Set the entrypoint as `agent`\n",
|
||||
"# This means that this node is the first one called\n",
|
||||
@@ -215,8 +194,6 @@
|
||||
"workflow.add_edge(\"action\", \"agent\")\n",
|
||||
"\n",
|
||||
"# Set up memory\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"memory = MemorySaver()\n",
|
||||
"\n",
|
||||
"# Finally, we compile it!\n",
|
||||
@@ -240,7 +217,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": 5,
|
||||
"id": "cfd140f0-a5a6-4697-8115-322242f197b5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -253,10 +230,10 @@
|
||||
"search for the weather in sf now\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"[{'text': \"Certainly! I'll search for the current weather in San Francisco for you. Let me use the search function to find this information.\", 'type': 'text'}, {'id': 'toolu_011s1G2cKjKkkkJTcWb3ze5m', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"[{'text': \"Certainly! I'll search for the current weather in San Francisco for you. Let me use the search function to find this information.\", 'type': 'text'}, {'id': 'toolu_019xfFeuGu6taKqA8unr6VxP', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"Tool Calls:\n",
|
||||
" search (toolu_011s1G2cKjKkkkJTcWb3ze5m)\n",
|
||||
" Call ID: toolu_011s1G2cKjKkkkJTcWb3ze5m\n",
|
||||
" search (toolu_019xfFeuGu6taKqA8unr6VxP)\n",
|
||||
" Call ID: toolu_019xfFeuGu6taKqA8unr6VxP\n",
|
||||
" Args:\n",
|
||||
" query: current weather in San Francisco\n"
|
||||
]
|
||||
@@ -283,7 +260,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 6,
|
||||
"id": "1aa7b1b9-9322-4815-bc0d-eb083870ac15",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -291,10 +268,10 @@
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'configurable': {'thread_id': '3',\n",
|
||||
" 'thread_ts': '1ef3102f-e345-627e-8002-bfdc440474fe'}}"
|
||||
" 'thread_ts': '1ef355a9-ab59-6102-8002-56ee1c266b09'}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -329,7 +306,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 7,
|
||||
"id": "a3fcf2bd-f881-49fe-b20e-ad16e6819bc6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -338,10 +315,10 @@
|
||||
"text/plain": [
|
||||
"[{'name': 'search',\n",
|
||||
" 'args': {'query': 'current weather in SF'},\n",
|
||||
" 'id': 'toolu_011s1G2cKjKkkkJTcWb3ze5m'}]"
|
||||
" 'id': 'toolu_019xfFeuGu6taKqA8unr6VxP'}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 21,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -363,7 +340,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"execution_count": 8,
|
||||
"id": "51923913-20f7-4ee1-b9ba-d01f5fb2869b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -374,16 +351,16 @@
|
||||
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
||||
"Name: search\n",
|
||||
"\n",
|
||||
"[\"I looked up: current weather in SF. Result: It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"]\n",
|
||||
"[\"It's sunny in San Francisco, but you better look out if you're a Gemini \\ud83d\\ude08.\"]\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Based on the search results, I can provide you with information about the current weather in San Francisco:\n",
|
||||
"Based on the search results, I can provide you with information about the current weather in San Francisco (SF):\n",
|
||||
"\n",
|
||||
"The weather in San Francisco is currently sunny. This means it's a clear day with plenty of sunshine, which is quite typical for San Francisco, especially during certain times of the year.\n",
|
||||
"The weather in San Francisco is currently sunny. This means it's a clear day with plenty of sunshine.\n",
|
||||
"\n",
|
||||
"It's worth noting that San Francisco's weather can be quite variable, even within the city itself, due to its unique microclimate and geography. While it's sunny now, it's always a good idea to be prepared for potential changes in weather, as the city is known for its foggy conditions that can roll in quickly, especially near the coast.\n",
|
||||
"However, I should note that the search result includes an unusual additional comment about astrology, which isn't typically part of a standard weather report. The mention of Geminis is likely not relevant to the actual weather conditions.\n",
|
||||
"\n",
|
||||
"The search result also included an unusual astrological reference about Geminis, but that's not relevant to the weather information you requested. If you need any more specific details about the weather, such as temperature, wind speed, or forecast for the coming days, please let me know, and I'd be happy to search for that information as well.\n"
|
||||
"If you'd like more specific details about the temperature, humidity, or wind conditions in San Francisco, I'd be happy to perform another search with a more focused query. Just let me know if you need any additional weather information!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -417,7 +394,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -57,7 +57,15 @@
|
||||
"execution_count": 2,
|
||||
"id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ANTHROPIC_API_KEY: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
@@ -102,26 +110,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 4,
|
||||
"id": "f5319e01",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/harrisonchase/.pyenv/versions/3.11.1/envs/permchain/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: The method `ChatAnthropic.bind_tools` is in beta. It is actively being worked on, so the API may change.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set up the state\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"\n",
|
||||
"# Set up the tool\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langgraph.prebuilt import ToolExecutor\n",
|
||||
"from langgraph.graph import MessagesState\n",
|
||||
"from langgraph.prebuilt import ToolNode\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def search(query: str):\n",
|
||||
@@ -129,25 +130,20 @@
|
||||
" # This is a placeholder for the actual implementation\n",
|
||||
" # Don't let the LLM know this though 😊\n",
|
||||
" return [\n",
|
||||
" f\"I looked up: {query}. Result: It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"\n",
|
||||
" \"It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"\n",
|
||||
" ]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"tools = [search]\n",
|
||||
"tool_executor = ToolExecutor(tools)\n",
|
||||
"tool_node = ToolNode(tools)\n",
|
||||
"\n",
|
||||
"# Set up the model\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
"\n",
|
||||
"model = ChatAnthropic(model=\"claude-3-5-sonnet-20240620\")\n",
|
||||
"model = model.bind_tools(tools)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define nodes and conditional edges\n",
|
||||
"\n",
|
||||
"from langchain_core.messages import ToolMessage\n",
|
||||
"\n",
|
||||
"from langgraph.prebuilt import ToolInvocation\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function that determines whether to continue or not\n",
|
||||
"def should_continue(state):\n",
|
||||
@@ -168,38 +164,12 @@
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [response]}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function to execute tools\n",
|
||||
"def call_tool(state):\n",
|
||||
" messages = state[\"messages\"]\n",
|
||||
" # Based on the continue condition\n",
|
||||
" # we know the last message involves a function call\n",
|
||||
" last_message = messages[-1]\n",
|
||||
" # We construct an ToolInvocation from the function_call\n",
|
||||
" tool_call = last_message.tool_calls[0]\n",
|
||||
" action = ToolInvocation(\n",
|
||||
" tool=tool_call[\"name\"],\n",
|
||||
" tool_input=tool_call[\"args\"],\n",
|
||||
" )\n",
|
||||
" # We call the tool_executor and get back a response\n",
|
||||
" response = tool_executor.invoke(action)\n",
|
||||
" # We use the response to create a ToolMessage\n",
|
||||
" tool_message = ToolMessage(\n",
|
||||
" content=str(response), name=action.tool, tool_call_id=tool_call[\"id\"]\n",
|
||||
" )\n",
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [tool_message]}\n",
|
||||
"\n",
|
||||
"# Build the graph\n",
|
||||
"\n",
|
||||
"from langgraph.graph import END, StateGraph\n",
|
||||
"\n",
|
||||
"# Define a new graph\n",
|
||||
"workflow = StateGraph(MessagesState)\n",
|
||||
"\n",
|
||||
"# Define the two nodes we will cycle between\n",
|
||||
"workflow.add_node(\"agent\", call_model)\n",
|
||||
"workflow.add_node(\"action\", call_tool)\n",
|
||||
"workflow.add_node(\"action\", tool_node)\n",
|
||||
"\n",
|
||||
"# Set the entrypoint as `agent`\n",
|
||||
"# This means that this node is the first one called\n",
|
||||
@@ -231,13 +201,14 @@
|
||||
"workflow.add_edge(\"action\", \"agent\")\n",
|
||||
"\n",
|
||||
"# Set up memory\n",
|
||||
"from langgraph.checkpoint.memory import MemorySaver\n",
|
||||
"\n",
|
||||
"memory = MemorySaver()\n",
|
||||
"\n",
|
||||
"# Finally, we compile it!\n",
|
||||
"# This compiles it into a LangChain Runnable,\n",
|
||||
"# meaning you can use it as you would any other runnable\n",
|
||||
"\n",
|
||||
"# We add in `interrupt_before=[\"action\"]`\n",
|
||||
"# This will add a breakpoint before the `action` node is called\n",
|
||||
"app = workflow.compile(checkpointer=memory)"
|
||||
]
|
||||
},
|
||||
@@ -253,7 +224,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"id": "cfd140f0-a5a6-4697-8115-322242f197b5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -266,31 +237,30 @@
|
||||
"Use the search tool to look up the weather in SF\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"Tool Calls:\n",
|
||||
" search (toolu_01M1JGmPF1wjJRxY2SYsCYS7)\n",
|
||||
" Call ID: toolu_01M1JGmPF1wjJRxY2SYsCYS7\n",
|
||||
" search (toolu_01Bpq6yiKqk9moPuGYKdLr8r)\n",
|
||||
" Call ID: toolu_01Bpq6yiKqk9moPuGYKdLr8r\n",
|
||||
" Args:\n",
|
||||
" query: weather in San Francisco\n",
|
||||
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
||||
"Name: search\n",
|
||||
"\n",
|
||||
"[\"I looked up: weather in San Francisco. Result: It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"]\n",
|
||||
"[\"It's sunny in San Francisco, but you better look out if you're a Gemini \\ud83d\\ude08.\"]\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Based on the search results, I can provide you with information about the weather in San Francisco:\n",
|
||||
"\n",
|
||||
"The current weather in San Francisco is sunny. This means it's a clear day with plenty of sunshine, which is quite common for San Francisco, especially during certain times of the year.\n",
|
||||
"The current weather in San Francisco is sunny. This is great news for residents and visitors who want to enjoy outdoor activities or explore the city.\n",
|
||||
"\n",
|
||||
"However, there's an interesting additional note in the search result that seems to be unrelated to the weather itself. It mentions something about Geminis, which appears to be a reference to astrology. This part of the result doesn't provide any relevant weather information, so we'll focus on the actual weather report.\n",
|
||||
"However, there's an interesting and somewhat humorous addition to the weather report. It mentions, \"but you better look out if you're a Gemini 😈.\" This appears to be a playful reference to astrology, suggesting that Geminis might have some challenges despite the good weather. Of course, this is not a scientific weather prediction and is likely just a fun addition to the report.\n",
|
||||
"\n",
|
||||
"To summarize:\n",
|
||||
"- Current weather in San Francisco: Sunny\n",
|
||||
"- Sky conditions: Clear\n",
|
||||
"1. The weather in San Francisco is currently sunny.\n",
|
||||
"2. It's a good day for outdoor activities.\n",
|
||||
"3. There's a playful astrological warning for Geminis, but this shouldn't be taken seriously in terms of actual weather conditions.\n",
|
||||
"\n",
|
||||
"Keep in mind that San Francisco's weather can change quickly due to its unique microclimate, influenced by the bay and ocean. Even on sunny days, it's always a good idea to be prepared for potential fog or cooler temperatures, especially near the coast or in the evenings.\n",
|
||||
"\n",
|
||||
"Is there any specific information about the San Francisco weather you'd like to know more about, such as temperature, wind conditions, or forecast for the coming days?\n"
|
||||
"Is there anything else you'd like to know about the weather in San Francisco or any other location?\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -315,7 +285,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 6,
|
||||
"id": "8578a66d-6489-4e03-8c23-fd0530278455",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -323,15 +293,15 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"StateSnapshot(values={'messages': []}, next=('__start__',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef3103d-f96d-65f2-bfff-f32837888e44'}}, metadata={'source': 'input', 'step': -1, 'writes': {'messages': [HumanMessage(content='Use the search tool to look up the weather in SF')]}}, created_at='2024-06-23T01:56:57.764168+00:00', parent_config=None)\n",
|
||||
"StateSnapshot(values={'messages': []}, next=('__start__',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef355ac-b80d-6e18-bfff-c903ebc4bdfd'}}, metadata={'source': 'input', 'step': -1, 'writes': {'messages': [HumanMessage(content='Use the search tool to look up the weather in SF')]}}, created_at='2024-06-28T14:29:14.932371+00:00', parent_config=None)\n",
|
||||
"--\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18')]}, next=('agent',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef3103d-f974-6b0e-8000-99038b849969'}}, metadata={'source': 'loop', 'step': 0, 'writes': None}, created_at='2024-06-23T01:56:57.767174+00:00', parent_config=None)\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577')]}, next=('agent',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef355ac-b810-60dc-8000-a9c67d8cc5e0'}}, metadata={'source': 'loop', 'step': 0, 'writes': None}, created_at='2024-06-28T14:29:14.933257+00:00', parent_config=None)\n",
|
||||
"--\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_01JGRvXQBPCGbXxHHHj5mSQs', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 82}}, id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7'}])]}, next=('action',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef3103e-072f-68f2-8001-29ebe76a1f5e'}}, metadata={'source': 'loop', 'step': 1, 'writes': {'agent': {'messages': [AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_01JGRvXQBPCGbXxHHHj5mSQs', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 82}}, id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7'}])]}}}, created_at='2024-06-23T01:56:59.206868+00:00', parent_config=None)\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_011ae64fY2jEcfS8kgrt4Fn9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 81}}, id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r'}], usage_metadata={'input_tokens': 363, 'output_tokens': 81, 'total_tokens': 444})]}, next=('action',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef355ac-c6b1-6028-8001-82bd095f9a87'}}, metadata={'source': 'loop', 'step': 1, 'writes': {'agent': {'messages': [AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_011ae64fY2jEcfS8kgrt4Fn9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 81}}, id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r'}], usage_metadata={'input_tokens': 363, 'output_tokens': 81, 'total_tokens': 444})]}}}, created_at='2024-06-28T14:29:16.467180+00:00', parent_config=None)\n",
|
||||
"--\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_01JGRvXQBPCGbXxHHHj5mSQs', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 82}}, id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7'}]), ToolMessage(content='[\"I looked up: weather in San Francisco. Result: It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini 😈.\"]', name='search', id='0e86ac06-d5a2-47f6-b6ff-6f221eac9f68', tool_call_id='toolu_01M1JGmPF1wjJRxY2SYsCYS7')]}, next=('agent',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef3103e-0739-6762-8002-1ff85304da93'}}, metadata={'source': 'loop', 'step': 2, 'writes': {'action': {'messages': [ToolMessage(content='[\"I looked up: weather in San Francisco. Result: It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini 😈.\"]', name='search', id='0e86ac06-d5a2-47f6-b6ff-6f221eac9f68', tool_call_id='toolu_01M1JGmPF1wjJRxY2SYsCYS7')]}}}, created_at='2024-06-23T01:56:59.210922+00:00', parent_config=None)\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_011ae64fY2jEcfS8kgrt4Fn9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 81}}, id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r'}], usage_metadata={'input_tokens': 363, 'output_tokens': 81, 'total_tokens': 444}), ToolMessage(content='[\"It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini \\\\ud83d\\\\ude08.\"]', name='search', id='b5aa87cb-335a-4ee0-8809-381e33d0f02e', tool_call_id='toolu_01Bpq6yiKqk9moPuGYKdLr8r')]}, next=('agent',), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef355ac-c6ba-63a8-8002-48d076c3c4b7'}}, metadata={'source': 'loop', 'step': 2, 'writes': {'action': {'messages': [ToolMessage(content='[\"It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini \\\\ud83d\\\\ude08.\"]', name='search', id='b5aa87cb-335a-4ee0-8809-381e33d0f02e', tool_call_id='toolu_01Bpq6yiKqk9moPuGYKdLr8r')]}}}, created_at='2024-06-28T14:29:16.470958+00:00', parent_config=None)\n",
|
||||
"--\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_01JGRvXQBPCGbXxHHHj5mSQs', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 82}}, id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7'}]), ToolMessage(content='[\"I looked up: weather in San Francisco. Result: It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini 😈.\"]', name='search', id='0e86ac06-d5a2-47f6-b6ff-6f221eac9f68', tool_call_id='toolu_01M1JGmPF1wjJRxY2SYsCYS7'), AIMessage(content=\"Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This means it's a clear day with plenty of sunshine, which is quite common for San Francisco, especially during certain times of the year.\\n\\nHowever, there's an interesting additional note in the search result that seems to be unrelated to the weather itself. It mentions something about Geminis, which appears to be a reference to astrology. This part of the result doesn't provide any relevant weather information, so we'll focus on the actual weather report.\\n\\nTo summarize:\\n- Current weather in San Francisco: Sunny\\n- Sky conditions: Clear\\n\\nKeep in mind that San Francisco's weather can change quickly due to its unique microclimate, influenced by the bay and ocean. Even on sunny days, it's always a good idea to be prepared for potential fog or cooler temperatures, especially near the coast or in the evenings.\\n\\nIs there any specific information about the San Francisco weather you'd like to know more about, such as temperature, wind conditions, or forecast for the coming days?\", response_metadata={'id': 'msg_01Y79Nyvq6vP57sDCZugtXHq', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 492, 'output_tokens': 239}}, id='run-ca257cec-308d-4860-8254-cf26118b56c2-0')]}, next=(), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef3103e-312a-6e54-8003-bfa2548298b2'}}, metadata={'source': 'loop', 'step': 3, 'writes': {'agent': {'messages': [AIMessage(content=\"Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This means it's a clear day with plenty of sunshine, which is quite common for San Francisco, especially during certain times of the year.\\n\\nHowever, there's an interesting additional note in the search result that seems to be unrelated to the weather itself. It mentions something about Geminis, which appears to be a reference to astrology. This part of the result doesn't provide any relevant weather information, so we'll focus on the actual weather report.\\n\\nTo summarize:\\n- Current weather in San Francisco: Sunny\\n- Sky conditions: Clear\\n\\nKeep in mind that San Francisco's weather can change quickly due to its unique microclimate, influenced by the bay and ocean. Even on sunny days, it's always a good idea to be prepared for potential fog or cooler temperatures, especially near the coast or in the evenings.\\n\\nIs there any specific information about the San Francisco weather you'd like to know more about, such as temperature, wind conditions, or forecast for the coming days?\", response_metadata={'id': 'msg_01Y79Nyvq6vP57sDCZugtXHq', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 492, 'output_tokens': 239}}, id='run-ca257cec-308d-4860-8254-cf26118b56c2-0')]}}}, created_at='2024-06-23T01:57:03.608964+00:00', parent_config=None)\n",
|
||||
"StateSnapshot(values={'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577'), AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_011ae64fY2jEcfS8kgrt4Fn9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 81}}, id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r'}], usage_metadata={'input_tokens': 363, 'output_tokens': 81, 'total_tokens': 444}), ToolMessage(content='[\"It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini \\\\ud83d\\\\ude08.\"]', name='search', id='b5aa87cb-335a-4ee0-8809-381e33d0f02e', tool_call_id='toolu_01Bpq6yiKqk9moPuGYKdLr8r'), AIMessage(content='Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This is great news for residents and visitors who want to enjoy outdoor activities or explore the city.\\n\\nHowever, there\\'s an interesting and somewhat humorous addition to the weather report. It mentions, \"but you better look out if you\\'re a Gemini 😈.\" This appears to be a playful reference to astrology, suggesting that Geminis might have some challenges despite the good weather. Of course, this is not a scientific weather prediction and is likely just a fun addition to the report.\\n\\nTo summarize:\\n1. The weather in San Francisco is currently sunny.\\n2. It\\'s a good day for outdoor activities.\\n3. There\\'s a playful astrological warning for Geminis, but this shouldn\\'t be taken seriously in terms of actual weather conditions.\\n\\nIs there anything else you\\'d like to know about the weather in San Francisco or any other location?', response_metadata={'id': 'msg_01NWeLrkQRLiGsVsxnepzq3p', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 486, 'output_tokens': 217}}, id='run-09f1b7d5-50ec-4f00-a31b-c4dec858b312-0', usage_metadata={'input_tokens': 486, 'output_tokens': 217, 'total_tokens': 703})]}, next=(), config={'configurable': {'thread_id': '1', 'thread_ts': '1ef355ac-f0f5-6942-8003-b79974988738'}}, metadata={'source': 'loop', 'step': 3, 'writes': {'agent': {'messages': [AIMessage(content='Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This is great news for residents and visitors who want to enjoy outdoor activities or explore the city.\\n\\nHowever, there\\'s an interesting and somewhat humorous addition to the weather report. It mentions, \"but you better look out if you\\'re a Gemini 😈.\" This appears to be a playful reference to astrology, suggesting that Geminis might have some challenges despite the good weather. Of course, this is not a scientific weather prediction and is likely just a fun addition to the report.\\n\\nTo summarize:\\n1. The weather in San Francisco is currently sunny.\\n2. It\\'s a good day for outdoor activities.\\n3. There\\'s a playful astrological warning for Geminis, but this shouldn\\'t be taken seriously in terms of actual weather conditions.\\n\\nIs there anything else you\\'d like to know about the weather in San Francisco or any other location?', response_metadata={'id': 'msg_01NWeLrkQRLiGsVsxnepzq3p', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 486, 'output_tokens': 217}}, id='run-09f1b7d5-50ec-4f00-a31b-c4dec858b312-0', usage_metadata={'input_tokens': 486, 'output_tokens': 217, 'total_tokens': 703})]}}}, created_at='2024-06-28T14:29:20.899258+00:00', parent_config=None)\n",
|
||||
"--\n"
|
||||
]
|
||||
}
|
||||
@@ -356,7 +326,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 7,
|
||||
"id": "02250602-8c4a-4fb5-bd6c-d0b9046e8699",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -366,18 +336,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 8,
|
||||
"id": "21e7fc18-6fd9-4e11-a84b-e0325c9640c8",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18'),\n",
|
||||
" AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_01JGRvXQBPCGbXxHHHj5mSQs', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 82}}, id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01M1JGmPF1wjJRxY2SYsCYS7'}])]}"
|
||||
"{'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577'),\n",
|
||||
" AIMessage(content=[{'text': \"Certainly! I'll use the search tool to look up the weather in San Francisco for you. Let me do that right away.\", 'type': 'text'}, {'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r', 'input': {'query': 'weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}], response_metadata={'id': 'msg_011ae64fY2jEcfS8kgrt4Fn9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'tool_use', 'stop_sequence': None, 'usage': {'input_tokens': 363, 'output_tokens': 81}}, id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0', tool_calls=[{'name': 'search', 'args': {'query': 'weather in San Francisco'}, 'id': 'toolu_01Bpq6yiKqk9moPuGYKdLr8r'}], usage_metadata={'input_tokens': 363, 'output_tokens': 81, 'total_tokens': 444})]}"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -388,7 +358,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": 9,
|
||||
"id": "d4b01634-0041-4632-8d1f-5464580e54f5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -398,7 +368,7 @@
|
||||
"('action',)"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -417,7 +387,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 10,
|
||||
"id": "e986f94f-706f-4b6f-b3c4-f95483b9e9b8",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -425,8 +395,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'messages': [ToolMessage(content='[\"I looked up: weather in San Francisco. Result: It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini 😈.\"]', name='search', tool_call_id='toolu_01M1JGmPF1wjJRxY2SYsCYS7')]}\n",
|
||||
"{'messages': [AIMessage(content='Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This means it\\'s a clear day with plenty of sunshine, which is quite typical for San Francisco, especially during certain times of the year.\\n\\nHowever, there\\'s an interesting and somewhat humorous addition to the weather report. It mentions, \"but you better look out if you\\'re a Gemini 😈.\" This appears to be a playful reference to astrology, suggesting that Geminis might have some challenges or interesting experiences today. Of course, this is not a scientific weather forecast and is likely just added for entertainment value.\\n\\nTo summarize:\\n1. The weather in San Francisco is currently sunny.\\n2. It\\'s a good day to be outside and enjoy the clear skies.\\n3. The playful astrological reference for Geminis is just for fun and not part of the actual weather conditions.\\n\\nIs there anything else you\\'d like to know about the weather in San Francisco or any other information you need?', response_metadata={'id': 'msg_01Dv7fci5B1w6QZH7kwa8iV5', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 492, 'output_tokens': 228}}, id='run-56df996d-5d30-4d25-a224-7fe153f86494-0')]}\n"
|
||||
"{'messages': [ToolMessage(content='[\"It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini \\\\ud83d\\\\ude08.\"]', name='search', tool_call_id='toolu_01Bpq6yiKqk9moPuGYKdLr8r')]}\n",
|
||||
"{'messages': [AIMessage(content='Based on the search results, I can provide you with information about the weather in San Francisco:\\n\\nThe current weather in San Francisco is sunny. This is great news for residents and visitors who want to enjoy outdoor activities or explore the city.\\n\\nHowever, there\\'s an interesting and somewhat humorous addition to the weather report. It mentions, \"but you better look out if you\\'re a Gemini 😈.\" This appears to be a playful reference to astrology, suggesting that Geminis might have some challenges despite the good weather. Of course, this is not a scientific weather prediction and is likely just a fun addition to the weather report.\\n\\nTo summarize:\\n1. The weather in San Francisco is currently sunny.\\n2. It\\'s a good day for outdoor activities.\\n3. There\\'s a playful astrological reference for Geminis, but this shouldn\\'t be taken as actual weather information.\\n\\nIs there anything else you\\'d like to know about the weather in San Francisco or any other location?', response_metadata={'id': 'msg_01S4uzzxbGwvsk1vfoLJAD7Z', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 486, 'output_tokens': 214}}, id='run-570bd10f-4007-4b33-8c29-44b9a19b6978-0', usage_metadata={'input_tokens': 486, 'output_tokens': 214, 'total_tokens': 700})]}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -450,7 +420,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 11,
|
||||
"id": "fbd5ad3b-5363-4ab7-ac63-b04668bc998f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -477,7 +447,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": 12,
|
||||
"id": "9a92d3da-62e2-45a2-8545-e4f6a64e0ffe",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -485,8 +455,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{'messages': [ToolMessage(content='[\"I looked up: current weather in SF. Result: It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini 😈.\"]', name='search', tool_call_id='toolu_01M1JGmPF1wjJRxY2SYsCYS7')]}\n",
|
||||
"{'messages': [AIMessage(content='Thank you for providing me with the search results. Based on the information I received, I can tell you about the current weather in San Francisco:\\n\\n1. It\\'s currently sunny in San Francisco.\\n\\nThis means you can expect clear skies and pleasant weather conditions. It\\'s a great day to be outdoors or enjoy activities in the city.\\n\\nInterestingly, the search result also included an unusual astrological reference:\\n\\n2. There was a playful warning for Geminis, suggesting they should \"look out.\"\\n\\nPlease note that the astrological comment is likely just for fun and not related to the actual weather conditions. It\\'s probably part of a horoscope or similar content that was included in the search results.\\n\\nIs there anything else you\\'d like to know about the weather in San Francisco or any other information you need?', response_metadata={'id': 'msg_01NG3SwButddYs3ui3KxuUU9', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 492, 'output_tokens': 178}}, id='run-019ec434-9e81-4335-a463-7dbb97d6a318-0')]}\n"
|
||||
"{'messages': [ToolMessage(content='[\"It\\'s sunny in San Francisco, but you better look out if you\\'re a Gemini \\\\ud83d\\\\ude08.\"]', name='search', tool_call_id='toolu_01Bpq6yiKqk9moPuGYKdLr8r')]}\n",
|
||||
"{'messages': [AIMessage(content=\"Based on the search results, I can provide you with information about the current weather in San Francisco (SF):\\n\\nThe weather in San Francisco is currently sunny. This means it's a clear day with plenty of sunshine, which is great for outdoor activities or simply enjoying the city's beautiful views.\\n\\nIt's worth noting that San Francisco's weather can be quite variable, even within the city itself, due to its unique geography and microclimates. While it's sunny now, it's always a good idea to be prepared for potential changes, as the city is known for its foggy conditions, especially in certain areas and during specific times of the day.\\n\\nThe search result also includes a playful reference to astrology, mentioning Geminis. However, this is likely just a humorous addition and not related to the actual weather conditions.\\n\\nIs there any specific information about the weather in San Francisco that you'd like to know more about, such as temperature, wind conditions, or forecast for the coming days?\", response_metadata={'id': 'msg_01AoFmmzZxbMLuu3npVXJKG7', 'model': 'claude-3-5-sonnet-20240620', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 486, 'output_tokens': 211}}, id='run-ccb9e786-c23e-4017-bf29-8405f17cec9f-0', usage_metadata={'input_tokens': 486, 'output_tokens': 211, 'total_tokens': 697})]}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -506,7 +476,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 13,
|
||||
"id": "01abb480-df55-4eba-a2be-cf9372b60b54",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -527,7 +497,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": 14,
|
||||
"id": "1a7cfcd4-289e-419e-8b49-dfaef4f88641",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -537,18 +507,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 15,
|
||||
"id": "5198f9c1-d2d4-458a-993d-3caa55810b1e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='8948e4e1-0d86-4dfd-929d-48da47fc0a18'),\n",
|
||||
" AIMessage(content='its warm!', id='run-3ec0086e-31c5-43e3-86cc-badaf14dd001-0')]}"
|
||||
"{'messages': [HumanMessage(content='Use the search tool to look up the weather in SF', id='9558b3e7-fa30-4e8b-9587-d58ae3491577'),\n",
|
||||
" AIMessage(content='its warm!', id='run-cfef25ca-d1be-4e79-8798-3bb9a7002287-0')]}"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -559,7 +529,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 16,
|
||||
"id": "5d89d55d-db84-4c2d-828b-64a29a69947b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -569,7 +539,7 @@
|
||||
"()"
|
||||
]
|
||||
},
|
||||
"execution_count": 21,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -611,7 +581,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -58,7 +58,15 @@
|
||||
"execution_count": 2,
|
||||
"id": "c903a1cf-2977-4e2d-ad7d-8b3946821d89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdin",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ANTHROPIC_API_KEY: ········\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import getpass\n",
|
||||
"import os\n",
|
||||
@@ -103,7 +111,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 4,
|
||||
"id": "f5319e01",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -116,7 +124,7 @@
|
||||
"# We'll also have one \"fake\" tool - a \"ask_human\" tool\n",
|
||||
"# Here we define any ACTUAL tools\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langgraph.prebuilt import ToolExecutor\n",
|
||||
"from langgraph.prebuilt import ToolNode\n",
|
||||
"\n",
|
||||
"@tool\n",
|
||||
"def search(query: str):\n",
|
||||
@@ -129,7 +137,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"tools = [search]\n",
|
||||
"tool_executor = ToolExecutor(tools)\n",
|
||||
"tool_node = ToolNode(tools)\n",
|
||||
"\n",
|
||||
"# Set up the model\n",
|
||||
"from langchain_anthropic import ChatAnthropic\n",
|
||||
@@ -183,26 +191,6 @@
|
||||
" return {\"messages\": [response]}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function to execute tools\n",
|
||||
"def call_tool(state):\n",
|
||||
" messages = state[\"messages\"]\n",
|
||||
" # Based on the continue condition\n",
|
||||
" # we know the last message involves a function call\n",
|
||||
" last_message = messages[-1]\n",
|
||||
" # We construct an ToolInvocation from the function_call\n",
|
||||
" tool_call = last_message.tool_calls[0]\n",
|
||||
" action = ToolInvocation(\n",
|
||||
" tool=tool_call[\"name\"],\n",
|
||||
" tool_input=tool_call[\"args\"],\n",
|
||||
" )\n",
|
||||
" # We call the tool_executor and get back a response\n",
|
||||
" response = tool_executor.invoke(action)\n",
|
||||
" # We use the response to create a ToolMessage\n",
|
||||
" tool_message = ToolMessage(\n",
|
||||
" content=str(response), name=action.tool, tool_call_id=tool_call[\"id\"]\n",
|
||||
" )\n",
|
||||
" # We return a list, because this will get added to the existing list\n",
|
||||
" return {\"messages\": [tool_message]}\n",
|
||||
"\n",
|
||||
"# We define a fake node to ask the human\n",
|
||||
"def ask_human(state):\n",
|
||||
@@ -217,7 +205,7 @@
|
||||
"\n",
|
||||
"# Define the three nodes we will cycle between\n",
|
||||
"workflow.add_node(\"agent\", call_model)\n",
|
||||
"workflow.add_node(\"action\", call_tool)\n",
|
||||
"workflow.add_node(\"action\", tool_node)\n",
|
||||
"workflow.add_node(\"ask_human\", ask_human)\n",
|
||||
"\n",
|
||||
"# Set the entrypoint as `agent`\n",
|
||||
@@ -278,7 +266,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 5,
|
||||
"id": "cfd140f0-a5a6-4697-8115-322242f197b5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -291,10 +279,10 @@
|
||||
"Use the search tool to ask the user where they are, then look up the weather there\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"[{'text': \"Certainly! I'll use the AskHuman function to ask the user where they are, and then I'll use the search function to look up the weather for that location. Let's start by asking the user about their location.\", 'type': 'text'}, {'id': 'toolu_01VbhJQTHN44bzfWHwPh2KK6', 'input': {'question': 'Where are you currently located?'}, 'name': 'AskHuman', 'type': 'tool_use'}]\n",
|
||||
"[{'text': \"Certainly! I'll use the AskHuman function to ask the user about their location, and then use the search function to look up the weather. Let's start by asking the user where they are.\", 'type': 'text'}, {'id': 'toolu_01HgfTkwJ2pZhPuCuunBYUq4', 'input': {'question': 'Where are you currently located?'}, 'name': 'AskHuman', 'type': 'tool_use'}]\n",
|
||||
"Tool Calls:\n",
|
||||
" AskHuman (toolu_01VbhJQTHN44bzfWHwPh2KK6)\n",
|
||||
" Call ID: toolu_01VbhJQTHN44bzfWHwPh2KK6\n",
|
||||
" AskHuman (toolu_01HgfTkwJ2pZhPuCuunBYUq4)\n",
|
||||
" Call ID: toolu_01HgfTkwJ2pZhPuCuunBYUq4\n",
|
||||
" Args:\n",
|
||||
" question: Where are you currently located?\n"
|
||||
]
|
||||
@@ -321,7 +309,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": 6,
|
||||
"id": "63598092-d565-4170-9773-e092d345f8c1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -331,7 +319,7 @@
|
||||
"('agent',)"
|
||||
]
|
||||
},
|
||||
"execution_count": 19,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -370,7 +358,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 7,
|
||||
"id": "a9f599b5-1a55-406b-a76b-f52b3ca06975",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -380,25 +368,23 @@
|
||||
"text": [
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"[{'text': \"Thank you for letting me know that you're in San Francisco. Now, I'll use the search function to look up the weather in San Francisco.\", 'type': 'text'}, {'id': 'toolu_013cvwkiiDBrHV9w1e97SvqB', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"[{'text': \"Thank you for letting me know that you're in San Francisco. Now, I'll use the search function to look up the weather in San Francisco.\", 'type': 'text'}, {'id': 'toolu_01BKzfQfHBSUcgTbz7c4gs8w', 'input': {'query': 'current weather in San Francisco'}, 'name': 'search', 'type': 'tool_use'}]\n",
|
||||
"Tool Calls:\n",
|
||||
" search (toolu_013cvwkiiDBrHV9w1e97SvqB)\n",
|
||||
" Call ID: toolu_013cvwkiiDBrHV9w1e97SvqB\n",
|
||||
" search (toolu_01BKzfQfHBSUcgTbz7c4gs8w)\n",
|
||||
" Call ID: toolu_01BKzfQfHBSUcgTbz7c4gs8w\n",
|
||||
" Args:\n",
|
||||
" query: current weather in San Francisco\n",
|
||||
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
||||
"Name: search\n",
|
||||
"\n",
|
||||
"[\"I looked up: current weather in San Francisco. Result: It's sunny in San Francisco, but you better look out if you're a Gemini 😈.\"]\n",
|
||||
"[\"I looked up: current weather in San Francisco. Result: It's sunny in San Francisco, but you better look out if you're a Gemini \\ud83d\\ude08.\"]\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Based on the search results, I can provide you with information about the current weather in San Francisco:\n",
|
||||
"\n",
|
||||
"The weather in San Francisco is currently sunny. This is great news for outdoor activities and enjoying the city's beautiful scenery.\n",
|
||||
"The weather in San Francisco is currently sunny. \n",
|
||||
"\n",
|
||||
"However, there was an unusual and somewhat humorous addition to the weather report, mentioning something about Geminis. This appears to be a joke or possibly a reference to an astrological forecast mixed in with the weather information. It's not typical for weather reports to include astrological references, so we should focus on the factual weather information, which is that it's sunny in San Francisco.\n",
|
||||
"\n",
|
||||
"Is there anything else you'd like to know about the weather or San Francisco in general?\n"
|
||||
"It's worth noting that the search result included a playful comment about Geminis, but that's not directly related to the weather information you requested. If you need more specific details about the temperature, humidity, or forecast, please let me know, and I'd be happy to search for more detailed weather information for San Francisco.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -432,7 +418,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user