Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app req tools
Browse files- app.py +8 -23
- tools/final_answer.py +12 -25
app.py
CHANGED
|
@@ -1,47 +1,32 @@
|
|
| 1 |
# app.py
|
| 2 |
-
from smolagents import CodeAgent,
|
| 3 |
-
import datetime
|
| 4 |
-
import requests
|
| 5 |
-
import pytz
|
| 6 |
-
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
# Initialize
|
| 10 |
final_answer = FinalAnswerTool()
|
| 11 |
-
|
| 12 |
-
# Initialize model
|
| 13 |
model = HfApiModel(
|
| 14 |
max_tokens=2096,
|
| 15 |
temperature=0.5,
|
| 16 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 17 |
-
custom_role_conversions=None,
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# Load tools
|
| 21 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 22 |
-
|
| 23 |
# Load prompt templates
|
| 24 |
with open("prompts.yaml", 'r') as stream:
|
| 25 |
prompt_templates = yaml.safe_load(stream)
|
| 26 |
|
| 27 |
-
# Create
|
| 28 |
agent = CodeAgent(
|
| 29 |
model=model,
|
| 30 |
-
tools=[final_answer],
|
| 31 |
max_steps=6,
|
| 32 |
verbosity_level=1,
|
| 33 |
-
grammar=None,
|
| 34 |
-
planning_interval=None,
|
| 35 |
-
name="Web Analyzer Agent",
|
| 36 |
-
description="An agent that analyzes web content using various tools",
|
| 37 |
prompt_templates=prompt_templates
|
| 38 |
)
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
from Gradio_UI import GradioUI
|
| 42 |
-
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
# Launch Gradio interface
|
| 45 |
GradioUI(agent).launch(
|
| 46 |
server_name="0.0.0.0",
|
| 47 |
server_port=7860
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
from smolagents import CodeAgent, HfApiModel
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
+
import yaml
|
| 5 |
+
from Gradio_UI import GradioUI
|
| 6 |
|
| 7 |
+
# Initialize components
|
| 8 |
final_answer = FinalAnswerTool()
|
|
|
|
|
|
|
| 9 |
model = HfApiModel(
|
| 10 |
max_tokens=2096,
|
| 11 |
temperature=0.5,
|
| 12 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
|
|
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
# Load prompt templates
|
| 16 |
with open("prompts.yaml", 'r') as stream:
|
| 17 |
prompt_templates = yaml.safe_load(stream)
|
| 18 |
|
| 19 |
+
# Create agent
|
| 20 |
agent = CodeAgent(
|
| 21 |
model=model,
|
| 22 |
+
tools=[final_answer],
|
| 23 |
max_steps=6,
|
| 24 |
verbosity_level=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
prompt_templates=prompt_templates
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Launch interface
|
|
|
|
|
|
|
| 29 |
if __name__ == "__main__":
|
|
|
|
| 30 |
GradioUI(agent).launch(
|
| 31 |
server_name="0.0.0.0",
|
| 32 |
server_port=7860
|
tools/final_answer.py
CHANGED
|
@@ -1,34 +1,21 @@
|
|
| 1 |
# tools/final_answer.py
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
@
|
| 6 |
class FinalAnswerTool:
|
| 7 |
-
"""A tool
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
to the user.
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
name: str = "final_answer"
|
| 15 |
-
description: str = "Tool for providing the final response to the user"
|
| 16 |
|
| 17 |
-
def __call__(self, response: str) -> str:
|
| 18 |
-
"""Provide the final answer.
|
| 19 |
-
|
| 20 |
Args:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
Returns:
|
| 24 |
-
The
|
| 25 |
"""
|
| 26 |
-
return
|
| 27 |
|
| 28 |
def __str__(self) -> str:
|
| 29 |
-
""
|
| 30 |
-
|
| 31 |
-
Returns:
|
| 32 |
-
The tool's name
|
| 33 |
-
"""
|
| 34 |
-
return self.name
|
|
|
|
| 1 |
# tools/final_answer.py
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
from typing import Any
|
| 4 |
|
| 5 |
+
@dataclass
|
| 6 |
class FinalAnswerTool:
|
| 7 |
+
"""A tool to format and deliver the final answer to the user."""
|
| 8 |
+
|
| 9 |
+
def __call__(self, answer: str) -> str:
|
| 10 |
+
"""Process and return the final response.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
Args:
|
| 13 |
+
answer: The final answer text to return to the user.
|
| 14 |
+
|
| 15 |
Returns:
|
| 16 |
+
The processed answer as a string.
|
| 17 |
"""
|
| 18 |
+
return answer
|
| 19 |
|
| 20 |
def __str__(self) -> str:
|
| 21 |
+
return "final_answer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|