|
15 | 15 | },
|
16 | 16 | {
|
17 | 17 | "cell_type": "code",
|
18 |
| - "execution_count": null, |
| 18 | + "execution_count": 1, |
19 | 19 | "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 | + ], |
21 | 29 | "source": [
|
22 |
| - "%pip install --upgrade --quiet google-search-results langchain-community" |
| 30 | + "%pip install --upgrade --quiet google-search-results langchain-community" |
23 | 31 | ]
|
24 | 32 | },
|
25 | 33 | {
|
|
31 | 39 | },
|
32 | 40 | {
|
33 | 41 | "cell_type": "code",
|
34 |
| - "execution_count": null, |
| 42 | + "execution_count": 2, |
35 | 43 | "metadata": {},
|
36 | 44 | "outputs": [],
|
37 | 45 | "source": [
|
38 | 46 | "import os\n",
|
39 | 47 | "\n",
|
| 48 | + "os.environ[\"SERPAPI_API_KEY\"] = \"\"" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "code", |
| 53 | + "execution_count": 3, |
| 54 | + "metadata": {}, |
| 55 | + "outputs": [], |
| 56 | + "source": [ |
40 | 57 | "from langchain_community.tools.google_finance import GoogleFinanceQueryRun\n",
|
41 | 58 | "from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper\n",
|
42 | 59 | "\n",
|
43 |
| - "os.environ[\"SERPAPI_API_KEY\"] = \"[your serpapi key]\"\n", |
44 | 60 | "tool = GoogleFinanceQueryRun(api_wrapper=GoogleFinanceAPIWrapper())"
|
45 | 61 | ]
|
46 | 62 | },
|
47 | 63 | {
|
48 | 64 | "cell_type": "code",
|
49 |
| - "execution_count": 3, |
| 65 | + "execution_count": 4, |
50 | 66 | "metadata": {},
|
51 | 67 | "outputs": [
|
52 | 68 | {
|
53 | 69 | "data": {
|
54 | 70 | "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'" |
56 | 72 | ]
|
57 | 73 | },
|
58 |
| - "execution_count": 3, |
| 74 | + "execution_count": 4, |
59 | 75 | "metadata": {},
|
60 | 76 | "output_type": "execute_result"
|
61 | 77 | }
|
|
73 | 89 | },
|
74 | 90 | {
|
75 | 91 | "cell_type": "code",
|
76 |
| - "execution_count": null, |
| 92 | + "execution_count": 5, |
77 | 93 | "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 | + ], |
79 | 103 | "source": [
|
80 | 104 | "%pip install --upgrade --quiet langgraph langchain-openai"
|
81 | 105 | ]
|
|
89 | 113 | },
|
90 | 114 | {
|
91 | 115 | "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, |
93 | 151 | "metadata": {},
|
94 | 152 | "outputs": [
|
95 | 153 | {
|
|
101 | 159 | "What is Google's stock?\n",
|
102 | 160 | "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
103 | 161 | "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", |
106 | 164 | " Args:\n",
|
107 | 165 | " query: Google\n",
|
108 | 166 | "=================================\u001b[1m Tool Message \u001b[0m=================================\n",
|
|
111 | 169 | "\n",
|
112 | 170 | "Query: Google\n",
|
113 | 171 | "stock: GOOGL:NASDAQ\n",
|
114 |
| - "price: $161.96\n", |
115 |
| - "percentage: 1.68\n", |
| 172 | + "price: $159.96\n", |
| 173 | + "percentage: 0.94\n", |
116 | 174 | "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", |
117 | 178 | "\n",
|
118 | 179 | "==================================\u001b[1m Ai Message \u001b[0m==================================\n",
|
119 | 180 | "\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" |
121 | 182 | ]
|
122 | 183 | }
|
123 | 184 | ],
|
124 | 185 | "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", |
129 | 186 | "from langgraph.prebuilt import create_react_agent\n",
|
130 | 187 | "\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", |
136 | 188 | "agent = create_react_agent(llm, tools)\n",
|
137 | 189 | "\n",
|
138 | 190 | "events = agent.stream(\n",
|
|
142 | 194 | "for event in events:\n",
|
143 | 195 | " event[\"messages\"][-1].pretty_print()"
|
144 | 196 | ]
|
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "code", |
| 200 | + "execution_count": null, |
| 201 | + "metadata": {}, |
| 202 | + "outputs": [], |
| 203 | + "source": [] |
145 | 204 | }
|
146 | 205 | ],
|
147 | 206 | "metadata": {
|
148 | 207 | "kernelspec": {
|
149 |
| - "display_name": "venv", |
| 208 | + "display_name": "Python 3 (ipykernel)", |
150 | 209 | "language": "python",
|
151 | 210 | "name": "python3"
|
152 | 211 | },
|
|
160 | 219 | "name": "python",
|
161 | 220 | "nbconvert_exporter": "python",
|
162 | 221 | "pygments_lexer": "ipython3",
|
163 |
| - "version": "3.12.7" |
| 222 | + "version": "3.12.4" |
164 | 223 | }
|
165 | 224 | },
|
166 | 225 | "nbformat": 4,
|
167 |
| - "nbformat_minor": 2 |
| 226 | + "nbformat_minor": 4 |
168 | 227 | }
|
0 commit comments