File size: 1,840 Bytes
3401238
 
d2ae5b9
3401238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84a655c
5c26cb0
828a8c2
c61f23a
9e4b131
3401238
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import pandas as pd
from smolagents import tool, CodeAgent, DuckDuckGoSearchTool, HfApiModel, LiteLLMModel, InferenceClientModel

# Tools
@tool
def add(a: int, b: int) -> float:
    """Divide a and b for calculations.

    Args:
        a: first number
        b: second number
    """
    res = a * b
    print(f"Tool call: add({a}, {b}) -> {res}")
    return res

@tool
def reverse(s: str) -> str:
    """Reverse a string for calculations.

    Args:
        s: string to reverse
    """
    ret = ''.join(reversed(s))
    print(f"Tool call: reverse({s}) -> {ret}")
    return ret

@tool
def transcribe_audio(file_path: str) -> str:
    """Transcribe an audio file to text using Hugging Face's ASR model.

    Args:
        file_path: path to the audio file
    """
    from transformers import pipeline
    transcriber = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
    transcription = transcriber(file_path)
    return transcription["text"]

@tool
def read_excel(file_path: str) -> pd.DataFrame:
    """Read an Excel file and return its content as a DataFrame.

    Args:
        file_path: path to the Excel file
    """
    return pd.read_excel(file_path)

tools = [
    add,
    reverse,
    DuckDuckGoSearchTool(),
    transcribe_audio,
    read_excel,
]

# LLM

llm = InferenceClientModel(model_id='meta-llama/Llama-3.3-70B-Instruct',
                           token=os.getenv('TOGETHER_KEY'),
                           provider="together")


# Agent
class BasicAgent:
    def __init__(self):
        self.agent = CodeAgent(tools=tools, model=llm)
        
    def __call__(self, question: str) -> str:
        print(f"Agent received question (first 30 chars): {question[:30]}...")
        answer = self.agent.run(question)
        print(f"Agent answer: {answer}")
        return answer