felixmortas commited on
Commit
0693e1a
·
1 Parent(s): d4c21c3

try gemini

Browse files
Files changed (2) hide show
  1. react_agent_test.ipynb +50 -27
  2. requirements.txt +2 -1
react_agent_test.ipynb CHANGED
@@ -10,25 +10,27 @@
10
  "import os\n",
11
  "from dotenv import load_dotenv \n",
12
  "from langchain_mistralai import ChatMistralAI\n",
 
13
  "from langchain_core.messages import SystemMessage, HumanMessage\n",
14
  "from langgraph.prebuilt import create_react_agent\n",
15
  "\n",
16
  "from custom_tools import custom_tools\n",
17
  "\n",
18
  "load_dotenv() \n",
19
- "os.environ[\"MISTRAL_API_KEY\"] = os.getenv(\"MISTRAL\")"
 
20
  ]
21
  },
22
  {
23
  "cell_type": "code",
24
- "execution_count": 10,
25
  "id": "7df8bade",
26
  "metadata": {},
27
  "outputs": [],
28
  "source": [
29
  "# LLM Configuration\n",
30
- "llm = ChatMistralAI(\n",
31
- " model=\"mistral-small-latest\",\n",
32
  " temperature=0,\n",
33
  " max_retries=5\n",
34
  ")\n",
@@ -47,7 +49,7 @@
47
  },
48
  {
49
  "cell_type": "code",
50
- "execution_count": 15,
51
  "id": "0ce2dd73",
52
  "metadata": {},
53
  "outputs": [
@@ -55,7 +57,7 @@
55
  "name": "stdout",
56
  "output_type": "stream",
57
  "text": [
58
- "a, b, e\n"
59
  ]
60
  }
61
  ],
@@ -84,18 +86,18 @@
84
  },
