File size: 2,205 Bytes
a2a7f98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
007e18f
 
a2a7f98
 
7e2c9ef
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from youtube_transcript_api import YouTubeTranscriptApi
from smolagents import tool

@tool
def analyze_image(question: str, image_url: str) -> str:
    """
    Analyze an image using OpenAI's API.
    Args:
        question (str): The question to ask about the image. eg. "What is in this image?"
        image_url (str): The URL of the image to analyze.
    """
    client = OpenAI()
    response = client.responses.create(
        model="gpt-4o-mini",
        input=[
            {
                "role": "user",
                "content": [
                    { "type": "input_text", "text": f"{question}" },
                    {
                        "type": "input_image",
                        "image_url": f"{image_url}",
                    }
                ]
            }
        ]
    )

    return response

@tool
# a function to get youtube transcript from video id
def get_youtube_transcript(video_id: str) -> str:
    """
    Fetches the transcript of a YouTube video given its video ID.
    Args:
        video_id (str): The ID of the YouTube video. Pass in the video ID, NOT the video URL. For a video with the URL https://www.youtube.com/watch?v=12345 the ID is 12345.
    Returns:
        str: The transcript of the YouTube video. as a single string with each line separated by a newline character.
    """
    # Initialize the YouTubeTranscriptApi
    ytt_api = YouTubeTranscriptApi()
    fetched_transcript = ytt_api.fetch(video_id)
    raw_data = fetched_transcript.to_raw_data()
    # raw data is in the form of [{        'text': 'Hey there',        'start': 0.0,        'duration': 1.54    },    {        'text': 'how are you',,        'start': 1.54,        'duration': 4.16    },   ... ] we will return ony the text element as lines
    transcript = "\n".join([item['text'] for item in raw_data])
    return transcript

@tool
def reverse_text(question: str) -> str:
    """
    Reverse a string if it appears to be written backward.
    Args:
        question (str): The question that seemed to be written backward"
    """
    if question.strip()[0] in "?.!":
        reversed_candidate = question[::-1]
        return reversed_candidate
    return "Text seems normal."