Spaces:
Sleeping
Sleeping
update
Browse files
agent.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import tool
|
| 2 |
+
from smolagents import CodeAgent, VisitWebpageTool, DuckDuckGoSearchTool
|
| 3 |
+
from smolagents import OpenAIServerModel
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
with open('prompt.txt', 'r') as f:
|
| 7 |
+
system_prompt = f.read()
|
| 8 |
+
system_prompt
|
| 9 |
+
|
| 10 |
+
model = OpenAIServerModel(
|
| 11 |
+
model_id="gemini-2.0-flash",
|
| 12 |
+
api_key= Gemini_Key,
|
| 13 |
+
# Google Gemini OpenAI-compatible API base URL
|
| 14 |
+
api_base="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
agent = CodeAgent(
|
| 18 |
+
model=model,
|
| 19 |
+
tools=[ VisitWebpageTool(), DuckDuckGoSearchTool()],
|
| 20 |
+
max_steps=20,
|
| 21 |
+
)
|
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"
|
|
@@ -13,11 +15,12 @@ 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
|
| 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 agent import agent
|
| 8 |
+
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
+
self.agent = agent
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 21 |
+
answer = self.agent.run(question)
|
| 22 |
+
print(f"Agent returning answer: {answer}")
|
| 23 |
+
return answer[14:]
|
| 24 |
|
| 25 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 26 |
"""
|