File size: 1,437 Bytes
ce0ec3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Analysis tools for understanding and interpreting song lyrics.
"""

import os
from loguru import logger
from smolagents import tool

from api_utils import make_api_call_with_retry

@tool
def analyze_lyrics_tool(song_title: str, artist: str, lyrics: str) -> str:
    """
    Performs a deep analysis of the musical track, given its metadata.

    Args:
        song_title: Title of the song or music track.
        artist: The name of the artist.
        lyrics: The lyrics of the song.

    Returns:
        A summary of the song's meaning in English.
    """

    prompt = f"""You are an expert in songs and their meanings. 
    Summarize the meaning of {song_title} by {artist} and identify 
    key themes based on the lyrics: 
    {lyrics}. 

    Include deep idea and vibes analysis with explanations 
    based on references to the exact lines.
    """

    # Determine which model to use based on configuration
    if os.getenv("USE_ANTHROPIC", "false").lower() == "true":
        model_to_use = "claude-3-haiku-20240307"
        logger.info("Using Anthropic model: {} for lyrics analysis", model_to_use)
    else:
        model_to_use = "gemini/gemini-2.0-flash"
        logger.info("Using Gemini model: {} for lyrics analysis", model_to_use)

    # Use the function with retry mechanism
    logger.info("Analyzing lyrics for song: '{}' by '{}'", song_title, artist)
    return make_api_call_with_retry(model_to_use, prompt)