Andrei Sferdian commited on
Commit
9b0b7f6
·
1 Parent(s): 88ae537

Use gpt-4.1 as model

Browse files
Files changed (4) hide show
  1. agent.py +4 -6
  2. app.py +10 -10
  3. tools/__init__.py +0 -2
  4. tools/wikipedia.py +0 -46
agent.py CHANGED
@@ -2,6 +2,7 @@ from typing import Annotated, TypedDict
2
 
3
  from langchain_community.tools.google_serper import GoogleSerperResults
4
  from langchain_core.messages import AnyMessage, HumanMessage
 
5
  from langchain_together import ChatTogether
6
  from langgraph.graph import START, StateGraph
7
  from langgraph.graph.message import add_messages
@@ -13,7 +14,6 @@ from tools import (
13
  add,
14
  divide,
15
  execute_python_code,
16
- filter_md_table_count,
17
  find_wiki_page,
18
  floor_divide,
19
  get_text_file,
@@ -40,12 +40,11 @@ tools = [
40
  power,
41
  modulus,
42
  floor_divide,
43
- filter_md_table_count,
44
  ]
45
 
46
- model = ChatTogether(
47
- model="meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
48
- temperature=0.3,
49
  max_retries=3,
50
  ).bind_tools(tools)
51
 
@@ -60,7 +59,6 @@ prompt = (
60
  " b. If the required information is not found in the search results, use the find_wiki_page tool to locate the relevant Wikipedia page.\n"
61
  " The response will be a JSON string with the page's summary and sections.\n"
62
  " c. If the Wikipedia page exists, and the summary does not contain the required info, use get_wiki_page_section_by_title tool to get the content of the desired section.\n"
63
- " d. If the section contains a table, apply the filter_md_table_count tool to count the number of rows that match specific criteria.\n"
64
  "If the user asks for an Excel file, use the load_excel_file tool.\n"
65
  "When you need to perform calculations, use the provided calculator tools (add, subtract, multiply, divide).\n"
66
  "If the user provides a Python code snippet, follow this sequence:\n"
 
2
 
3
  from langchain_community.tools.google_serper import GoogleSerperResults
4
  from langchain_core.messages import AnyMessage, HumanMessage
5
+ from langchain_openai import ChatOpenAI
6
  from langchain_together import ChatTogether
7
  from langgraph.graph import START, StateGraph
8
  from langgraph.graph.message import add_messages
 
14
  add,
15
  divide,
16
  execute_python_code,
 
17
  find_wiki_page,
18
  floor_divide,
19
  get_text_file,
 
40
  power,
41
  modulus,
42
  floor_divide,
 
43
  ]
44
 
45
+ model = ChatOpenAI(
46
+ model="gpt-4.1",
47
+ temperature=0.0,
48
  max_retries=3,
49
  ).bind_tools(tools)
50
 
 
59
  " b. If the required information is not found in the search results, use the find_wiki_page tool to locate the relevant Wikipedia page.\n"
60
  " The response will be a JSON string with the page's summary and sections.\n"
61
  " c. If the Wikipedia page exists, and the summary does not contain the required info, use get_wiki_page_section_by_title tool to get the content of the desired section.\n"
 
62
  "If the user asks for an Excel file, use the load_excel_file tool.\n"
63
  "When you need to perform calculations, use the provided calculator tools (add, subtract, multiply, divide).\n"
64
  "If the user provides a Python code snippet, follow this sequence:\n"
app.py CHANGED
@@ -263,11 +263,11 @@ def run_locally():
263
  # print("No questions available to run.")
264
  # return
265
  questions = [
266
- {
267
- "task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
268
- "question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
269
- "file_name": "",
270
- },
271
  # {
272
  # "task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d",
273
  # "question": "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
@@ -288,11 +288,11 @@ def run_locally():
288
  # "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.",
289
  # "file_name": "7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx",
290
  # },
291
- # {
292
- # "task_id": "f918266a-b3e0-4914-865d-4faa564f1aef",
293
- # "question": "What is the final numeric output from the attached Python code?",
294
- # "file_name": "f918266a-b3e0-4914-865d-4faa564f1aef.py",
295
- # },
296
  ]
297
 
298
  max_concurrency = int(os.getenv("MAX_CONCURRENCY", 1))
 
263
  # print("No questions available to run.")
264
  # return
265
  questions = [
266
+ # {
267
+ # "task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
268
+ # "question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
269
+ # "file_name": "",
270
+ # },
271
  # {
272
  # "task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d",
273
  # "question": "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
 
288
  # "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.",
289
  # "file_name": "7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx",
290
  # },
291
+ {
292
+ "task_id": "f918266a-b3e0-4914-865d-4faa564f1aef",
293
+ "question": "What is the final numeric output from the attached Python code?",
294
+ "file_name": "f918266a-b3e0-4914-865d-4faa564f1aef.py",
295
+ },
296
  ]
297
 
298
  max_concurrency = int(os.getenv("MAX_CONCURRENCY", 1))
tools/__init__.py CHANGED
@@ -11,7 +11,6 @@ from .execute_code import execute_python_code
11
  from .files import get_text_file, load_excel_file
12
  from .get_youtube_transcript import GetYouTubeTranscript
13
  from .wikipedia import (
14
- filter_md_table_count,
15
  find_wiki_page,
16
  get_wiki_page_section_by_title,
17
  )
@@ -30,5 +29,4 @@ Tools = [
30
  modulus,
31
  floor_divide,
32
  execute_python_code,
33
- filter_md_table_count,
34
  ]
 
11
  from .files import get_text_file, load_excel_file
12
  from .get_youtube_transcript import GetYouTubeTranscript
13
  from .wikipedia import (
 
14
  find_wiki_page,
15
  get_wiki_page_section_by_title,
16
  )
 
29
  modulus,
30
  floor_divide,
31
  execute_python_code,
 
32
  ]
