BasicAgent updated with required tools
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -13,11 +14,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
"""
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, WikipediaSearchTool, VisitWebpageTool
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
|
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
print("BasicAgent initialized.")
|
17 |
+
model =
|
18 |
+
self.agent = CodeAgent(
|
19 |
+
model = HfApiModel(),
|
20 |
+
tools = [DuckDuckGoSearchTool(), WikipediaSearchTool(), VisitWebpageTool()],
|
21 |
+
additional_authorized_imports = ["pandas", "numpy"]
|
22 |
+
)
|
23 |
+
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question.
|
24 |
+
Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
25 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
26 |
+
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.
|
27 |
+
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.
|
28 |
+
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.
|
29 |
+
"""
|
30 |
+
self.prompt = SYSTEM_PROMPT
|
31 |
+
|
32 |
def __call__(self, question: str) -> str:
|
33 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
34 |
+
final_answer = self.model.generate_answer(question)
|
35 |
+
print(f"Agent returning fixed answer: {final_answer}")
|
36 |
+
return final_answer
|
37 |
|
38 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
39 |
"""
|