File size: 1,279 Bytes
99c4fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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(),
	]