from smolagents import Tool, DuckDuckGoSearchTool import whisper class read_file(Tool): name="read_file" description="Read a file and return the content." inputs={ "file_path": { "type": "string", "description": "The path to the file to read." } } output_type = "string" def forward(self, file_path: str) -> str: """ Read the content of a file and return it as a string. """ try: with open(file_path, 'r') as file: content = file.read() return content except Exception as e: return f"Error reading file: {str(e)}" class transcribe_audio(Tool): name="transcribe_audio" description="Transcribe an audio file and return the text." inputs={ "audio_path": { "type": "string", "description": "The path to the audio file to transcribe." } } output_type = "string" def forward(self, audio_path: str) -> str: try: # Load the Whisper model model = whisper.load_model("small") # Transcribe the audio file result = model.transcribe(audio_path) return result['text'] except Exception as e: return f"Error transcribing audio: {str(e)}" def return_tools() -> list[Tool]: """ Returns a list of tools to be used by the agent. """ return [ read_file(), transcribe_audio(), DuckDuckGoSearchTool(), ]