Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,13 @@ from tavily import TavilyClient
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
load_dotenv()
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# (Keep Constants as is)
|
| 17 |
# --- Constants ---
|
| 18 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -36,24 +43,22 @@ class BasicAgent:
|
|
| 36 |
base_url="https://openrouter.ai/api/v1",
|
| 37 |
api_key=os.getenv("OPENROUTER_API_KEY")
|
| 38 |
)
|
| 39 |
-
|
| 40 |
-
tools = [self.web_search]
|
| 41 |
self.agent = create_agent(
|
| 42 |
model=self.llm,
|
| 43 |
tools=tools,
|
| 44 |
system_prompt=SYSTEM_PROMPT
|
| 45 |
)
|
| 46 |
print("BasicAgent initialized.")
|
| 47 |
-
|
| 48 |
-
def web_search(self, query: str) -> Dict[str, Any]:
|
| 49 |
-
"""Search the web for information"""
|
| 50 |
-
return self.tavily_client.search(query)
|
| 51 |
def __call__(self, question: str) -> str:
|
|
|
|
| 52 |
user_prompt = HumanMessage(content=question)
|
| 53 |
response = self.agent.invoke(
|
| 54 |
{"messages": [user_prompt]}
|
| 55 |
)
|
| 56 |
answer = response['messages'][-1].content.strip()
|
|
|
|
| 57 |
return answer
|
| 58 |
|
| 59 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
load_dotenv()
|
| 15 |
|
| 16 |
+
|
| 17 |
+
tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
|
| 18 |
+
@tool
|
| 19 |
+
def web_search(query: str) -> Dict[str, Any]:
|
| 20 |
+
"""Search the web for information"""
|
| 21 |
+
return tavily_client.search(query)
|
| 22 |
+
|
| 23 |
# (Keep Constants as is)
|
| 24 |
# --- Constants ---
|
| 25 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 43 |
base_url="https://openrouter.ai/api/v1",
|
| 44 |
api_key=os.getenv("OPENROUTER_API_KEY")
|
| 45 |
)
|
| 46 |
+
tools = [web_search]
|
|
|
|
| 47 |
self.agent = create_agent(
|
| 48 |
model=self.llm,
|
| 49 |
tools=tools,
|
| 50 |
system_prompt=SYSTEM_PROMPT
|
| 51 |
)
|
| 52 |
print("BasicAgent initialized.")
|
| 53 |
+
|
|
|
|
|
|
|
|
|
|
| 54 |
def __call__(self, question: str) -> str:
|
| 55 |
+
print(f"Agent received question: {question}")
|
| 56 |
user_prompt = HumanMessage(content=question)
|
| 57 |
response = self.agent.invoke(
|
| 58 |
{"messages": [user_prompt]}
|
| 59 |
)
|
| 60 |
answer = response['messages'][-1].content.strip()
|
| 61 |
+
print(f"Agent generated answer: {answer}")
|
| 62 |
return answer
|
| 63 |
|
| 64 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|