kokluch commited on
Commit
b6ba19b
·
1 Parent(s): 146f00f

Update model

Browse files
Files changed (2) hide show
  1. agent.py +15 -32
  2. app.py +2 -1
agent.py CHANGED
@@ -2,7 +2,9 @@ import base64
2
  import os
3
  import re
4
  import tempfile
 
5
  from pathlib import Path
 
6
  from typing import TypedDict, Annotated, Optional
7
  import pandas as pd
8
  import requests
@@ -18,6 +20,7 @@ from langgraph.prebuilt import tools_condition
18
  from mediawikiapi import MediaWikiAPI
19
  from wikipedia_tool import WikipediaTool
20
  from yt_tool import speech_recognition_pipe, yt_transcribe
 
21
 
22
 
23
  @tool
@@ -41,39 +44,11 @@ def read_xlsx_file(file_path: str) -> str:
41
  except Exception as e:
42
  return f"Error analyzing CSV file: {str(e)}"
43
 
44
- @tool
45
- def addition(a: int, b: int) -> int:
46
- """
47
- Add two int numbers.
48
-
49
- Args:
50
- a: int
51
- b int
52
-
53
- Returns:
54
- a + b
55
- """
56
- return a + b
57
-
58
- @tool
59
- def multiple(a: int, b: int) -> float:
60
- """
61
- Multiple two float numbers.
62
-
63
- Args:
64
- a: int
65
- b int
66
-
67
- Returns:
68
- a * b
69
- """
70
- return a * b
71
-
72
  class Agent:
73
  def __init__(self):
74
 
75
  llm = ChatGoogleGenerativeAI(
76
- model="gemini-2.5-flash-preview-04-17",
77
  # model="gemini-2.0-flash",
78
  # model="gemini-1.5-pro",
79
  temperature=0
@@ -83,8 +58,10 @@ class Agent:
83
  WikipediaTool(api_wrapper=WikipediaAPIWrapper(wiki_client=MediaWikiAPI())),
84
  TavilySearch(),
85
  read_xlsx_file,
86
- addition,
 
87
  multiple,
 
88
  yt_transcribe
89
  ]
90
 
@@ -256,11 +233,17 @@ class Agent:
256
  return builder.compile()
257
 
258
  def run(self, question: str, task_id: str, file_name: str | None):
259
- system_prompt = SystemMessage(content="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, use digit not letter, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.")
 
 
 
 
 
 
260
 
261
  messages = [system_prompt, HumanMessage(content=question)]
262
 
263
- response = self.graph.invoke({"messages": messages, "task_id": task_id, "file_name": file_name}, debug=True)
264
 
265
  answer = response['messages'][-1].content
266
 
 
2
  import os
3
  import re
4
  import tempfile
5
+ import time
6
  from pathlib import Path
7
+ from time import sleep
8
  from typing import TypedDict, Annotated, Optional
9
  import pandas as pd
10
  import requests
 
20
  from mediawikiapi import MediaWikiAPI
21
  from wikipedia_tool import WikipediaTool
22
  from yt_tool import speech_recognition_pipe, yt_transcribe
23
+ from calculus_tools import add, substract, multiple, divide
24
 
25
 
26
  @tool
 
44
  except Exception as e:
45
  return f"Error analyzing CSV file: {str(e)}"
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  class Agent:
48
  def __init__(self):
49
 
50
  llm = ChatGoogleGenerativeAI(
51
+ model="gemini-2.5-flash-preview-05-20",
52
  # model="gemini-2.0-flash",
53
  # model="gemini-1.5-pro",
54
  temperature=0
 
58
  WikipediaTool(api_wrapper=WikipediaAPIWrapper(wiki_client=MediaWikiAPI())),
59
  TavilySearch(),
60
  read_xlsx_file,
61
+ add,
62
+ substract,
63
  multiple,
64
+ divide,
65
  yt_transcribe
66
  ]
67
 
 
233
  return builder.compile()
234
 
235
  def run(self, question: str, task_id: str, file_name: str | None):
236
+ system_prompt = SystemMessage(content="""
237
+ You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, use digit not letter, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
238
+
239
+ If you are asked a list of items separated by coma, add a space after each coma.
240
+
241
+ If you are asked a list in alphabetical order, it is the first word of each item that matters.
242
+ """)
243
 
244
  messages = [system_prompt, HumanMessage(content=question)]
245
 
246
+ response = self.graph.invoke({"messages": messages, "task_id": task_id, "file_name": file_name})
247
 
248
  answer = response['messages'][-1].content
249
 
app.py CHANGED
@@ -93,6 +93,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
93
  answers_payload = []
94
  print(f"Running agent on {len(questions_data)} questions...")
95
  for item in questions_data:
 
96
  task_id = item.get("task_id")
97
  question_text = item.get("question")
98
  file_name = item.get("file_name")
@@ -215,4 +216,4 @@ if __name__ == "__main__":
215
  print("-"*(60 + len(" App Starting ")) + "\n")
216
 
217
  print("Launching Gradio Interface for Basic Agent Evaluation...")
218
- demo.launch(debug=True, share=False)
 
93
  answers_payload = []
94
  print(f"Running agent on {len(questions_data)} questions...")
95
  for item in questions_data:
96
+ time.sleep(60)
97
  task_id = item.get("task_id")
98
  question_text = item.get("question")
99
  file_name = item.get("file_name")
 
216
  print("-"*(60 + len(" App Starting ")) + "\n")
217
 
218
  print("Launching Gradio Interface for Basic Agent Evaluation...")
219
+ demo.launch(share=False)