Spaces:
Sleeping
Sleeping
""" | |
Web agent for finding and extracting song lyrics from online sources. | |
""" | |
from loguru import logger | |
from smolagents import CodeAgent, VisitWebpageTool, FinalAnswerTool | |
from config import load_prompt_templates | |
from tools.analysis_tools import AnalyzeLyricsTool | |
from tools.formatting_tools import FormatAnalysisResultsTool | |
from tools.search_tools import BraveSearchTool | |
from tools.image_generation_tools import GenerateImageTool | |
def create_single_agent(model, analysis_tool_model_id=None): | |
""" | |
Create an agent specialized in web browsing and lyrics extraction. | |
Args: | |
model: The LLM model to use with this agent | |
model_id: The model ID string to use for lyrics analysis (optional) | |
Returns: | |
A configured CodeAgent for web searches | |
""" | |
prompt_templates = load_prompt_templates() | |
# Define agent parameters directly in the code instead of using config | |
# Example usage within the agent | |
agent = CodeAgent( | |
tools=[ | |
BraveSearchTool(), | |
# ThrottledDuckDuckGoSearchTool(min_delay=7.0, max_delay=15.0), | |
VisitWebpageTool(), | |
AnalyzeLyricsTool(model_id=analysis_tool_model_id), | |
FormatAnalysisResultsTool(), | |
GenerateImageTool(), | |
FinalAnswerTool(), | |
], | |
model=model, | |
additional_authorized_imports=['numpy', 'bs4', 'rich', 'json'], | |
max_steps=25, | |
verbosity_level=2, | |
description="Specialized agent for finding and extracting song lyrics specified by the user using search and analysis tools. Performs lyrics search and after getting the lyrics full text from the web, it performs the analysis using given tools. Generates visual representation of the song based on the analysis results. Provides detailed commentary with beautiful and human-readable format using rich library formatting. Format analysis results in rich colorful output.", | |
prompt_templates=prompt_templates | |
) | |
logger.info("Web agent (lyrics search) created successfully") | |
return agent |