DeekshithN05 commited on
Commit
cc2c216
·
verified ·
1 Parent(s): b4eaa7a

Delete agent_tools.py

Browse files
Files changed (1) hide show
  1. agent_tools.py +0 -242
agent_tools.py DELETED
@@ -1,242 +0,0 @@
1
-
2
- import datetime
3
- import pytz
4
- import cmath
5
-
6
- from typing import Optional
7
- import os
8
- import tempfile
9
-
10
-
11
-
12
- ### =============== TIMEZONE TOOLS =============== ###
13
-
14
- @tool
15
- def get_current_time_in_timezone(timezone: str) -> str:
16
- """Fetches the current local time in a specified timezone.
17
- Args:
18
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
19
- """
20
- try:
21
- tz = pytz.timezone(timezone)
22
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
23
- return f"The current local time in {timezone} is: {local_time}"
24
- except Exception as e:
25
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
26
-
27
-
28
-
29
- ### =============== MATHEMATICAL TOOLS =============== ###
30
-
31
-
32
- @tool
33
- def multiply(a: float, b: float) -> float:
34
- """
35
- Multiplies two numbers.
36
- Args:
37
- a (float): the first number
38
- b (float): the second number
39
- """
40
- return a * b
41
-
42
-
43
- @tool
44
- def add(a: float, b: float) -> float:
45
- """
46
- Adds two numbers.
47
- Args:
48
- a (float): the first number
49
- b (float): the second number
50
- """
51
- return a + b
52
-
53
-
54
- @tool
55
- def subtract(a: float, b: float) -> int:
56
- """
57
- Subtracts two numbers.
58
- Args:
59
- a (float): the first number
60
- b (float): the second number
61
- """
62
- return a - b
63
-
64
-
65
- @tool
66
- def divide(a: float, b: float) -> float:
67
- """
68
- Divides two numbers.
69
- Args:
70
- a (float): the first float number
71
- b (float): the second float number
72
- """
73
- if b == 0:
74
- raise ValueError("Cannot divided by zero.")
75
- return a / b
76
-
77
-
78
- @tool
79
- def modulus(a: int, b: int) -> int:
80
- """
81
- Get the modulus of two numbers.
82
- Args:
83
- a (int): the first number
84
- b (int): the second number
85
- """
86
- return a % b
87
-
88
-
89
- @tool
90
- def power(a: float, b: float) -> float:
91
- """
92
- Get the power of two numbers.
93
- Args:
94
- a (float): the first number
95
- b (float): the second number
96
- """
97
- return a**b
98
-
99
-
100
- @tool
101
- def square_root(a: float) -> float | complex:
102
- """
103
- Get the square root of a number.
104
- Args:
105
- a (float): the number to get the square root of
106
- """
107
- if a >= 0:
108
- return a**0.5
109
- return cmath.sqrt(a)
110
-
111
-
112
- ### =============== DOCUMENT PROCESSING TOOLS =============== ###
113
-
114
-
115
- @tool
116
- def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
117
- """
118
- Save content to a file and return the path.
119
- Args:
120
- content (str): the content to save to the file
121
- filename (str, optional): the name of the file. If not provided, a random name file will be created.
122
- """
123
- temp_dir = tempfile.gettempdir()
124
- if filename is None:
125
- temp_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
126
- filepath = temp_file.name
127
- else:
128
- filepath = os.path.join(temp_dir, filename)
129
-
130
- with open(filepath, "w") as f:
131
- f.write(content)
132
-
133
- return f"File saved to {filepath}. You can read this file to process its contents."
134
-
135
-
136
- @tool
137
- def download_file_from_url(url: str, filename: Optional[str] = None) -> str:
138
- """
139
- Download a file from a URL and save it to a temporary location.
140
- Args:
141
- url (str): the URL of the file to download.
142
- filename (str, optional): the name of the file. If not provided, a random name file will be created.
143
- """
144
- try:
145
- # Parse URL to get filename if not provided
146
- if not filename:
147
- path = urlparse(url).path
148
- filename = os.path.basename(path)
149
- if not filename:
150
- filename = f"downloaded_{uuid.uuid4().hex[:8]}"
151
-
152
- # Create temporary file
153
- temp_dir = tempfile.gettempdir()
154
- filepath = os.path.join(temp_dir, filename)
155
-
156
- # Download the file
157
- response = requests.get(url, stream=True)
158
- response.raise_for_status()
159
-
160
- # Save the file
161
- with open(filepath, "wb") as f:
162
- for chunk in response.iter_content(chunk_size=8192):
163
- f.write(chunk)
164
-
165
- return f"File downloaded to {filepath}. You can read this file to process its contents."
166
- except Exception as e:
167
- return f"Error downloading file: {str(e)}"
168
-
169
-
170
- @tool
171
- def extract_text_from_image(image_path: str) -> str:
172
- """
173
- Extract text from an image using OCR library pytesseract (if available).
174
- Args:
175
- image_path (str): the path to the image file.
176
- """
177
- try:
178
- # Open the image
179
- image = Image.open(image_path)
180
-
181
- # Extract text from the image
182
- text = pytesseract.image_to_string(image)
183
-
184
- return f"Extracted text from image:\n\n{text}"
185
- except Exception as e:
186
- return f"Error extracting text from image: {str(e)}"
187
-
188
-
189
- @tool
190
- def analyze_csv_file(file_path: str, query: str) -> str:
191
- """
192
- Analyze a CSV file using pandas and answer a question about it.
193
- Args:
194
- file_path (str): the path to the CSV file.
195
- query (str): Question about the data
196
- """
197
- try:
198
- # Read the CSV file
199
- df = pd.read_csv(file_path)
200
-
201
- # Run various analyses based on the query
202
- result = f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
203
- result += f"Columns: {', '.join(df.columns)}\n\n"
204
-
205
- # Add summary statistics
206
- result += "Summary statistics:\n"
207
- result += str(df.describe())
208
-
209
- return result
210
-
211
- except Exception as e:
212
- return f"Error analyzing CSV file: {str(e)}"
213
-
214
-
215
- @tool
216
- def analyze_excel_file(file_path: str, query: str) -> str:
217
- """
218
- Analyze an Excel file using pandas and answer a question about it.
219
- Args:
220
- file_path (str): the path to the Excel file.
221
- query (str): Question about the data
222
- """
223
- try:
224
- # Read the Excel file
225
- df = pd.read_excel(file_path)
226
-
227
- # Run various analyses based on the query
228
- result = (
229
- f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
230
- )
231
- result += f"Columns: {', '.join(df.columns)}\n\n"
232
-
233
- # Add summary statistics
234
- result += "Summary statistics:\n"
235
- result += str(df.describe())
236
-
237
- return result
238
-
239
- except Exception as e:
240
- return f"Error analyzing Excel file: {str(e)}"
241
-
242
-