Commit
·
db33b17
1
Parent(s):
fa83b52
added a few models
Browse files
app.py
CHANGED
|
@@ -25,9 +25,10 @@ class BasicAgent:
|
|
| 25 |
# api_key=os.getenv("GEMINI_API_KEY"))
|
| 26 |
#model=HfApiModel(api_key=os.getenv('HUGGING_FACE_API_KEY'))
|
| 27 |
# Instantiate the agent
|
|
|
|
| 28 |
self.agent = CodeAgent(
|
| 29 |
tools=[
|
| 30 |
-
|
| 31 |
ChessSolver(),
|
| 32 |
#DuckDuckGoSearchTool(),
|
| 33 |
VegetableFruitClassification(),
|
|
@@ -46,11 +47,11 @@ class BasicAgent:
|
|
| 46 |
If you are asked for a number, don't use comma to write your number neither use units such as $ or
|
| 47 |
percent sign unless specified otherwise.
|
| 48 |
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the
|
| 49 |
-
digits in plain text unless specified otherwise. Never include currency symbols in the response.
|
| 50 |
If you are asked for a comma separated list, apply the above rules depending of whether the element
|
| 51 |
to be put in the list is a number or a string. For question that contain phrases like `what is the number` or
|
| 52 |
`what is the highest number` return just the number, e.g., 2. For questions around currency,
|
| 53 |
-
include just the number, not the currency sign.
|
| 54 |
"""
|
| 55 |
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
| 56 |
def __call__(self, question: str) -> str:
|
|
@@ -98,11 +99,14 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 98 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 99 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 100 |
try:
|
| 101 |
-
|
| 102 |
api_key=os.getenv("GEMINI_API_KEY"))
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
| 106 |
print('Initialized the agent.')
|
| 107 |
except Exception as e:
|
| 108 |
print(f"Error instantiating agent: {e}")
|
|
@@ -115,10 +119,15 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 115 |
results_log = []
|
| 116 |
answers_payload = []
|
| 117 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 118 |
-
#questions_data = [i for i in questions_data if i['task_id'] == '
|
| 119 |
images = []
|
| 120 |
#added limit for testing
|
| 121 |
for req_num, item in enumerate(questions_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
task_id = item.get("task_id")
|
| 123 |
question_text = item.get("question") + ' You can use wikipedia. Do not change original names or omit name parts.'
|
| 124 |
file_name = item.get('file_name')
|
|
@@ -130,14 +139,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 130 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 131 |
continue
|
| 132 |
try:
|
| 133 |
-
submitted_answer =
|
| 134 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 135 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 136 |
except Exception as e:
|
| 137 |
print(f"Error running agent on task {task_id}: {e}")
|
| 138 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 139 |
time.sleep(30)
|
| 140 |
-
print('Number of answered questions:', len(results_log))
|
| 141 |
|
| 142 |
if not answers_payload:
|
| 143 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 25 |
# api_key=os.getenv("GEMINI_API_KEY"))
|
| 26 |
#model=HfApiModel(api_key=os.getenv('HUGGING_FACE_API_KEY'))
|
| 27 |
# Instantiate the agent
|
| 28 |
+
web_search = GoogleSearchTool(provider="serper")
|
| 29 |
self.agent = CodeAgent(
|
| 30 |
tools=[
|
| 31 |
+
web_search,
|
| 32 |
ChessSolver(),
|
| 33 |
#DuckDuckGoSearchTool(),
|
| 34 |
VegetableFruitClassification(),
|
|
|
|
| 47 |
If you are asked for a number, don't use comma to write your number neither use units such as $ or
|
| 48 |
percent sign unless specified otherwise.
|
| 49 |
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the
|
| 50 |
+
digits in plain text unless specified otherwise. Never include currency symbols in the response.
|
| 51 |
If you are asked for a comma separated list, apply the above rules depending of whether the element
|
| 52 |
to be put in the list is a number or a string. For question that contain phrases like `what is the number` or
|
| 53 |
`what is the highest number` return just the number, e.g., 2. For questions around currency,
|
| 54 |
+
include just the number, not the currency sign.
|
| 55 |
"""
|
| 56 |
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
| 57 |
def __call__(self, question: str) -> str:
|
|
|
|
| 99 |
return f"An unexpected error occurred fetching questions: {e}", None
|
| 100 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 101 |
try:
|
| 102 |
+
gemini_model = LiteLLMModel(model_id= "gemini/gemini-2.0-flash",
|
| 103 |
api_key=os.getenv("GEMINI_API_KEY"))
|
| 104 |
+
gpt_model = OpenAIServerModel(model_id="gpt-4o",
|
| 105 |
+
api_key=os.getenv("OPEN_AI_KEY"))
|
| 106 |
+
qwen_model=HfApiModel(api_key=os.getenv('HUGGING_FACE_API_KEY'))
|
| 107 |
+
chat_gpt_agent = BasicAgent(model=gpt_model)
|
| 108 |
+
gemini_agent = BasicAgent(model=gemini_model)
|
| 109 |
+
qwen_agent = BasicAgent(model=qwen_model)
|
| 110 |
print('Initialized the agent.')
|
| 111 |
except Exception as e:
|
| 112 |
print(f"Error instantiating agent: {e}")
|
|
|
|
| 119 |
results_log = []
|
| 120 |
answers_payload = []
|
| 121 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 122 |
+
#questions_data = [i for i in questions_data if i['task_id'] == '7bd855d8-463d-4ed5-93ca-5fe35145f733']
|
| 123 |
images = []
|
| 124 |
#added limit for testing
|
| 125 |
for req_num, item in enumerate(questions_data):
|
| 126 |
+
if item.get("task_id") in ['3f57289b-8c60-48be-bd80-01f8099ca449', '8e867cd7-cff9-4e6c-867a-ff5ddc2550be',
|
| 127 |
+
'3cef3a44-215e-4aed-8e3b-b1e3f08063b7']:
|
| 128 |
+
executing_agent = chat_gpt_agent
|
| 129 |
+
else:
|
| 130 |
+
executing_agent = gemini_agent
|
| 131 |
task_id = item.get("task_id")
|
| 132 |
question_text = item.get("question") + ' You can use wikipedia. Do not change original names or omit name parts.'
|
| 133 |
file_name = item.get('file_name')
|
|
|
|
| 139 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 140 |
continue
|
| 141 |
try:
|
| 142 |
+
submitted_answer = executing_agent(question_text)
|
| 143 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 144 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 145 |
except Exception as e:
|
| 146 |
print(f"Error running agent on task {task_id}: {e}")
|
| 147 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 148 |
time.sleep(30)
|
|
|
|
| 149 |
|
| 150 |
if not answers_payload:
|
| 151 |
print("Agent did not produce any answers to submit.")
|