Spaces:
Sleeping
Sleeping
openAI
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +20 -7
__pycache__/app.cpython-310.pyc
CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -4,7 +4,14 @@ import requests
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
7 |
-
from smolagents import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
@@ -14,16 +21,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
class BasicAgent:
|
16 |
def __init__(self):
|
17 |
-
self.model =
|
|
|
|
|
|
|
|
|
18 |
self.agent = ToolCallingAgent(
|
19 |
tools=[DuckDuckGoSearchTool()],
|
20 |
-
model=self.model
|
|
|
21 |
)
|
22 |
-
self.agent.prompt_templates['system_prompt'] = """
|
23 |
|
24 |
-
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, 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.
|
25 |
|
26 |
-
"""
|
27 |
print("BasicAgent initialized.")
|
28 |
def __call__(self, question: str) -> str:
|
29 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
@@ -85,7 +97,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
85 |
results_log = []
|
86 |
answers_payload = []
|
87 |
print(f"Running agent on {len(questions_data)} questions...")
|
88 |
-
for item in questions_data:
|
89 |
task_id = item.get("task_id")
|
90 |
question_text = item.get("question")
|
91 |
if not task_id or question_text is None:
|
@@ -98,6 +110,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
98 |
except Exception as e:
|
99 |
print(f"Error running agent on task {task_id}: {e}")
|
100 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
101 |
|
102 |
if not answers_payload:
|
103 |
print("Agent did not produce any answers to submit.")
|
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
7 |
+
from smolagents import (
|
8 |
+
ToolCallingAgent,
|
9 |
+
CodeAgent,
|
10 |
+
DuckDuckGoSearchTool,
|
11 |
+
InferenceClientModel,
|
12 |
+
HfApiModel,
|
13 |
+
OpenAIServerModel
|
14 |
+
)
|
15 |
|
16 |
# (Keep Constants as is)
|
17 |
# --- Constants ---
|
|
|
21 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
22 |
class BasicAgent:
|
23 |
def __init__(self):
|
24 |
+
self.model = OpenAIServerModel(
|
25 |
+
model_id='o4-mini',
|
26 |
+
api_base="https://api.openai.com/v1",
|
27 |
+
api_key=os.environ["OPENAI_API_KEY"],
|
28 |
+
)
|
29 |
self.agent = ToolCallingAgent(
|
30 |
tools=[DuckDuckGoSearchTool()],
|
31 |
+
model=self.model,
|
32 |
+
add_base_tools=True
|
33 |
)
|
34 |
+
#self.agent.prompt_templates['system_prompt'] = """
|
35 |
|
36 |
+
#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, 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.
|
37 |
|
38 |
+
#"""
|
39 |
print("BasicAgent initialized.")
|
40 |
def __call__(self, question: str) -> str:
|
41 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
97 |
results_log = []
|
98 |
answers_payload = []
|
99 |
print(f"Running agent on {len(questions_data)} questions...")
|
100 |
+
for i, item in enumerate(questions_data):
|
101 |
task_id = item.get("task_id")
|
102 |
question_text = item.get("question")
|
103 |
if not task_id or question_text is None:
|
|
|
110 |
except Exception as e:
|
111 |
print(f"Error running agent on task {task_id}: {e}")
|
112 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
113 |
+
|
114 |
|
115 |
if not answers_payload:
|
116 |
print("Agent did not produce any answers to submit.")
|