85
  {
86
  "cell_type": "code",
87
- "execution_count": 16,
88
  "id": "17dc251b",
89
  "metadata": {},
90
  "outputs": [
91
  {
92
  "data": {
93
  "text/plain": [
94
- "{'messages': [HumanMessage(content='\\n\"task_id\": \"6f37996b-2ac7-44b0-8e68-6d28256631b4\",\\n \"question\": \"Given this table defining * on the set S = {a, b, c, d, e}\\n\\n|*|a|b|c|d|e|\\n|---|---|---|---|---|---|\\n|a|a|b|c|b|d|\\n|b|b|c|a|e|c|\\n|c|c|a|b|b|a|\\n|d|b|e|b|e|d|\\n|e|d|b|a|d|c|\\n\\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.\",\\n \"Level\": \"1\",\\n \"file_name\": \"\"\\n ', additional_kwargs={}, response_metadata={}, id='456b861d-e60e-403b-be65-3e043565a7e6'),\n",
95
- " AIMessage(content=\"To determine if the operation \\\\( * \\\\) is commutative, we need to check if \\\\( x * y = y * x \\\\) for all \\\\( x, y \\\\in S \\\\). If we find any pair \\\\( (x, y) \\\\) such that \\\\( x * y \\\\neq y * x \\\\), then \\\\( * \\\\) is not commutative, and the subset \\\\( \\\\{x, y\\\\} \\\\) will be part of the counter-example.\\n\\nLet's analyze the table step by step:\\n\\n1. \\\\( a * b = b \\\\) and \\\\( b * a = c \\\\). Since \\\\( b \\\\neq c \\\\), \\\\( * \\\\) is not commutative.\\n2. \\\\( a * c = c \\\\) and \\\\( c * a = c \\\\). Here \\\\( a * c = c * a \\\\), so no counter-example here.\\n3. \\\\( a * d = b \\\\) and \\\\( d * a = b \\\\). Here \\\\( a * d = d * a \\\\), so no counter-example here.\\n4. \\\\( a * e = d \\\\) and \\\\( e * a = d \\\\). Here \\\\( a * e = e * a \\\\), so no counter-example here.\\n5. \\\\( b * c = a \\\\) and \\\\( c * b = a \\\\). Here \\\\( b * c = c * b \\\\), so no counter-example here.\\n6. \\\\( b * d = e \\\\) and \\\\( d * b = e \\\\). Here \\\\( b * d = d * b \\\\), so no counter-example here.\\n7. \\\\( b * e = c \\\\) and \\\\( e * b = b \\\\). Since \\\\( c \\\\neq b \\\\), \\\\( * \\\\) is not commutative.\\n8. \\\\( c * d = b \\\\) and \\\\( d * c = b \\\\). Here \\\\( c * d = d * c \\\\), so no counter-example here.\\n9. \\\\( c * e = a \\\\) and \\\\( e * c = a \\\\). Here \\\\( c * e = e * c \\\\), so no counter-example here.\\n10. \\\\( d * e = d \\\\) and \\\\( e * d = d \\\\). Here \\\\( d * e = e * d \\\\), so no counter-example here.\\n\\nFrom the analysis, the pairs \\\\( (a, b) \\\\) and \\\\( (b, e) \\\\) are counter-examples that prove \\\\( * \\\\) is not commutative.\\n\\nFINAL ANSWER: a, b, e\", additional_kwargs={}, response_metadata={'token_usage': {'prompt_tokens': 1467, 'total_tokens': 1981, 'completion_tokens': 514}, 'model_name': 'mistral-small-latest', 'model': 'mistral-small-latest', 'finish_reason': 'stop'}, id='run--54102f8a-ae50-4a89-a96f-e2b1b1178a24-0', usage_metadata={'input_tokens': 1467, 'output_tokens': 514, 'total_tokens': 1981})]}"
96
  ]
97
  },
98
- "execution_count": 16,
99
  "metadata": {},
100
  "output_type": "execute_result"
101
  }
@@ -114,7 +116,7 @@
114
  },
115
  {
116
  "cell_type": "code",
117
- "execution_count": 3,
118
  "id": "4b7ca6fa",
119
  "metadata": {},
120
  "outputs": [
@@ -122,7 +124,7 @@
122
  "name": "stdout",
123
  "output_type": "stream",
124
  "text": [
125
- "Qd1#\n"
126
  ]
127
  }
128
  ],
@@ -181,10 +183,18 @@
181
  },
