Skip to content

The agent engineering platform.

docs: replace deprecated load_tools in google_finance.ipynb (#31220)

Michael Li395f0572435f
diff --git a/docs/docs/integrations/tools/google_finance.ipynb b/docs/docs/integrations/tools/google_finance.ipynb
index 2a24395615..fa43044a41 100644
--- a/docs/docs/integrations/tools/google_finance.ipynb
+++ b/docs/docs/integrations/tools/google_finance.ipynb
@@ -15,11 +15,19 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Note: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
+ ],
"source": [
- "%pip install --upgrade --quiet google-search-results langchain-community"
+ "%pip install --upgrade --quiet google-search-results langchain-community"
]
},
{
@@ -31,31 +39,39 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
+ "os.environ[\"SERPAPI_API_KEY\"] = \"\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [],
+ "source": [
"from langchain_community.tools.google_finance import GoogleFinanceQueryRun\n",
"from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper\n",
"\n",
- "os.environ[\"SERPAPI_API_KEY\"] = \"[your serpapi key]\"\n",
"tool = GoogleFinanceQueryRun(api_wrapper=GoogleFinanceAPIWrapper())"
]
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "'\\nQuery: Google\\nstock: GOOGL:NASDAQ\\nprice: $161.96\\npercentage: 1.68\\nmovement: Up\\n'"
+ "'\\nQuery: Google\\nstock: GOOGL:NASDAQ\\nprice: $159.96\\npercentage: 0.94\\nmovement: Up\\nus: price = 42210.57, movement = Down\\neurope: price = 23638.56, movement = Up\\nasia: price = 38183.26, movement = Up\\n'"
]
},
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@@ -73,9 +89,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Note: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
+ ],
"source": [
"%pip install --upgrade --quiet langgraph langchain-openai"
]
@@ -89,7 +113,41 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
+ "os.environ[\"SERP_API_KEY\"] = \"\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from langchain.chat_models import init_chat_model\n",
+ "\n",
+ "llm = init_chat_model(\"gpt-4o-mini\", model_provider=\"openai\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from langchain_community.agent_toolkits.load_tools import load_tools\n",
+ "\n",
+ "tools = load_tools([\"google-scholar\", \"google-finance\"], llm=llm)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
@@ -101,8 +159,8 @@
"What is Google's stock?\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"Tool Calls:\n",
- " google_finance (call_u676mJAkdojgkW806ZGSE8mF)\n",
- " Call ID: call_u676mJAkdojgkW806ZGSE8mF\n",
+ " google_finance (call_8m0txCtxNuQaAv9UlomPhSA1)\n",
+ " Call ID: call_8m0txCtxNuQaAv9UlomPhSA1\n",
" Args:\n",
" query: Google\n",
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
@@ -111,28 +169,22 @@
"\n",
"Query: Google\n",
"stock: GOOGL:NASDAQ\n",
- "price: $161.96\n",
- "percentage: 1.68\n",
+ "price: $159.96\n",
+ "percentage: 0.94\n",
"movement: Up\n",
+ "us: price = 42210.57, movement = Down\n",
+ "europe: price = 23638.56, movement = Up\n",
+ "asia: price = 38183.26, movement = Up\n",
"\n",
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
"\n",
- "Google's stock (Ticker: GOOGL) is currently priced at $161.96, showing an increase of 1.68%.\n"
+ "Google's stock, listed as GOOGL on NASDAQ, is currently priced at $159.96, with a movement up by 0.94%.\n"
]
}
],
"source": [
- "import os\n",
- "\n",
- "from langchain.agents import load_tools\n",
- "from langchain.chat_models import init_chat_model\n",
"from langgraph.prebuilt import create_react_agent\n",
"\n",
- "os.environ[\"OPENAI_API_KEY\"] = \"[your openai key]\"\n",
- "os.environ[\"SERP_API_KEY\"] = \"[your serpapi key]\"\n",
- "\n",
- "llm = init_chat_model(\"gpt-4o-mini\", model_provider=\"openai\")\n",
- "tools = load_tools([\"google-scholar\", \"google-finance\"], llm=llm)\n",
"agent = create_react_agent(llm, tools)\n",
"\n",
"events = agent.stream(\n",
@@ -142,11 +194,18 @@
"for event in events:\n",
" event[\"messages\"][-1].pretty_print()"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
"kernelspec": {
- "display_name": "venv",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -160,9 +219,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.12.7"
+ "version": "3.12.4"
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}