Added Gemini API, improved agent prompt
Browse files
app.py
CHANGED
|
@@ -7,13 +7,18 @@ import pandas as pd
|
|
| 7 |
import asyncio
|
| 8 |
import aiohttp
|
| 9 |
|
| 10 |
-
from smolagents import CodeAgent,
|
| 11 |
|
| 12 |
# --- Constants ---
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
class BasicAgent:
|
| 18 |
def __init__(self):
|
| 19 |
print("BasicAgent initialized to use smolagents.")
|
|
@@ -22,13 +27,16 @@ class BasicAgent:
|
|
| 22 |
try:
|
| 23 |
search_tool = DuckDuckGoSearchTool()
|
| 24 |
|
| 25 |
-
llm_model =
|
| 26 |
-
model_id=
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
-
|
| 29 |
self.agent_executor = CodeAgent(
|
| 30 |
model=llm_model,
|
| 31 |
tools=[search_tool],
|
|
|
|
| 32 |
)
|
| 33 |
print("smolagents AgentExecutor initialized successfully with WebSearchTool.")
|
| 34 |
|
|
@@ -56,7 +64,6 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 56 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 57 |
and displays the results.
|
| 58 |
"""
|
| 59 |
-
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 60 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 61 |
|
| 62 |
if profile:
|
|
|
|
| 7 |
import asyncio
|
| 8 |
import aiohttp
|
| 9 |
|
| 10 |
+
from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, CODE_SYSTEM_PROMPT
|
| 11 |
|
| 12 |
# --- Constants ---
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
+
MODEL_ID = "gemini-2.5-pro-preview-06-05"
|
| 17 |
+
SYSTEM_PROMPT = f"""${CODE_SYSTEM_PROMPT}\n\n
|
| 18 |
+
Give as precise answer as possible. Do not include extra explanation, thoughts or questions.
|
| 19 |
+
Include just answer to the specific question.
|
| 20 |
+
"""
|
| 21 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 22 |
class BasicAgent:
|
| 23 |
def __init__(self):
|
| 24 |
print("BasicAgent initialized to use smolagents.")
|
|
|
|
| 27 |
try:
|
| 28 |
search_tool = DuckDuckGoSearchTool()
|
| 29 |
|
| 30 |
+
llm_model = OpenAIServerModel(
|
| 31 |
+
model_id=MODEL_ID,
|
| 32 |
+
api_base="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 33 |
+
api_key=GOOGLE_API_KEY,
|
| 34 |
+
temperature=0.7
|
| 35 |
)
|
|
|
|
| 36 |
self.agent_executor = CodeAgent(
|
| 37 |
model=llm_model,
|
| 38 |
tools=[search_tool],
|
| 39 |
+
system_prompt=SYSTEM_PROMPT,
|
| 40 |
)
|
| 41 |
print("smolagents AgentExecutor initialized successfully with WebSearchTool.")
|
| 42 |
|
|
|
|
| 64 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 65 |
and displays the results.
|
| 66 |
"""
|
|
|
|
| 67 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 68 |
|
| 69 |
if profile:
|