Added the Agent Implementation
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import requests
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
|
|
|
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
@@ -12,12 +14,25 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
print("BasicAgent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
|
19 |
-
print(f"Agent returning fixed answer: {
|
20 |
-
return
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
|
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
|
7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
|
8 |
+
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
11 |
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 |
+
print("Initializing the BasicAgent")
|
18 |
+
model = OpenAIServerModel(model_id="gpt-4o")
|
19 |
+
print("GPT-4o LLM is instantiated")
|
20 |
+
# Initialize the search tool
|
21 |
+
search_tool = DuckDuckGoSearchTool()
|
22 |
+
print("DuckDuckSearchTool instantiated")
|
23 |
+
|
24 |
+
print("Agent is now created")
|
25 |
+
# Initializing Agent
|
26 |
+
self.agent = CodeAgent(
|
27 |
+
model = model,
|
28 |
+
tools=[search_tool]
|
29 |
+
)
|
30 |
+
|
31 |
def __call__(self, question: str) -> str:
|
32 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
33 |
+
final_answer = self.agent.run(question)
|
34 |
+
print(f"Agent returning fixed answer: {final_answer}")
|
35 |
+
return final_answer
|
36 |
|
37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
38 |
"""
|