Skip to content

Commit 395f057

Browse files
docs: replace deprecated load_tools in google_finance.ipynb (#31220)
Thank you for contributing to LangChain! - [x] **PR title**: "package: description" - Where "package" is whichever of langchain, core, etc. is being modified. Use "docs: ..." for purely docs changes, "infra: ..." for CI changes. - Example: "core: add foobar LLM" - [x] **PR message**: ***Delete this entire checklist*** and replace with - **Description:** a description of the change - **Issue:** the issue # it fixes, if applicable - **Dependencies:** any dependencies required for this change - **Twitter handle:** if your PR gets announced, and you'd like a mention, we'll gladly shout you out! - [x] **Add tests and docs**: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ Additional guidelines: - Make sure optional dependencies are imported within a function. - Please do not add dependencies to pyproject.toml files (even optional ones) unless they are required for unit tests. - Most PRs should not touch more than one package. - Changes should be backwards compatible. If no one reviews your PR within a few days, please @-mention one of baskaryan, eyurtsev, ccurme, vbarda, hwchase17.
1 parent a9ee625 commit 395f057

File tree

1 file changed

+87
-28
lines changed

1 file changed

+87
-28
lines changed

docs/docs/integrations/tools/google_finance.ipynb

Lines changed: 87 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": null,
18+
"execution_count": 1,
1919
"metadata": {},
20-
"outputs": [],
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"Note: you may need to restart the kernel to use updated packages.\n"
26+
]
27+
}
28+
],
2129
"source": [
22-
"%pip install --upgrade --quiet google-search-results langchain-community"
30+
"%pip install --upgrade --quiet google-search-results langchain-community"
2331
]
2432
},
2533
{
@@ -31,31 +39,39 @@
3139
},
3240
{
3341
"cell_type": "code",
34-
"execution_count": null,
42+
"execution_count": 2,
3543
"metadata": {},
3644
"outputs": [],
3745
"source": [
3846
"import os\n",
3947
"\n",
48+
"os.environ[\"SERPAPI_API_KEY\"] = \"\""
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 3,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
4057
"from langchain_community.tools.google_finance import GoogleFinanceQueryRun\n",
4158
"from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper\n",
4259
"\n",
43-
"os.environ[\"SERPAPI_API_KEY\"] = \"[your serpapi key]\"\n",
4460
"tool = GoogleFinanceQueryRun(api_wrapper=GoogleFinanceAPIWrapper())"
4561
]
4662
},
4763
{
4864
"cell_type": "code",
49-
"execution_count": 3,
65+
"execution_count": 4,
5066
"metadata": {},
5167
"outputs": [
5268
{
5369
"data": {
5470
"text/plain": [
55-
"'\\nQuery: Google\\nstock: GOOGL:NASDAQ\\nprice: $161.96\\npercentage: 1.68\\nmovement: Up\\n'"
71+
"'\\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'"
5672
]
5773
},
58-
"execution_count": 3,
74+
"execution_count": 4,
5975
"metadata": {},
6076
"output_type": "execute_result"
6177
}
@@ -73,9 +89,17 @@
7389
},
7490
{
7591
"cell_type": "code",
76-
"execution_count": null,
92+
"execution_count": 5,
7793
"metadata": {},
78-
"outputs": [],
94+
"outputs": [
95+
{
96+
"name": "stdout",
97+
"output_type": "stream",
98+
"text": [
99+
"Note: you may need to restart the kernel to use updated packages.\n"
100+
]
101+
}
102+
],
79103
"source": [
80104
"%pip install --upgrade --quiet langgraph langchain-openai"
81105
]
@@ -89,7 +113,41 @@
89113
},
90114
{
91115
"cell_type": "code",
92-
"execution_count": null,
116+
"execution_count": 6,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"import os\n",
121+
"\n",
122+
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
123+
"os.environ[\"SERP_API_KEY\"] = \"\""
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": 7,
129+
"metadata": {},
130+
"outputs": [],
131+
"source": [
132+
"from langchain.chat_models import init_chat_model\n",
133+
"\n",
134+
"llm = init_chat_model(\"gpt-4o-mini\", model_provider=\"openai\")"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 8,
140+
"metadata": {},
141+
"outputs": [],
142+
"source": [
143+
"from langchain_community.agent_toolkits.load_tools import load_tools\n",
144+
"\n",
145+
"tools = load_tools([\"google-scholar\", \"google-finance\"], llm=llm)"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 9,
93151
"metadata": {},
94152
"outputs": [
95153
{
@@ -101,8 +159,8 @@
101159
"What is Google's stock?\n",
102160
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
103161
"Tool Calls:\n",
104-
" google_finance (call_u676mJAkdojgkW806ZGSE8mF)\n",
105-
" Call ID: call_u676mJAkdojgkW806ZGSE8mF\n",
162+
" google_finance (call_8m0txCtxNuQaAv9UlomPhSA1)\n",
163+
" Call ID: call_8m0txCtxNuQaAv9UlomPhSA1\n",
106164
" Args:\n",
107165
" query: Google\n",
108166
"=================================\u001b[1m Tool Message \u001b[0m=================================\n",
@@ -111,28 +169,22 @@
111169
"\n",
112170
"Query: Google\n",
113171
"stock: GOOGL:NASDAQ\n",
114-
"price: $161.96\n",
115-
"percentage: 1.68\n",
172+
"price: $159.96\n",
173+
"percentage: 0.94\n",
116174
"movement: Up\n",
175+
"us: price = 42210.57, movement = Down\n",
176+
"europe: price = 23638.56, movement = Up\n",
177+
"asia: price = 38183.26, movement = Up\n",
117178
"\n",
118179
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
119180
"\n",
120-
"Google's stock (Ticker: GOOGL) is currently priced at $161.96, showing an increase of 1.68%.\n"
181+
"Google's stock, listed as GOOGL on NASDAQ, is currently priced at $159.96, with a movement up by 0.94%.\n"
121182
]
122183
}
123184
],
124185
"source": [
125-
"import os\n",
126-
"\n",
127-
"from langchain.agents import load_tools\n",
128-
"from langchain.chat_models import init_chat_model\n",
129186
"from langgraph.prebuilt import create_react_agent\n",
130187
"\n",
131-
"os.environ[\"OPENAI_API_KEY\"] = \"[your openai key]\"\n",
132-
"os.environ[\"SERP_API_KEY\"] = \"[your serpapi key]\"\n",
133-
"\n",
134-
"llm = init_chat_model(\"gpt-4o-mini\", model_provider=\"openai\")\n",
135-
"tools = load_tools([\"google-scholar\", \"google-finance\"], llm=llm)\n",
136188
"agent = create_react_agent(llm, tools)\n",
137189
"\n",
138190
"events = agent.stream(\n",
@@ -142,11 +194,18 @@
142194
"for event in events:\n",
143195
" event[\"messages\"][-1].pretty_print()"
144196
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"metadata": {},
202+
"outputs": [],
203+
"source": []
145204
}
146205
],
147206
"metadata": {
148207
"kernelspec": {
149-
"display_name": "venv",
208+
"display_name": "Python 3 (ipykernel)",
150209
"language": "python",
151210
"name": "python3"
152211
},
@@ -160,9 +219,9 @@
160219
"name": "python",
161220
"nbconvert_exporter": "python",
162221
"pygments_lexer": "ipython3",
163-
"version": "3.12.7"
222+
"version": "3.12.4"
164223
}
165224
},
166225
"nbformat": 4,
167-
"nbformat_minor": 2
226+
"nbformat_minor": 4
168227
}

0 commit comments

Comments
 (0)