Update app.py
Browse files
app.py
CHANGED
@@ -2,36 +2,25 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
-
import openai
|
6 |
|
7 |
-
from smolagents
|
8 |
-
from smolagents.tools.code_interpreter import CodeInterpreterTool
|
9 |
-
from langchain_community.tools import DuckDuckGoSearchRun
|
10 |
|
11 |
# Constants
|
12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
13 |
|
14 |
-
# --- Agent Definition
|
15 |
class SmartGAIAAgent:
|
16 |
def __init__(self):
|
17 |
self.api_key = os.getenv("OPENAI_API_KEY")
|
18 |
if not self.api_key:
|
19 |
raise ValueError("Missing OPENAI_API_KEY")
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
self.
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
self.agent = ToolCallingAgent(
|
28 |
-
tools=[self.search, self.calculator],
|
29 |
-
model="gpt-4",
|
30 |
-
max_steps=8,
|
31 |
-
system_prompt=(
|
32 |
-
"You are a helpful assistant solving complex reasoning and factual questions. "
|
33 |
-
"Use tools only if needed. Return only the final answer. Do not add explanations or formatting."
|
34 |
-
)
|
35 |
)
|
36 |
|
37 |
def __call__(self, question: str) -> str:
|
|
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import pandas as pd
|
|
|
5 |
|
6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
|
|
|
|
|
7 |
|
8 |
# Constants
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
|
11 |
+
# --- Agent Definition using smolagents ---
|
12 |
class SmartGAIAAgent:
|
13 |
def __init__(self):
|
14 |
self.api_key = os.getenv("OPENAI_API_KEY")
|
15 |
if not self.api_key:
|
16 |
raise ValueError("Missing OPENAI_API_KEY")
|
17 |
+
self.model = OpenAIServerModel(model_id="gpt-4", api_key=self.api_key)
|
18 |
+
|
19 |
+
# Agent with DuckDuckGo and code execution tool
|
20 |
+
self.agent = CodeAgent(
|
21 |
+
tools=[DuckDuckGoSearchTool()],
|
22 |
+
model=self.model,
|
23 |
+
add_base_tools=True # adds code interpreter and other built-ins
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
def __call__(self, question: str) -> str:
|