Tesvia commited on
Commit
40ad9f8
·
verified ·
1 Parent(s): b251ad0

Upload 4 files

Browse files
Files changed (1) hide show
  1. tools.py +27 -23
tools.py CHANGED
@@ -10,14 +10,13 @@ from smolagents import Tool
10
  # ---- 1. PythonRunTool ------------------------------------------------------
11
  class PythonRunTool(Tool):
12
  name = "python_run"
13
- description = (
14
- "Execute trusted Python code and return printed output "
15
- "+ repr() of the last expression (or _result variable)."
16
- )
17
  inputs = {
18
- "code": {"type": "string", "description": "Python code to execute", "required": True}
19
  }
20
- output_type = "string"
21
 
22
  def forward(self, code: str) -> str:
23
  buf, ns = io.StringIO(), {}
@@ -34,14 +33,13 @@ class PythonRunTool(Tool):
34
  # ---- 2. ExcelLoaderTool ----------------------------------------------------
35
  class ExcelLoaderTool(Tool):
36
  name = "load_spreadsheet"
37
- description = (
38
- "Read .xlsx/.xls/.csv from disk and return "
39
- "rows as a list of dictionaries with string keys."
40
- )
41
  inputs = {
42
- "path": {"type": "string", "description": "Path to .csv/.xls/.xlsx file", "required": True},
43
  "sheet": {
44
- "type": "string",
45
  "description": "Sheet name or index (optional, required for Excel files only)",
46
  "required": False,
47
  "default": "",
@@ -67,12 +65,14 @@ class ExcelLoaderTool(Tool):
67
  # ---- 3. YouTubeTranscriptTool ---------------------------------------------
68
  class YouTubeTranscriptTool(Tool):
69
  name = "youtube_transcript"
70
- description = "Return the subtitles of a YouTube URL using youtube-transcript-api."
 
 
71
  inputs = {
72
- "url": {"type": "string", "description": "YouTube URL", "required": True},
73
- "lang": {"type": "string", "description": "Transcript language (default: en)", "required": False, "default": "en"}
74
  }
75
- output_type = "string"
76
 
77
  def forward(self, url: str, lang: str = "en") -> str:
78
  from urllib.parse import urlparse, parse_qs
@@ -84,12 +84,14 @@ class YouTubeTranscriptTool(Tool):
84
  # ---- 4. AudioTranscriptionTool --------------------------------------------
85
  class AudioTranscriptionTool(Tool):
86
  name = "transcribe_audio"
87
- description = "Transcribe an audio file with OpenAI Whisper, returns plain text."
 
 
88
  inputs = {
89
- "path": {"type": "string", "description": "Path to audio file", "required": True},
90
- "model": {"type": "string", "description": "Model name for transcription (default: whisper-1)", "required": False, "default": "whisper-1"}
91
  }
92
- output_type = "string"
93
 
94
  def forward(self, path: str, model: str = "whisper-1") -> str:
95
  import openai
@@ -103,11 +105,13 @@ class AudioTranscriptionTool(Tool):
103
  # ---- 5. SimpleOCRTool ------------------------------------------------------
104
  class SimpleOCRTool(Tool):
105
  name = "image_ocr"
106
- description = "Return any text spotted in an image via pytesseract OCR."
 
 
107
  inputs = {
108
- "path": {"type": "string", "description": "Path to image file", "required": True}
109
  }
110
- output_type = "string"
111
 
112
  def forward(self, path: str) -> str:
113
  from PIL import Image
 
10
  # ---- 1. PythonRunTool ------------------------------------------------------
11
  class PythonRunTool(Tool):
12
  name = "python_run"
13
+ description = """
14
+ Execute trusted Python code and return printed output + repr() of the last expression (or _result variable).
15
+ """
 
16
  inputs = {
17
+ "code": {"type": str, "description": "Python code to execute", "required": True}
18
  }
19
+ output_type = "str"
20
 
21
  def forward(self, code: str) -> str:
22
  buf, ns = io.StringIO(), {}
 
33
  # ---- 2. ExcelLoaderTool ----------------------------------------------------
34
  class ExcelLoaderTool(Tool):
35
  name = "load_spreadsheet"
36
+ description = """
37
+ Read .xlsx/.xls/.csv from disk and return rows as a list of dictionaries with string keys.
38
+ """
 
39
  inputs = {
40
+ "path": {"type": str, "description": "Path to .csv/.xls/.xlsx file", "required": True},
41
  "sheet": {
42
+ "type": str,
43
  "description": "Sheet name or index (optional, required for Excel files only)",
44
  "required": False,
45
  "default": "",
 
65
  # ---- 3. YouTubeTranscriptTool ---------------------------------------------
66
  class YouTubeTranscriptTool(Tool):
67
  name = "youtube_transcript"
68
+ description = """
69
+ Return the subtitles of a YouTube URL using youtube-transcript-api.
70
+ """
71
  inputs = {
72
+ "url": {"type": str, "description": "YouTube URL", "required": True},
73
+ "lang": {"type": str, "description": "Transcript language (default: en)", "required": False, "default": "en"}
74
  }
75
+ output_type = "str"
76
 
77
  def forward(self, url: str, lang: str = "en") -> str:
78
  from urllib.parse import urlparse, parse_qs
 
84
  # ---- 4. AudioTranscriptionTool --------------------------------------------
85
  class AudioTranscriptionTool(Tool):
86
  name = "transcribe_audio"
87
+ description = """
88
+ Transcribe an audio file with OpenAI Whisper, returns plain text."
89
+ """
90
  inputs = {
91
+ "path": {"type": str, "description": "Path to audio file", "required": True},
92
+ "model": {"type": str, "description": "Model name for transcription (default: whisper-1)", "required": False, "default": "whisper-1"}
93
  }
94
+ output_type = "str"
95
 
96
  def forward(self, path: str, model: str = "whisper-1") -> str:
97
  import openai
 
105
  # ---- 5. SimpleOCRTool ------------------------------------------------------
106
  class SimpleOCRTool(Tool):
107
  name = "image_ocr"
108
+ description = """
109
+ Return any text spotted in an image via pytesseract OCR.
110
+ """
111
  inputs = {
112
+ "path": {"type": str, "description": "Path to image file", "required": True}
113
  }
114
+ output_type = "str"
115
 
116
  def forward(self, path: str) -> str:
117
  from PIL import Image