tools/wikipedia.py CHANGED
@@ -1,10 +1,8 @@
1
  import re
2
- from io import StringIO
3
  from typing import List
4
  from urllib.parse import quote
5
 
6
  import markdownify as md
7
- import pandas as pd
8
  import requests
9
  import wikipedia
10
  import wikipediaapi
@@ -201,47 +199,3 @@ def get_wiki_page_section_by_title(page_title: str, section_title: str) -> str |
201
  section_md = md.markdownify(section_html)
202
  print(f"Section content: {section_md}")
203
  return section_md
204
-
205
-
206
- @tool(parse_docstring=True)
207
- def filter_md_table_count(
208
- md_table: str, column_name: str, filter_values: List[str]
209
- ) -> int:
210
- """
211
- Filters a Markdown table based on a column name and a list of values, and returns the count of matching rows.
212
-
213
- Args:
214
- md_table (str): The Markdown table as a string.
215
- column_name (str): The name of the column to filter on.
216
- filter_values (List[str]): A list of values to filter against.
217
-
218
- Returns:
219
- int: The count of rows that match the filter criteria.
220
- """
221
-
222
- try:
223
- # Convert Markdown table to a Pandas DataFrame
224
- df = pd.read_csv(
225
- StringIO(md_table),
226
- sep="|",
227
- skipinitialspace=True,
228
- engine="python",
229
- skiprows=1,
230
- )
231
- df = df.rename(columns=lambda x: x.strip()).iloc[
232
- :, 1:-1
233
- ] # Remove empty columns from Markdown parsing
234
-
235
- # Check if the column exists
236
- if column_name not in df.columns:
237
- print(f"Column '{column_name}' not found in the table.")
238
- return 0
239
-
240
- # Filter rows based on the column and values
241
- filtered_df = df[df[column_name].isin(filter_values)]
242
-
243
- # Return the count of matching rows
244
- return len(filtered_df)
245
- except Exception as e:
246
- print(f"Error processing Markdown table: {e}")
247
- return 0
 
1
  import re
 
2
  from typing import List
3
  from urllib.parse import quote
4
 
5
  import markdownify as md
 
6
  import requests
7
  import wikipedia
8
  import wikipediaapi
 
199
  section_md = md.markdownify(section_html)
200
  print(f"Section content: {section_md}")
201
  return section_md