mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-17 21:25:46 +02:00
docs: remove warnings/update diagrams (#1746)
* remove warnings/udpate diagrams * replace get_relevant_documents with invoke
This commit is contained in:
@@ -72,15 +72,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 1,
|
||||
"id": "ef5a3ec6-0cd0-4541-ab1b-d63ede22720e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# this is all that's needed for the agent.py\n",
|
||||
"from typing import Literal\n",
|
||||
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
|
||||
"from langchain_core.runnables import ConfigurableField\n",
|
||||
"from langchain_core.tools import tool\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"from langgraph.prebuilt import create_react_agent\n",
|
||||
@@ -884,26 +882,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"execution_count": 2,
|
||||
"id": "94b815e4-1dd2-4999-9e73-6e29836d9160",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph-example-dev/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"Invalid Tool Calls:\n",
|
||||
" get_weather (call_dsr61w9qcahi8CC7LV2S29O3)\n",
|
||||
" Call ID: call_dsr61w9qcahi8CC7LV2S29O3\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",
|
||||
@@ -956,25 +946,16 @@
|
||||
" is\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" currently\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",
|
||||
" Enjoy\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" the\n",
|
||||
"============================\u001b[1m Aimessagechunk Message \u001b[0m============================\n",
|
||||
"\n",
|
||||
" sunshine\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"
|
||||
]
|
||||
}
|
||||
@@ -1055,7 +1036,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.1"
|
||||
"version": "3.11.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -96,7 +96,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 7,
|
||||
"id": "378899a9-3b9a-4748-95b6-eb00e0828677",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -176,7 +176,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 8,
|
||||
"id": "57b27553-21be-43e5-ac48-d1d0a3aa0dca",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -189,13 +189,13 @@
|
||||
"hi! I'm bob\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"It's nice to meet you, Bob! I'm Claude, an AI assistant created by Anthropic. How can I assist you today?\n",
|
||||
"It's nice to meet you, Bob! I'm an AI assistant created by Anthropic. I'm here to help out with any questions or tasks you might have. Please let me know if there's anything I can assist you with.\n",
|
||||
"================================\u001b[1m Human Message \u001b[0m=================================\n",
|
||||
"\n",
|
||||
"what's my name?\n",
|
||||
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
||||
"\n",
|
||||
"Your name is Bob, as you introduced yourself at the beginning of our conversation.\n"
|
||||
"You said your name is Bob.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -225,20 +225,20 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 9,
|
||||
"id": "8a850529-d038-48f7-b5a2-8d4d2923f83a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[HumanMessage(content=\"hi! I'm bob\", id='bc1c6dd2-3bb9-4aa9-b7af-3c6af7e173ea'),\n",
|
||||
" AIMessage(content=\"It's nice to meet you, Bob! I'm Claude, an AI assistant created by Anthropic. How can I assist you today?\", response_metadata={'id': 'msg_01XPSAenmSqK8rX2WgPZHfz7', 'model': 'claude-3-haiku-20240307', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 12, 'output_tokens': 32}}, id='run-1c69af09-adb1-412d-9010-2456e5a555fb-0', usage_metadata={'input_tokens': 12, 'output_tokens': 32, 'total_tokens': 44}),\n",
|
||||
" HumanMessage(content=\"what's my name?\", id='f3c71afe-8ce2-4ed0-991e-65021f03b0a5'),\n",
|
||||
" AIMessage(content='Your name is Bob, as you introduced yourself at the beginning of our conversation.', response_metadata={'id': 'msg_01BPZdwsjuMAbC1YAkqawXaF', 'model': 'claude-3-haiku-20240307', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 52, 'output_tokens': 19}}, id='run-b2eb9137-2f4e-446f-95f5-3d5f621a2cf8-0', usage_metadata={'input_tokens': 52, 'output_tokens': 19, 'total_tokens': 71})]"
|
||||
"[HumanMessage(content=\"hi! I'm bob\", additional_kwargs={}, response_metadata={}, id='db576005-3a60-4b3b-8925-dc602ac1c571'),\n",
|
||||
" AIMessage(content=\"It's nice to meet you, Bob! I'm an AI assistant created by Anthropic. I'm here to help out with any questions or tasks you might have. Please let me know if there's anything I can assist you with.\", additional_kwargs={}, response_metadata={'id': 'msg_01BKAnYxmoC6bQ9PpCuHk8ZT', 'model': 'claude-3-haiku-20240307', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 12, 'output_tokens': 52}}, id='run-3a60c536-b207-4c56-98f3-03f94d49a9e4-0', usage_metadata={'input_tokens': 12, 'output_tokens': 52, 'total_tokens': 64}),\n",
|
||||
" HumanMessage(content=\"what's my name?\", additional_kwargs={}, response_metadata={}, id='2088c465-400b-430b-ad80-fad47dc1f2d6'),\n",
|
||||
" AIMessage(content='You said your name is Bob.', additional_kwargs={}, response_metadata={'id': 'msg_013UWTLTzwZi81vke8mMQ2KP', 'model': 'claude-3-haiku-20240307', 'stop_reason': 'end_turn', 'stop_sequence': None, 'usage': {'input_tokens': 72, 'output_tokens': 10}}, id='run-3a6883be-0c52-4938-af98-e9e7476659eb-0', usage_metadata={'input_tokens': 72, 'output_tokens': 10, 'total_tokens': 82})]"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -258,26 +258,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 10,
|
||||
"id": "df1a0970-7e64-4170-beef-2855d10eef42",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: The class `RemoveMessage` is in beta. It is actively being worked on, so the API may change.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'configurable': {'thread_id': '2',\n",
|
||||
" 'thread_ts': '1ef42d00-d9ad-6f24-8005-feb089654def'}}"
|
||||
" 'checkpoint_ns': '',\n",
|
||||
" 'checkpoint_id': '1ef75157-f251-6a2a-8005-82a86a6593a0'}}"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -81,7 +81,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 1,
|
||||
"id": "e5213193-5a7d-43e7-aeba-fe732bb1cd7a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -124,7 +124,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"id": "2b9d13b1-9d72-48a0-b63a-adc062c06c29",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -134,7 +134,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"id": "3fe36f67-073a-4fd7-a8f8-da196dd46a0d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -159,7 +159,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 4,
|
||||
"id": "bd235fc7-1e5c-4db6-a90b-ea75462ccf7d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -376,19 +376,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 5,
|
||||
"id": "4faf6087-73cc-4957-9a4f-f3509a32a740",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph-postgres/lib/python3.11/site-packages/psycopg_pool/pool_async.py:138: RuntimeWarning: opening the async pool AsyncConnectionPool in the constructor is deprecated and will not be supported anymore in a future release. Please use `await pool.open()`, or use the pool as context manager using: `async with AsyncConnectionPool(...) as pool: `...\n",
|
||||
" warnings.warn(\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from psycopg_pool import AsyncConnectionPool\n",
|
||||
"\n",
|
||||
@@ -401,7 +392,7 @@
|
||||
" checkpointer = AsyncPostgresSaver(pool)\n",
|
||||
"\n",
|
||||
" # NOTE: you need to call .setup() the first time you're using your checkpointer\n",
|
||||
" # await checkpointer.setup()\n",
|
||||
" await checkpointer.setup()\n",
|
||||
"\n",
|
||||
" graph = create_react_agent(model, tools=tools, checkpointer=checkpointer)\n",
|
||||
" config = {\"configurable\": {\"thread_id\": \"4\"}}\n",
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -139,14 +139,6 @@
|
||||
"text": [
|
||||
"{'chunk': 'Four'}|{'chunk': 'score'}|{'chunk': 'and'}|{'chunk': 'seven'}|{'chunk': 'years'}|{'chunk': 'ago'}|{'chunk': 'our'}|{'chunk': 'fathers'}|{'chunk': '...'}|"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 1,
|
||||
"id": "d59234f9-173e-469d-a725-c13e0979663e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -190,7 +190,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"id": "b90941d8-afe4-42ec-9262-9c3b87c3b1ec",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -261,7 +261,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"id": "228260be-1f9a-4195-80e0-9604f8a5dba6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -303,18 +303,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 4,
|
||||
"id": "45c96a79-4147-42e3-89fd-d942b2b49f6c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 1,
|
||||
"id": "083757a9-26d7-481e-8f3d-3e34bcba154b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -117,7 +117,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"id": "2cb38dd9-74d8-456d-9e39-4655f2bf3f37",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -157,7 +157,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"id": "7254310e-7016-45f7-9795-6d52a1160086",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -177,27 +177,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 4,
|
||||
"id": "31fe94ab-80de-4729-843e-5a0fe1bb52c0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.12/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1. Books - A collection of written or printed works bound together with covers. They can be fiction or non-fiction and come in various genres.\n",
|
||||
"1. Books: A shelf is typically used to store books. These can be novels, textbooks, or reference books, and they come in various sizes and genres.\n",
|
||||
"\n",
|
||||
"2. Picture frames - A decorative border for a photograph or artwork, typically made of wood, metal, or plastic. Picture frames are used to display and protect a picture or painting.\n",
|
||||
"2. Picture frames: Picture frames are commonly placed on shelves to display photographs or artwork. They can be made of wood, metal, or plastic and come in different shapes and sizes.\n",
|
||||
"\n",
|
||||
"3. Candles - A cylinder of wax with a central wick that is lit to produce light or fragrance. Candles are often used for decoration, ambiance, or religious ceremonies."
|
||||
"3. Decorative items: Shelves often display decorative items such as vases, figurines, or candles. These items can add a personal touch to a room and enhance its aesthetic appeal."
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -87,7 +87,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "d59234f9-173e-469d-a725-c13e0979663e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -99,7 +99,6 @@
|
||||
" ensure_config,\n",
|
||||
" get_callback_manager_for_config,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"openai_client = AsyncOpenAI()\n",
|
||||
"# define tool schema for openai tool calling\n",
|
||||
"\n",
|
||||
@@ -190,7 +189,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 2,
|
||||
"id": "b756ea32",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -240,7 +239,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "228260be-1f9a-4195-80e0-9604f8a5dba6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -282,29 +281,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 4,
|
||||
"id": "45c96a79-4147-42e3-89fd-d942b2b49f6c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/vadymbarda/.virtualenvs/langgraph/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: This API is in beta and may change in the future.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': 'call_xUcx3IPa8GREPOpjHVj5k9Wx', 'function': {'arguments': '', 'name': 'get_items'}, 'type': 'function'}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': 'get_items', 'args': '', 'id': 'call_xUcx3IPa8GREPOpjHVj5k9Wx', 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': 'get_items', 'args': '', 'id': 'call_xUcx3IPa8GREPOpjHVj5k9Wx', 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '{\"', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [{'name': '', 'args': {}, 'id': None}], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '{\"', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'place', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'place', 'id': None, 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'place', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '\":\"', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': '\":\"', 'id': None, 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '\":\"', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'bed', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'bed', 'id': None, 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'bed', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'room', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'room', 'id': None, 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'room', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '\"}', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': '\"}', 'id': None, 'error': None}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '\"}', 'id': None, 'index': 0}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': 'call_6XZimd7lxnCgoLK1ZM3iAR6S', 'function': {'arguments': '', 'name': 'get_items'}, 'type': 'function'}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [{'name': 'get_items', 'args': {}, 'id': 'call_6XZimd7lxnCgoLK1ZM3iAR6S', 'type': 'tool_call'}], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': [{'name': 'get_items', 'args': '', 'id': 'call_6XZimd7lxnCgoLK1ZM3iAR6S', 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '{\"', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [{'name': '', 'args': {}, 'id': None, 'type': 'tool_call'}], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '{\"', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'place', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'place', 'id': None, 'error': None, 'type': 'invalid_tool_call'}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'place', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '\":\"', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': '\":\"', 'id': None, 'error': None, 'type': 'invalid_tool_call'}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '\":\"', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'bed', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'bed', 'id': None, 'error': None, 'type': 'invalid_tool_call'}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'bed', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'room', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': 'room', 'id': None, 'error': None, 'type': 'invalid_tool_call'}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': 'room', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': '', 'additional_kwargs': {'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '\"}', 'name': None}, 'type': None}]}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [{'name': None, 'args': '\"}', 'id': None, 'error': None, 'type': 'invalid_tool_call'}], 'usage_metadata': None, 'tool_call_chunks': [{'name': None, 'args': '\"}', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]}\n",
|
||||
"LLM token {'content': 'In', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' the', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' bedroom', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
@@ -316,22 +307,11 @@
|
||||
"LLM token {'content': ' shoes', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ',', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' and', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' some', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' dust', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' b', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': 'unn', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': 'ies', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': '.', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' Is', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' there', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' anything', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' else', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' you', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' would', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' like', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' to', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': ' know', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n",
|
||||
"LLM token {'content': '?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n"
|
||||
"LLM token {'content': '.', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'AIMessageChunk', 'name': None, 'id': None, 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None, 'tool_call_chunks': []}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+184
-132
@@ -105,7 +105,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 1,
|
||||
"id": "54c6f319-3966-4f66-aa7b-50e249189111",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -267,7 +267,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 2,
|
||||
"id": "e10c94ba-9daa-4899-97ce-4f28428c2c38",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -299,7 +299,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 3,
|
||||
"id": "48738896-42ac-47eb-b482-0d4d4dd86c87",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -321,29 +321,19 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 4,
|
||||
"id": "55c2aff3-f454-43da-8f45-1a3d46523cd5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/var/folders/td/vzm913rx77x21csd90g63_7c0000gn/T/ipykernel_4902/4209779393.py:9: LangGraphDeprecationWarning: ToolExecutor is deprecated as of version 0.2.0 and will be removed in 0.3.0. Use langgraph.prebuilt.ToolNode instead.\n",
|
||||
" tool_executor = ToolExecutor(tools=tools)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.tools.tavily_search import TavilySearchResults\n",
|
||||
"from langchain_community.utilities.tavily_search import TavilySearchAPIWrapper\n",
|
||||
"\n",
|
||||
"from langgraph.prebuilt.tool_executor import ToolExecutor, ToolInvocation\n",
|
||||
"from langgraph.prebuilt import ToolNode\n",
|
||||
"\n",
|
||||
"search = TavilySearchAPIWrapper()\n",
|
||||
"tavily_tool = TavilySearchResults(api_wrapper=search, max_results=5)\n",
|
||||
"tools = [tavily_tool]\n",
|
||||
"tool_executor = ToolExecutor(tools=tools)"
|
||||
"tool_node = ToolNode(tools=tools)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -359,7 +349,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 5,
|
||||
"id": "ddfd1750-c265-4b29-b505-83b1c5e2d30e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -412,7 +402,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 6,
|
||||
"id": "72fc5363-f0f3-4362-8499-14eb583bd75b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -442,17 +432,17 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 7,
|
||||
"id": "7207f913-a6db-4ef9-a98d-ecb8612b23d5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_mljwYuqZwfWNjUKnatTCC0zI', 'function': {'arguments': '{\"query\": \"lithium pollution research report 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}, {'id': 'call_EYJv1yTvnPoymBcqmbQqoUJG', 'function': {'arguments': '{\"query\": \"lithium mining environmental impact 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}, {'id': 'call_o4vzIZsAeGXQyJPaGRxsSIk3', 'function': {'arguments': '{\"query\": \"lithium battery disposal environmental effects 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 95, 'prompt_tokens': 93, 'total_tokens': 188, 'completion_tokens_details': {'reasoning_tokens': 0}}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_992d1ea92d', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-7924bc82-258a-4f1b-8c9b-87f7512eec7c-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report 2023'}, 'id': 'call_mljwYuqZwfWNjUKnatTCC0zI', 'type': 'tool_call'}, {'name': 'tavily_search_results_json', 'args': {'query': 'lithium mining environmental impact 2023'}, 'id': 'call_EYJv1yTvnPoymBcqmbQqoUJG', 'type': 'tool_call'}, {'name': 'tavily_search_results_json', 'args': {'query': 'lithium battery disposal environmental effects 2023'}, 'id': 'call_o4vzIZsAeGXQyJPaGRxsSIk3', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 95, 'total_tokens': 188})"
|
||||
"AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_xRFx5hZJNyfurW9kWrPAWx15', 'function': {'arguments': '{\"query\":\"lithium pollution research 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}], 'refusal': None}, response_metadata={'token_usage': {'completion_tokens': 25, 'prompt_tokens': 93, 'total_tokens': 118, 'completion_tokens_details': {'reasoning_tokens': 0}}, 'model_name': 'gpt-4o-2024-05-13', 'system_fingerprint': 'fp_a5d11b2ef2', 'finish_reason': 'tool_calls', 'logprobs': None}, id='run-448238e0-f2a7-4be0-b21d-03beb7d22121-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research 2023'}, 'id': 'call_xRFx5hZJNyfurW9kWrPAWx15', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 25, 'total_tokens': 118})"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -476,26 +466,22 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": 46,
|
||||
"id": "5b6b173c-78f5-4ae1-80b3-28c80e68f5c5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the node we will add to the graph\n",
|
||||
"def generate_initial_response(state: TreeState) -> dict:\n",
|
||||
" \"\"\"Generate the initial candidate response.\"\"\"\n",
|
||||
" res = initial_answer_chain.invoke({\"input\": state[\"input\"]})\n",
|
||||
" parsed = parser.invoke(res)\n",
|
||||
" tool_responses = tool_executor.batch(\n",
|
||||
" [ToolInvocation(tool=r[\"type\"], tool_input=r[\"args\"]) for r in parsed]\n",
|
||||
" )\n",
|
||||
" output_messages = [res] + [\n",
|
||||
" ToolMessage(content=json.dumps(resp), tool_call_id=tool_call[\"id\"])\n",
|
||||
" for resp, tool_call in zip(tool_responses, parsed)\n",
|
||||
" ]\n",
|
||||
" tool_responses = [tool_node.invoke(\n",
|
||||
" {\"messages\": [\n",
|
||||
" AIMessage(content=\"\",tool_calls=[{\"name\":r[\"type\"], \"args\":r[\"args\"], 'id':r['id']}]) \n",
|
||||
" ]}\n",
|
||||
" ) for r in parsed]\n",
|
||||
" output_messages = [res] + [tr['messages'][0] for tr in tool_responses]\n",
|
||||
" reflection = reflection_chain.invoke(\n",
|
||||
" {\"input\": state[\"input\"], \"candidate\": output_messages}\n",
|
||||
" )\n",
|
||||
@@ -518,7 +504,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 47,
|
||||
"id": "550bff9a-86aa-43ad-ad98-506e97c122d2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -545,21 +531,21 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 23,
|
||||
"id": "e368e61f-8150-4fd6-b3fd-208d1f0ddc9c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'function': {'arguments': '{\"query\":\"lithium pollution research report 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}], 'refusal': None}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-f5d36271-77a1-49f4-b57b-914baa04e3e1-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report 2023'}, 'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'function': {'arguments': '{\"query\":\"lithium pollution research 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-f5d36271-77a1-49f4-b57b-914baa04e3e1-1', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research 2023'}, 'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'function': {'arguments': '{\"query\":\"lithium pollution research report 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-f5d36271-77a1-49f4-b57b-914baa04e3e1-2', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report 2023'}, 'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'function': {'arguments': '{\"query\":\"lithium pollution research report\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-f5d36271-77a1-49f4-b57b-914baa04e3e1-3', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report'}, 'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'function': {'arguments': '{\"query\":\"lithium pollution research report\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-f5d36271-77a1-49f4-b57b-914baa04e3e1-4', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report'}, 'id': 'call_z2POWhKzUjyEJzAMPhT9OkaY', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216})]"
|
||||
"[AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'function': {'arguments': '{\"query\":\"lithium pollution research 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}], 'refusal': None}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dc7c2f76-1eaf-4c65-8803-7ccededfcf0e-0', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research 2023'}, 'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'function': {'arguments': '{\"query\":\"lithium pollution research report 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dc7c2f76-1eaf-4c65-8803-7ccededfcf0e-1', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report 2023'}, 'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'function': {'arguments': '{\"query\":\"lithium pollution research report\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dc7c2f76-1eaf-4c65-8803-7ccededfcf0e-2', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report'}, 'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'function': {'arguments': '{\"query\":\"lithium pollution research report\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dc7c2f76-1eaf-4c65-8803-7ccededfcf0e-3', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report'}, 'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216}),\n",
|
||||
" AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'function': {'arguments': '{\"query\":\"lithium pollution research report 2023\"}', 'name': 'tavily_search_results_json'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_calls', 'logprobs': None}, id='run-dc7c2f76-1eaf-4c65-8803-7ccededfcf0e-4', tool_calls=[{'name': 'tavily_search_results_json', 'args': {'query': 'lithium pollution research report 2023'}, 'id': 'call_rf2Ns2CW2LppxuUFI4irvRhM', 'type': 'tool_call'}], usage_metadata={'input_tokens': 93, 'output_tokens': 123, 'total_tokens': 216})]"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -582,7 +568,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 48,
|
||||
"id": "d32af859-53e8-46be-8182-7d522be31f54",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -617,16 +603,15 @@
|
||||
" for i, tool_calls in enumerate(parsed)\n",
|
||||
" for tool_call in tool_calls\n",
|
||||
" ]\n",
|
||||
" tool_responses = tool_executor.batch(\n",
|
||||
" [\n",
|
||||
" ToolInvocation(tool=tool_call[\"type\"], tool_input=tool_call[\"args\"])\n",
|
||||
" for _, tool_call in flattened\n",
|
||||
" ]\n",
|
||||
" )\n",
|
||||
" tool_responses = [(i,tool_node.invoke(\n",
|
||||
" {\"messages\":\n",
|
||||
" [AIMessage(content=\"\",tool_calls=[{\"name\":tool_call[\"type\"], \"args\":tool_call[\"args\"], 'id':tool_call['id']}])]\n",
|
||||
" }\n",
|
||||
" )) for i, tool_call in flattened]\n",
|
||||
" collected_responses = defaultdict(list)\n",
|
||||
" for (i, tool_call), resp in zip(flattened, tool_responses):\n",
|
||||
" for i, resp in tool_responses:\n",
|
||||
" collected_responses[i].append(\n",
|
||||
" ToolMessage(content=json.dumps(resp), tool_call_id=tool_call[\"id\"])\n",
|
||||
" resp['messages'][0]\n",
|
||||
" )\n",
|
||||
" output_messages = []\n",
|
||||
" for i, candidate in enumerate(new_candidates):\n",
|
||||
@@ -660,7 +645,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 44,
|
||||
"id": "8aec0f20-f978-4df0-8900-e3a1f0544f6d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -702,7 +687,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"execution_count": 36,
|
||||
"id": "d1674593",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -713,7 +698,7 @@
|
||||
"<IPython.core.display.Image object>"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"execution_count": 36,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -734,7 +719,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"execution_count": 37,
|
||||
"id": "92392fb3-8431-4649-9e78-2cc160e96ec1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -764,7 +749,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 38,
|
||||
"id": "37a9e785-9909-4b56-b9be-da484e3711e1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -772,45 +757,34 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Based on the search results, here is a summary of the top 5 most common birds, their average size and weight, and the oldest recorded instances:\n",
|
||||
"Let's synthesize the information into a coherent table summarizing the average size, weight, and the oldest recorded instance for each of the top 5 most common birds.\n",
|
||||
"\n",
|
||||
"### Most Common Birds\n",
|
||||
"1. **House Sparrow (Passer domesticus)**\n",
|
||||
" - **Average Size**: 16 cm (6.3 in)\n",
|
||||
" - **Average Weight**: 24-39 grams\n",
|
||||
" - **Oldest Recorded Instance**: Approximately 13 years\n",
|
||||
"### Top 5 Most Common Birds\n",
|
||||
"Based on the search results, the top 5 most common birds are:\n",
|
||||
"1. Domestic Chicken\n",
|
||||
"2. House Sparrow\n",
|
||||
"3. European Starling\n",
|
||||
"4. Ring-billed Gull\n",
|
||||
"5. Barn Swallow\n",
|
||||
"\n",
|
||||
"2. **European Starling (Sturnus vulgaris)**\n",
|
||||
" - **Average Size**: 20 cm (8 in)\n",
|
||||
" - **Average Weight**: 75-90 grams\n",
|
||||
" - **Oldest Recorded Instance**: 15 years\n",
|
||||
"### Table: Average Size, Weight, and Oldest Recorded Instance\n",
|
||||
"\n",
|
||||
"3. **Ring-billed Gull (Larus delawarensis)**\n",
|
||||
" - **Average Size**: 49 cm (19 in)\n",
|
||||
" - **Average Weight**: 300-500 grams\n",
|
||||
" - **Oldest Recorded Instance**: 23 years\n",
|
||||
"| Bird | Average Size (cm) | Average Weight (g) | Oldest Recorded Instance |\n",
|
||||
"|--------------------|-------------------|--------------------|-------------------------|\n",
|
||||
"| Domestic Chicken | 40-50 | 1,200-2,500 | ~16 years (Pet record) |\n",
|
||||
"| House Sparrow | 14-18 | 24-40 | 13 years |\n",
|
||||
"| European Starling | 20-23 | 58-100 | 15 years |\n",
|
||||
"| Ring-billed Gull | 48-53 | 300-700 | 23 years |\n",
|
||||
"| Barn Swallow | 15-20 | 17-20 | 16 years |\n",
|
||||
"\n",
|
||||
"4. **Barn Swallow (Hirundo rustica)**\n",
|
||||
" - **Average Size**: 15-20 cm (5.9-7.9 in)\n",
|
||||
" - **Average Weight**: 17-20 grams\n",
|
||||
" - **Oldest Recorded Instance**: 11 years\n",
|
||||
"### Additional Details\n",
|
||||
"- **Domestic Chicken**: The average size and weight can vary significantly based on breed and diet. The oldest recorded pet chicken lived up to 16 years.\n",
|
||||
"- **House Sparrow**: Commonly found in urban areas, with an average lifespan significantly shorter in the wild.\n",
|
||||
"- **European Starling**: Known for their adaptability, starlings have a notable lifespan when not exposed to predators or harsh conditions.\n",
|
||||
"- **Ring-billed Gull**: These gulls are common in North America and have a relatively long lifespan compared to other birds.\n",
|
||||
"- **Barn Swallow**: Known for their migratory habits, these birds have relatively high longevity given their size.\n",
|
||||
"\n",
|
||||
"5. **Red-billed Quelea (Quelea quelea)**\n",
|
||||
" - **Average Size**: 12-13 cm (4.7-5.1 in)\n",
|
||||
" - **Average Weight**: 15-20 grams\n",
|
||||
" - **Oldest Recorded Instance**: 17 years\n",
|
||||
"\n",
|
||||
"### Table Format\n",
|
||||
"\n",
|
||||
"| Bird Species | Average Size | Average Weight | Oldest Recorded Instance |\n",
|
||||
"|-----------------------|--------------|----------------|--------------------------|\n",
|
||||
"| House Sparrow | 16 cm | 24-39 grams | 13 years |\n",
|
||||
"| European Starling | 20 cm | 75-90 grams | 15 years |\n",
|
||||
"| Ring-billed Gull | 49 cm | 300-500 grams | 23 years |\n",
|
||||
"| Barn Swallow | 15-20 cm | 17-20 grams | 11 years |\n",
|
||||
"| Red-billed Quelea | 12-13 cm | 15-20 grams | 17 years |\n",
|
||||
"\n",
|
||||
"This table summarizes the average size and weight, as well as the oldest recorded instance, for each of the top 5 most common birds. These values are based on general data, and specific numbers may vary slightly depending on the source.\n"
|
||||
"This table now provides a structured and comprehensive summary of the requested information.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -822,7 +796,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"execution_count": 49,
|
||||
"id": "1e084037-42e7-4f8e-962d-aaa3f04ab54c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -838,6 +812,12 @@
|
||||
"---\n",
|
||||
"expand\n",
|
||||
"rolled out: 3\n",
|
||||
"---\n",
|
||||
"expand\n",
|
||||
"rolled out: 3\n",
|
||||
"---\n",
|
||||
"expand\n",
|
||||
"rolled out: 3\n",
|
||||
"---\n"
|
||||
]
|
||||
}
|
||||
@@ -855,7 +835,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"execution_count": 50,
|
||||
"id": "d403c1c8-b26b-4d79-87b1-d2d16c1a7673",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -863,54 +843,126 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"To propose an alternate strategy for Magnus Carlsen in a game against Alireza Firouzja, especially if Firouzja opts for the b3 Sicilian system, let's consider the typical play and counterplay options against this opening.\n",
|
||||
"It appears that the specific game moves between Magnus Carlsen and Alireza Firouzja are not readily available in the search results. However, I can provide a general idea of what a typical game between high-level players like Carlsen and Firouzja might look like and propose an alternate strategy based on common chess principles.\n",
|
||||
"\n",
|
||||
"### Overview of the b3 Sicilian\n",
|
||||
"The b3 Sicilian is a rare but strategically rich system where White aims to fianchetto the queen's bishop and gain control over the central squares indirectly. The typical moves might start with:\n",
|
||||
"1. e4 c5\n",
|
||||
"2. Nf3 d6\n",
|
||||
"3. Bb2\n",
|
||||
"### Example Game Moves (Hypothetical)\n",
|
||||
"Here's a hypothetical sequence of moves in a game between Magnus Carlsen and Alireza Firouzja:\n",
|
||||
"\n",
|
||||
"### Potential Strategy and Counterplay for Magnus Carlsen\n",
|
||||
"1. e4 e5\n",
|
||||
"2. Nf3 Nc6\n",
|
||||
"3. Bb5 a6\n",
|
||||
"4. Ba4 Nf6\n",
|
||||
"5. O-O Be7\n",
|
||||
"6. Re1 b5\n",
|
||||
"7. Bb3 d6\n",
|
||||
"8. c3 O-O\n",
|
||||
"9. h3 Nb8\n",
|
||||
"10. d4 Nbd7\n",
|
||||
"11. Nbd2 Bb7\n",
|
||||
"12. Bc2 Re8\n",
|
||||
"13. Nf1 Bf8\n",
|
||||
"14. Ng3 g6\n",
|
||||
"15. a4 c5\n",
|
||||
"16. d5 c4\n",
|
||||
"17. Be3 Qc7\n",
|
||||
"18. Qd2 Nc5\n",
|
||||
"19. Nh2 Bg7\n",
|
||||
"20. Ng4 Nxg4\n",
|
||||
"21. hxg4 Qd7\n",
|
||||
"22. f3 f6\n",
|
||||
"23. Kf2 Qf7\n",
|
||||
"24. Rh1 Rad8\n",
|
||||
"25. Rh3 Bc8\n",
|
||||
"26. Rah1 h6\n",
|
||||
"27. Bxh6 Bxh6\n",
|
||||
"28. Rxh6 Qg7\n",
|
||||
"29. g5 f5\n",
|
||||
"30. exf5 Bxf5\n",
|
||||
"31. Bxf5 gxf5\n",
|
||||
"32. Nh5 Qf7\n",
|
||||
"33. Nf6+ Kf8\n",
|
||||
"34. Rh8+ Ke7\n",
|
||||
"35. Rxe8+ Rxe8\n",
|
||||
"36. Nxe8 Qxe8\n",
|
||||
"37. Rh7+ Kd8\n",
|
||||
"38. g6 Qg8\n",
|
||||
"39. Qg5+ Kc8\n",
|
||||
"40. Qe7 Qd8\n",
|
||||
"41. Qxd8+ Kxd8\n",
|
||||
"42. g7 Kc7\n",
|
||||
"43. g8=Q+ Kb6\n",
|
||||
"44. Qb8+ Ka5\n",
|
||||
"45. Qd8+ Kxa4\n",
|
||||
"46. g4 fxg4\n",
|
||||
"47. fxg4 Kb3\n",
|
||||
"48. g5 Kxb2\n",
|
||||
"49. Qb6 Kxc3\n",
|
||||
"50. Qxc5 dxc5\n",
|
||||
"51. d6 b4\n",
|
||||
"52. d7 b3\n",
|
||||
"53. d8=Q b2\n",
|
||||
"54. Qd1 b1=Q\n",
|
||||
"55. Rxb1 Kxc4\n",
|
||||
"56. Qc1+ Kd5\n",
|
||||
"57. Qxc3 c4\n",
|
||||
"58. Ke3 Kc6\n",
|
||||
"59. Kd4 Kc7\n",
|
||||
"60. Qxc4+ Kd6\n",
|
||||
"61. Qc5+ Ke6\n",
|
||||
"62. Rb6+ Kf7\n",
|
||||
"63. Qc7+ Ke8\n",
|
||||
"64. Rb8#\n",
|
||||
"\n",
|
||||
"1. **Solid Development**:\n",
|
||||
" - **1...e5**: Aiming for control of the center and developing pieces efficiently.\n",
|
||||
" - **2...Nc6**: Developing the knight to a natural square, attacking the e5 pawn and preparing to bring out other pieces.\n",
|
||||
"### Alternate Strategy\n",
|
||||
"\n",
|
||||
"2. **Control the Center**:\n",
|
||||
" - **3...Nf6**: Attacking the e4 pawn and preparing to develop the other knight.\n",
|
||||
" - **4...d5**: If allowed, striking the center with the d5 pawn to challenge White's setup.\n",
|
||||
"If we consider that Magnus Carlsen played the white pieces and used a typical Ruy Lopez opening, an alternate strategy could involve a different opening or a variation within the Ruy Lopez itself. For instance:\n",
|
||||
"\n",
|
||||
"3. **Flexible Pawn Structure**:\n",
|
||||
" - **...a6**: Preparing for a possible b5 expansion or simply controlling the b5 square.\n",
|
||||
" - **...e6**: Preparing to develop the bishop to e7 and castling short.\n",
|
||||
"1. **Alternative Opening: The Italian Game**\n",
|
||||
" - 1. e4 e5\n",
|
||||
" - 2. Nf3 Nc6\n",
|
||||
" - 3. Bc4 Bc5\n",
|
||||
" - 4. c3 Nf6\n",
|
||||
" - 5. d4 exd4\n",
|
||||
" - 6. cxd4 Bb4+\n",
|
||||
" - 7. Nc3 Nxe4\n",
|
||||
" - 8. O-O Bxc3\n",
|
||||
" - 9. d5 Ne7\n",
|
||||
" - 10. Qd3 f5\n",
|
||||
" - 11. bxc3 d6\n",
|
||||
" - 12. Nd4 O-O\n",
|
||||
" - 13. f3 Nc5\n",
|
||||
" - 14. Qc2 f4\n",
|
||||
" - 15. Re1 Ng6\n",
|
||||
" - 16. Ba3 Qg5\n",
|
||||
" - 17. Bxc5 dxc5\n",
|
||||
" - 18. Ne6 Bxe6\n",
|
||||
" - 19. dxe6 Ne7\n",
|
||||
" - 20. Rad1 Rad8\n",
|
||||
" - 21. Rd7 Rxd7\n",
|
||||
" - 22. exd7+ Kh8\n",
|
||||
" - 23. Qe4 Nc6\n",
|
||||
" - 24. Bd3 g6\n",
|
||||
" - 25. Qe8 Kg7\n",
|
||||
" - 26. Bb5 Nd8\n",
|
||||
" - 27. Re7+ Kh6\n",
|
||||
" - 28. Qxf8+ Kh5\n",
|
||||
" - 29. Rxh7#\n",
|
||||
"\n",
|
||||
"4. **Counterattacks**:\n",
|
||||
" - **...Be7** and **...O-O**: Completing development and preparing for potential pawn breaks with ...d5 or ...f5, depending on the position.\n",
|
||||
" - **...Re8**: In some lines, this rook move can support a central break with ...e5 or ...f5.\n",
|
||||
"2. **Variation in the Ruy Lopez:**\n",
|
||||
" - Instead of the main lines, White could opt for the \"Cozy Variation\" or the \"Deferred Steinitz Defense.\"\n",
|
||||
" - For example, after the initial moves:\n",
|
||||
" - 1. e4 e5\n",
|
||||
" - 2. Nf3 Nc6\n",
|
||||
" - 3. Bb5 a6\n",
|
||||
" - 4. Ba4 d6 (Deferred Steinitz Defense)\n",
|
||||
" - 5. c3 Bg4\n",
|
||||
" - 6. h3 Bh5\n",
|
||||
" - 7. d4 exd4\n",
|
||||
" - 8. cxd4 Be7\n",
|
||||
" - 9. Nc3 Nf6\n",
|
||||
" - 10. O-O O-O\n",
|
||||
"\n",
|
||||
"### Sample Move Sequence and Plan\n",
|
||||
"Here is a hypothetical series of moves that Magnus could employ to counter Firouzja's b3 Sicilian:\n",
|
||||
"\n",
|
||||
"1. e4 c5\n",
|
||||
"2. Nf3 d6\n",
|
||||
"3. Bb2 Nf6\n",
|
||||
"4. Nc3 Nc6\n",
|
||||
"5. Bb5 Bd7\n",
|
||||
"6. O-O e6\n",
|
||||
"7. Re1 Be7\n",
|
||||
"8. d4 cxd4\n",
|
||||
"9. Nxd4 O-O\n",
|
||||
"10. Bf1 a6\n",
|
||||
"\n",
|
||||
"In this sequence, Black has developed all pieces harmoniously and is ready to counterattack in the center or on the queenside. The idea is to maintain solid control over the center while preparing for potential pawn breaks to disrupt White's plans.\n",
|
||||
"\n",
|
||||
"### Key Ideas for Magnus:\n",
|
||||
"- **Maintain Flexibility**: Avoid committing to pawn structures too early; respond to White's setup dynamically.\n",
|
||||
"- **Central Breaks**: Look for opportunities to break with ...d5 or ...f5 to open the position in favor of Black.\n",
|
||||
"- **Piece Activity**: Ensure all pieces are well-placed and ready to enter the fray when the position opens up.\n",
|
||||
"\n",
|
||||
"This strategy allows Magnus to maintain a strong, flexible position, ready to counter Firouzja's plans effectively.\n"
|
||||
"By varying the opening or the approach within a given opening, Carlsen could potentially avoid deep preparation by Firouzja and steer the game into less familiar territory for his opponent.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3a0a8450",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Helper Files\n",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -110,7 +110,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 4,
|
||||
"id": "af8379bd-7eae-4ba6-b632-12e89eab9920",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -129,19 +129,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 2,
|
||||
"id": "f9ff6b99-080d-4827-b2cb-f775543d76f5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Downloading: 100%|██████████| 274M/274M [00:43<00:00, 6.38MiB/s] \n",
|
||||
"Verifying: 100%|██████████| 274M/274M [00:00<00:00, 618MiB/s] \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
|
||||
"from langchain_community.document_loaders import WebBaseLoader\n",
|
||||
@@ -183,18 +174,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"id": "7045e064-e666-4aea-9111-6e9d2007f27e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/var/folders/td/vzm913rx77x21csd90g63_7c0000gn/T/ipykernel_7200/1754575056.py:22: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 1.0. Use invoke instead.\n",
|
||||
" docs = retriever.get_relevant_documents(question)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
@@ -225,14 +208,14 @@
|
||||
"\n",
|
||||
"question_router = prompt | llm | JsonOutputParser()\n",
|
||||
"question = \"llm agent memory\"\n",
|
||||
"docs = retriever.get_relevant_documents(question)\n",
|
||||
"docs = retriever.invoke(question)\n",
|
||||
"doc_txt = docs[1].page_content\n",
|
||||
"print(question_router.invoke({\"question\": question}))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 7,
|
||||
"id": "813cdcef-8b75-4214-a2ed-b89077b3d287",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -267,25 +250,17 @@
|
||||
"\n",
|
||||
"retrieval_grader = prompt | llm | JsonOutputParser()\n",
|
||||
"question = \"agent memory\"\n",
|
||||
"docs = retriever.get_relevant_documents(question)\n",
|
||||
"docs = retriever.invoke(question)\n",
|
||||
"doc_txt = docs[1].page_content\n",
|
||||
"print(retrieval_grader.invoke({\"question\": question, \"document\": doc_txt}))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 9,
|
||||
"id": "aeb8b373-0289-4dec-bd4b-8b2701200301",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/isaachershenson/.pyenv/versions/3.11.9/lib/python3.11/site-packages/langsmith/client.py:5301: LangChainBetaWarning: The function `loads` is in beta. It is actively being worked on, so the API may change.\n",
|
||||
" prompt = loads(json.dumps(prompt_object.manifest))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
@@ -526,7 +501,7 @@
|
||||
" question = state[\"question\"]\n",
|
||||
"\n",
|
||||
" # Retrieval\n",
|
||||
" documents = retriever.get_relevant_documents(question)\n",
|
||||
" documents = retriever.invoke(question)\n",
|
||||
" return {\"documents\": documents, \"question\": question}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -360,7 +360,7 @@
|
||||
" question = state[\"question\"]\n",
|
||||
"\n",
|
||||
" # Retrieval\n",
|
||||
" documents = retriever.get_relevant_documents(question)\n",
|
||||
" documents = retriever.invoke(question)\n",
|
||||
" return {\"documents\": documents, \"question\": question}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -445,7 +445,7 @@
|
||||
" question = state[\"question\"]\n",
|
||||
"\n",
|
||||
" # Retrieval\n",
|
||||
" documents = retriever.get_relevant_documents(question)\n",
|
||||
" documents = retriever.invoke(question)\n",
|
||||
" return {\"documents\": documents, \"question\": question}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -446,7 +446,7 @@
|
||||
" question = state[\"question\"]\n",
|
||||
"\n",
|
||||
" # Retrieval\n",
|
||||
" documents = retriever.get_relevant_documents(question)\n",
|
||||
" documents = retriever.invoke(question)\n",
|
||||
" return {\"documents\": documents, \"question\": question}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
Reference in New Issue
Block a user