Update app.py
Browse files
app.py
CHANGED
|
@@ -13,44 +13,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
import os
|
| 14 |
from typing import List, Dict, Any, Optional
|
| 15 |
from smolagents import CodeAgent, Tool, tool, LiteLLMModel
|
| 16 |
-
from
|
| 17 |
|
| 18 |
import json
|
| 19 |
import re
|
| 20 |
from datetime import datetime
|
| 21 |
|
| 22 |
|
| 23 |
-
class LinkupSearchTool(Tool):
|
| 24 |
-
name = "linkup_web_search"
|
| 25 |
-
description = "Performs a search for your text query using Linkup sdk then returns a string of the top search results."
|
| 26 |
-
inputs = {
|
| 27 |
-
"query": {"type": "string", "description": "The search query to perform."},
|
| 28 |
-
}
|
| 29 |
-
output_type = "string"
|
| 30 |
-
|
| 31 |
-
def __init__(self, answer_output_type: str = "sourcedAnswer",
|
| 32 |
-
**kwargs):
|
| 33 |
-
super().__init__(self)
|
| 34 |
-
import os
|
| 35 |
-
|
| 36 |
-
self.api_key = os.getenv("LINKUP_API_KEY")
|
| 37 |
-
if self.api_key is None:
|
| 38 |
-
raise ValueError("Missing Linkup API key. Make sure you have 'LINKUP_API_KEY' in your env variables.")
|
| 39 |
-
|
| 40 |
-
self.client = LinkupClient(api_key=self.api_key)
|
| 41 |
-
self.answer_output_type = answer_output_type
|
| 42 |
-
|
| 43 |
-
def forward(self, query: str) -> str:
|
| 44 |
-
response = self.client.search(
|
| 45 |
-
query=query,
|
| 46 |
-
depth="deep",
|
| 47 |
-
output_type=self.answer_output_type
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
answer_text = getattr(response, "answer", "No answer provided.")
|
| 51 |
-
|
| 52 |
-
return f'Answer:{answer_text}'
|
| 53 |
-
|
| 54 |
|
| 55 |
custom_role_conversions = {"tool-call": "assistant", "tool-response": "user"}
|
| 56 |
|
|
@@ -66,23 +35,8 @@ class BasicAgent:
|
|
| 66 |
"""
|
| 67 |
print("BasicAgent initialized.")
|
| 68 |
|
| 69 |
-
# Initialize tools
|
| 70 |
-
self.web_search_tool = LinkupSearchTool()
|
| 71 |
-
|
| 72 |
-
model_params = {
|
| 73 |
-
"model_id": "gpt-4o-mini",
|
| 74 |
-
"custom_role_conversions": custom_role_conversions,
|
| 75 |
-
"max_completion_tokens": 8192,
|
| 76 |
-
}
|
| 77 |
-
self.model = LiteLLMModel(**model_params)
|
| 78 |
-
|
| 79 |
# Initialize the agent
|
| 80 |
-
self.agent =
|
| 81 |
-
model=self.model,
|
| 82 |
-
tools=[
|
| 83 |
-
self.web_search_tool,
|
| 84 |
-
],
|
| 85 |
-
)
|
| 86 |
|
| 87 |
def __call__(self, question: str) -> str:
|
| 88 |
"""
|
|
|
|
| 13 |
import os
|
| 14 |
from typing import List, Dict, Any, Optional
|
| 15 |
from smolagents import CodeAgent, Tool, tool, LiteLLMModel
|
| 16 |
+
from agents import create_agent
|
| 17 |
|
| 18 |
import json
|
| 19 |
import re
|
| 20 |
from datetime import datetime
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
custom_role_conversions = {"tool-call": "assistant", "tool-response": "user"}
|
| 25 |
|
|
|
|
| 35 |
"""
|
| 36 |
print("BasicAgent initialized.")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Initialize the agent
|
| 39 |
+
self.agent = create_agent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
def __call__(self, question: str) -> str:
|
| 42 |
"""
|