182
  {
183
  "cell_type": "code",
184
- "execution_count": null,
185
  "id": "69cf16b8",
186
  "metadata": {},
187
- "outputs": [],
 
 
 
 
 
 
 
 
188
  "source": [
189
  "hum_prompt = \"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?\"\n",
190
  "\n",
@@ -233,10 +243,18 @@
233
  },
234
  {
235
  "cell_type": "code",
236
- "execution_count": null,
237
  "id": "8eb59a66",
238
  "metadata": {},
239
- "outputs": [],
 
 
 
 
 
 
 
 
240
  "source": [
241
  "hum_prompt = \"\"\"{'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.', 'Level': '1', 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'}\"\"\"\n",
242
  "\n",
@@ -250,27 +268,24 @@
250
  " {\"messages\": HumanMessage(content=hum_prompt)}\n",
251
  ")\n",
252
  "\n",
253
- "print(response[\"messages\"][-1].content.split(\"FINAL ANSWER: \")[-1])"
 
254
  ]
255
  },
256
  {
257
  "cell_type": "code",
258
- "execution_count": 14,
259
  "id": "2ca6f955",
260
  "metadata": {},
261
  "outputs": [
262
  {
263
  "data": {
264
  "text/plain": [
265
- "{'messages': [HumanMessage(content=\"{'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.', 'Level': '1', 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'}\", additional_kwargs={}, response_metadata={}, id='b30a3914-ea49-43d1-be67-dc9fb8ae72ba'),\n",
266
- " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'zlVnoOJVW', 'function': {'name': 'read_excel', 'arguments': '{\"task_id\": \"7bd855d8-463d-4ed5-93ca-5fe35145f733\", \"file_path\": \"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\"}'}, 'index': 0}]}, response_metadata={'token_usage': {'prompt_tokens': 1120, 'total_tokens': 1219, 'completion_tokens': 99}, 'model_name': 'mistral-large-latest', 'model': 'mistral-large-latest', 'finish_reason': 'tool_calls'}, id='run--fef0ff1c-7680-4fc1-9c2e-05d702f7ce54-0', tool_calls=[{'name': 'read_excel', 'args': {'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'file_path': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'}, 'id': 'zlVnoOJVW', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1120, 'output_tokens': 99, 'total_tokens': 1219}),\n",
267
- " ToolMessage(content=' Location Burgers Hot Dogs Salads Fries Ice Cream Soda\\n Pinebrook 1594 1999 2002 2005 1977 1980\\n Wharvton 1983 2008 2014 2015 2017 2018\\n Sagrada 2019 2022 2022 2023 2021 2019\\n Algrimand 1958 1971 1982 1989 1998 2009\\n Marztep 2015 2016 2018 2019 2021 2022\\nSan Cecelia 2011 2010 2012 2013 2015 2016\\n Pimento 2017 1999 2001 2003 1969 2967\\n Tinseles 1967 1969 1982 1994 2005 2006\\n Rosdale 2007 2009 2021 1989 2005 2011', name='read_excel', id='276bb0ab-b6d8-40a8-8c95-8b19c53bdf86', tool_call_id='zlVnoOJVW'),\n",
268
- " AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'DDJAAo0N4', 'function': {'name': 'sum_pandas_df', 'arguments': '{\"task_id\": \"7bd855d8-463d-4ed5-93ca-5fe35145f733\", \"file_name\": \"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx\", \"column_names\": [\"Burgers\", \"Hot Dogs\", \"Salads\", \"Fries\", \"Ice Cream\"]}'}, 'index': 0}]}, response_metadata={'token_usage': {'prompt_tokens': 1579, 'total_tokens': 1710, 'completion_tokens': 131}, 'model_name': 'mistral-large-latest', 'model': 'mistral-large-latest', 'finish_reason': 'tool_calls'}, id='run--5f838a6e-0ad5-4667-80a4-f15a71da05a8-0', tool_calls=[{'name': 'sum_pandas_df', 'args': {'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx', 'column_names': ['Burgers', 'Hot Dogs', 'Salads', 'Fries', 'Ice Cream']}, 'id': 'DDJAAo0N4', 'type': 'tool_call'}], usage_metadata={'input_tokens': 1579, 'output_tokens': 131, 'total_tokens': 1710}),\n",
269
- " ToolMessage(content='89706', name='sum_pandas_df', id='a7e43a29-7c6b-45c4-93be-78757094c520', tool_call_id='DDJAAo0N4'),\n",
270
- " AIMessage(content='To find the total sales made from food (excluding drinks), we need to sum the sales of Burgers, Hot Dogs, Salads, Fries, and Ice Cream across all locations.\\n\\nThe total sales from food items are calculated as follows:\\n\\n- Burgers: 1594 + 1983 + 2019 + 1958 + 2015 + 2011 + 2017 + 1967 + 2007 = 16571\\n- Hot Dogs: 1999 + 2008 + 2022 + 1971 + 2016 + 2010 + 1999 + 1969 + 2009 = 16993\\n- Salads: 2002 + 2014 + 2022 + 1982 + 2018 + 2012 + 2001 + 1982 + 2021 = 17054\\n- Fries: 2005 + 2015 + 2023 + 1989 + 2019 + 2013 + 2003 + 1994 + 1989 = 17060\\n- Ice Cream: 1977 + 2017 + 2021 + 1998 + 2021 + 2015 + 1969 + 2005 + 2005 = 17028\\n\\nAdding these totals together:\\n\\nTotal food sales = 16571 + 16993 + 17054 + 17060 + 17028 = 89706\\n\\nFINAL ANSWER: 89706.00 USD', additional_kwargs={}, response_metadata={'token_usage': {'prompt_tokens': 1739, 'total_tokens': 2197, 'completion_tokens': 458}, 'model_name': 'mistral-large-latest', 'model': 'mistral-large-latest', 'finish_reason': 'stop'}, id='run--4431fdb9-25e6-4e67-9924-38b61e37ed92-0', usage_metadata={'input_tokens': 1739, 'output_tokens': 458, 'total_tokens': 2197})]}"
271
  ]
272
  },
273
- "execution_count": 14,
274
  "metadata": {},
275
  "output_type": "execute_result"
276
  }
@@ -289,10 +304,18 @@
289
  },
290
  {
291
  "cell_type": "code",
292
- "execution_count": null,
293
  "id": "f80a471d",
294
  "metadata": {},
295
- "outputs": [],
 
 
 
 
 
 
 
 
296
  "source": [
297
  "hum_prompt = \"\"\"{'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2', 'question': 'Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\\n\\nWhat does Teal\\'c say in response to the question \"Isn\\'t that hot?\"', 'Level': '1', 'file_name': ''}\"\"\"\n",
298
  "\n",
 
10
  "import os\n",
11
  "from dotenv import load_dotenv \n",
12
  "from langchain_mistralai import ChatMistralAI\n",
13
+ "from langchain_google_genai import ChatGoogleGenerativeAI\n",
14
  "from langchain_core.messages import SystemMessage, HumanMessage\n",
15
  "from langgraph.prebuilt import create_react_agent\n",
16
  "\n",
17
  "from custom_tools import custom_tools\n",
18
  "\n",
19
  "load_dotenv() \n",
20
+ "os.environ[\"MISTRAL_API_KEY\"] = os.getenv(\"MISTRAL\")\n",
21
+ "os.environ[\"GOOGLE_API_KEY\"] = os.getenv(\"GOOGLE\")"
22
  ]
23
  },
24
  {
25
  "cell_type": "code",
26
+ "execution_count": 2,
27
  "id": "7df8bade",
28
  "metadata": {},
29
  "outputs": [],
30
  "source": [
31
  "# LLM Configuration\n",
32
+ "llm = ChatGoogleGenerativeAI( # ChatMistralAI\n",
33
+ " model=\"gemini-2.5-flash\", # mistral-small-latest\n",
34
  " temperature=0,\n",
35
  " max_retries=5\n",
36
  ")\n",
 
49
  },
50
  {
51
  "cell_type": "code",
52
+ "execution_count": 3,
53
  "id": "0ce2dd73",
54
  "metadata": {},
55
  "outputs": [
 
57
  "name": "stdout",
58
  "output_type": "stream",
59
  "text": [
60
+ "b,e\n"
61
  ]
62
  }
63
  ],
 
86
  },
87
  {
88
  "cell_type": "code",
89
+ "execution_count": 4,
90
  "id": "17dc251b",
91
  "metadata": {},
92
  "outputs": [
93
  {
94
  "data": {
95
  "text/plain": [
96
+ "{'messages': [HumanMessage(content='\\n\"task_id\": \"6f37996b-2ac7-44b0-8e68-6d28256631b4\",\\n \"question\": \"Given this table defining * on the set S = {a, b, c, d, e}\\n\\n|*|a|b|c|d|e|\\n|---|---|---|---|---|---|\\n|a|a|b|c|b|d|\\n|b|b|c|a|e|c|\\n|c|c|a|b|b|a|\\n|d|b|e|b|e|d|\\n|e|d|b|a|d|c|\\n\\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.\",\\n \"Level\": \"1\",\\n \"file_name\": \"\"\\n ', additional_kwargs={}, response_metadata={}, id='17e37204-e33b-4a13-8a35-5b843358f3a4'),\n",
97
+ " AIMessage(content='FINAL ANSWER: b,e', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.5-flash', 'safety_ratings': []}, id='run--30a88cdb-6076-4b29-822e-c5ded1b678e9-0', usage_metadata={'input_tokens': 1436, 'output_tokens': 6, 'total_tokens': 1864, 'input_token_details': {'cache_read': 0}, 'output_token_details': {'reasoning': 422}})]}"
98
  ]
99
  },
100
+ "execution_count": 4,
101
  "metadata": {},
102
  "output_type": "execute_result"
103
  }
 
116
  },
117
  {
118
  "cell_type": "code",
119
+ "execution_count": 6,
120
  "id": "4b7ca6fa",
121
  "metadata": {},
122
  "outputs": [
 
124
  "name": "stdout",
125
  "output_type": "stream",
126
  "text": [
127
+ "Qh4+\n"
128
  ]
129
  }
130
  ],
 
183
  },
184
  {
185
  "cell_type": "code",
186
+ "execution_count": 7,
187
  "id": "69cf16b8",
188
  "metadata": {},
189
+ "outputs": [
190
+ {
191
+ "name": "stdout",
192
+ "output_type": "stream",
193
+ "text": [
194
+ "Claus\n"
195
+ ]
196
+ }
197
+ ],
198
  "source": [
199
  "hum_prompt = \"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?\"\n",
200
  "\n",
 
243
  },
244
  {
245
  "cell_type": "code",
246
+ "execution_count": 8,
247
  "id": "8eb59a66",
248
  "metadata": {},
249
+ "outputs": [
250
+ {
251
+ "name": "stdout",
252
+ "output_type": "stream",
253
+ "text": [
254
+ "\n"
255
+ ]
256
+ }
257
+ ],
258
  "source": [
259
  "hum_prompt = \"\"\"{'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.', 'Level': '1', 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'}\"\"\"\n",
260
  "\n",
 
268
  " {\"messages\": HumanMessage(content=hum_prompt)}\n",
269
  ")\n",
270
  "\n",
271
+ "print(response[\"messages\"][-1].content.split(\"FINAL ANSWER: \")[-1])\n",
272
+ "# 89 706"
273
  ]
274
  },
275
  {
276
  "cell_type": "code",
277
+ "execution_count": 9,
278
  "id": "2ca6f955",
279
  "metadata": {},
280
  "outputs": [
281
  {
282
  "data": {
283
  "text/plain": [
284
+ "{'messages': [HumanMessage(content=\"{'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733', 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.', 'Level': '1', 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'}\", additional_kwargs={}, response_metadata={}, id='62ca610d-ba20-4584-81bd-232fe6b6ab66'),\n",
285
+ " AIMessage(content='', additional_kwargs={}, response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'MAX_TOKENS', 'model_name': 'gemini-2.5-flash', 'safety_ratings': []}, id='run--50d067b9-d6cc-44bf-a52c-1ac15bdd42dd-0', usage_metadata={'input_tokens': 1352, 'output_tokens': 0, 'total_tokens': 66887, 'input_token_details': {'cache_read': 0}, 'output_token_details': {'reasoning': 65535}})]}"
 
 
 
 
286
  ]
287
  },
288
+ "execution_count": 9,
289
  "metadata": {},
290
  "output_type": "execute_result"
291
  }
 
304
  },
305
  {
306
  "cell_type": "code",
307
+ "execution_count": 10,
308
  "id": "f80a471d",
309
  "metadata": {},
310
+ "outputs": [
311
+ {
312
+ "name": "stdout",
313
+ "output_type": "stream",
314
+ "text": [
315
+ "extremely\n"
316
+ ]
317
+ }
318
+ ],
319
  "source": [
320
  "hum_prompt = \"\"\"{'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2', 'question': 'Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\\n\\nWhat does Teal\\'c say in response to the question \"Isn\\'t that hot?\"', 'Level': '1', 'file_name': ''}\"\"\"\n",
321
  "\n",
requirements.txt CHANGED
@@ -15,4 +15,5 @@ opencv
15
  transformers
16
  # pytorch==2.6.0
17
  # torchvision==0.22
18
- groq
 
 
15
  transformers
16
  # pytorch==2.6.0
17
  # torchvision==0.22
18
+ groq
19
+ langchain-google-genai