Update app.py
Browse files
app.py
CHANGED
@@ -4,37 +4,32 @@ import requests
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
import openai
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
# --- Constants ---
|
10 |
-
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
-
|
12 |
-
# --- Basic Agent Definition ---
|
13 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
14 |
-
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
|
|
|
25 |
try:
|
26 |
-
|
27 |
-
model="gpt-4",
|
28 |
-
messages=[
|
29 |
-
{"role": "system", "content": system_prompt},
|
30 |
-
{"role": "user", "content": question}
|
31 |
-
],
|
32 |
-
temperature=0.3,
|
33 |
-
)
|
34 |
-
answer = response['choices'][0]['message']['content'].strip()
|
35 |
-
return answer
|
36 |
except Exception as e:
|
37 |
-
print(f"
|
38 |
return "error"
|
39 |
|
40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
import openai
|
7 |
+
from smolagents.agents import ToolCallingAgent
|
8 |
+
from smolagents.tools import CodeInterpreterTool
|
9 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
10 |
|
11 |
+
class SmartGAIAAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def __init__(self):
|
13 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
14 |
+
|
15 |
+
self.search = DuckDuckGoSearchRun()
|
16 |
+
self.calculator = CodeInterpreterTool()
|
17 |
+
|
18 |
+
self.agent = ToolCallingAgent(
|
19 |
+
tools=[self.search, self.calculator],
|
20 |
+
model="gpt-4", # or gpt-3.5-turbo
|
21 |
+
max_steps=8,
|
22 |
+
system_prompt=(
|
23 |
+
"You are an expert assistant answering complex factual and reasoning questions. "
|
24 |
+
"Use tools only when necessary. Only return the final answer, nothing else."
|
25 |
+
)
|
26 |
)
|
27 |
|
28 |
+
def __call__(self, question: str) -> str:
|
29 |
try:
|
30 |
+
return self.agent.run(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
except Exception as e:
|
32 |
+
print(f"Agent error: {e}")
|
33 |
return "error"
|
34 |
|
35 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|