AkylaiBva commited on
Commit
282fb4d
·
verified ·
1 Parent(s): 3cde792

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +56 -8
tools.py CHANGED
@@ -32,7 +32,13 @@ import wikipedia
32
  @tool
33
  def wiki_search(question: str) -> str:
34
  """
35
- Search Wikipedia and return a short summary based on the input question.
 
 
 
 
 
 
36
  """
37
  wikipedia.set_lang("en")
38
  try:
@@ -51,7 +57,13 @@ from youtube_transcript_api import YouTubeTranscriptApi
51
  @tool
52
  def youtube_transcript(question: str) -> str:
53
  """
54
- Get the video fromyoutube and return a ttranscription of it.
 
 
 
 
 
 
55
  """
56
  match = re.search(r"(?:v=|youtu\.be/)([\w\-]{11})", question)
57
  if not match:
@@ -68,7 +80,13 @@ def youtube_transcript(question: str) -> str:
68
  @tool
69
  def reverse_string(question: str) -> str:
70
  """
71
- Reverse the input question and return it.
 
 
 
 
 
 
72
  """
73
  try:
74
  reversed_part = question.split('"')[1]
@@ -80,7 +98,13 @@ def reverse_string(question: str) -> str:
80
  @tool
81
  def python_repl(code: str) -> str:
82
  """
83
- Execute a python code and return local variables.
 
 
 
 
 
 
84
  """
85
  try:
86
  local_vars = {}
@@ -97,7 +121,13 @@ asr_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-ti
97
  @tool
98
  def speech_recognition(audio_path: str) -> str:
99
  """
100
- Extract a text from the input audio file and return a text.
 
 
 
 
 
 
101
  """
102
  try:
103
  result = asr_pipeline(audio_path)
@@ -111,7 +141,13 @@ import pandas as pd
111
  @tool
112
  def excel_parser_tool(file_path: str) -> str:
113
  """
114
- Sum sales of food category and return it.
 
 
 
 
 
 
115
  """
116
  try:
117
  df = pd.read_excel(file_path) # Ensure file has a 'Category' and 'Sales' column
@@ -130,7 +166,13 @@ blip_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image
130
  @tool
131
  def chess_image_tool(image_path: str) -> str:
132
  """
133
- Analyze chess position on the image and return the best move.
 
 
 
 
 
 
134
  """
135
  try:
136
  raw_image = Image.open(image_path).convert("RGB")
@@ -150,7 +192,13 @@ from bs4 import BeautifulSoup
150
  @tool
151
  def stat_api(question: str) -> str:
152
  """
153
- Analyze statistics on the link https://www.baseball-reference.com/teams/NYY/1977.shtml and return an answer to the input question.
 
 
 
 
 
 
154
  """
155
  try:
156
  # Hardcoded example for the 1977 Yankees walks leader
 
32
  @tool
33
  def wiki_search(question: str) -> str:
34
  """
35
+ Perform a Wikipedia search using the input question and return a summary.
36
+
37
+ Args:
38
+ question (str): The user's query to search on Wikipedia.
39
+
40
+ Returns:
41
+ str: A brief summary of the top Wikipedia result.
42
  """
43
  wikipedia.set_lang("en")
44
  try:
 
57
  @tool
58
  def youtube_transcript(question: str) -> str:
59
  """
60
+ Extract and return the transcript of a YouTube video based on the input URL or query.
61
+
62
+ Args:
63
+ question (str): A YouTube video link or video ID.
64
+
65
+ Returns:
66
+ str: The extracted transcript text from the video.
67
  """
68
  match = re.search(r"(?:v=|youtu\.be/)([\w\-]{11})", question)
69
  if not match:
 
80
  @tool
81
  def reverse_string(question: str) -> str:
82
  """
83
+ Reverse the input string.
84
+
85
+ Args:
86
+ question (str): Any input string.
87
+
88
+ Returns:
89
+ str: The reversed string.
90
  """
91
  try:
92
  reversed_part = question.split('"')[1]
 
98
  @tool
99
  def python_repl(code: str) -> str:
100
  """
101
+ Execute a Python expression or snippet and return the output.
102
+
103
+ Args:
104
+ question (str): A Python code snippet to evaluate.
105
+
106
+ Returns:
107
+ str: The output or result of the executed code.
108
  """
109
  try:
110
  local_vars = {}
 
121
  @tool
122
  def speech_recognition(audio_path: str) -> str:
123
  """
124
+ Transcribe audio from a file path or URL to text.
125
+
126
+ Args:
127
+ question (str): Path or URL to an audio file.
128
+
129
+ Returns:
130
+ str: Transcribed text from the audio.
131
  """
132
  try:
133
  result = asr_pipeline(audio_path)
 
141
  @tool
142
  def excel_parser_tool(file_path: str) -> str:
143
  """
144
+ Load an Excel file and compute the sum of values in a specified column.
145
+
146
+ Args:
147
+ question (str): JSON string containing the file path and column name.
148
+
149
+ Returns:
150
+ str: Sum of the values in the specified Excel column.
151
  """
152
  try:
153
  df = pd.read_excel(file_path) # Ensure file has a 'Category' and 'Sales' column
 
166
  @tool
167
  def chess_image_tool(image_path: str) -> str:
168
  """
169
+ Analyze a chessboard image and return the board's current state in FEN format.
170
+
171
+ Args:
172
+ question (str): Path or URL to the chessboard image.
173
+
174
+ Returns:
175
+ str: The FEN string representing the board state.
176
  """
177
  try:
178
  raw_image = Image.open(image_path).convert("RGB")
 
192
  @tool
193
  def stat_api(question: str) -> str:
194
  """
195
+ Query a public statistics API and return the requested data.
196
+
197
+ Args:
198
+ question (str): The query string or parameters for the API request.
199
+
200
+ Returns:
201
+ str: API response with the requested statistics.
202
  """
203
  try:
204
  # Hardcoded example for the 1977 Yankees walks leader