Skip to content

Commit 4da81f5

Browse files
authored
HOT FIX: Quick started error with custom python tool (#401)
* added validate check when s3 link * removed download method
1 parent 8c93391 commit 4da81f5

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

aixplain/factories/file_factory.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from aixplain.utils.file_utils import upload_data
3030
from typing import Any, Dict, Text, Union, Optional, List
3131

32+
3233
MB_1 = 1048576
3334
MB_25 = 26214400
3435
MB_50 = 52428800
@@ -94,10 +95,10 @@ def check_storage_type(cls, input_link: Any) -> StorageType:
9495
if os.path.exists(input_link) is True and os.path.isfile(input_link) is True:
9596
return StorageType.FILE
9697
elif (
97-
input_link.startswith("s3://")
98-
or input_link.startswith("http://")
99-
or input_link.startswith("https://")
100-
or validators.url(input_link)
98+
input_link.startswith("s3://") # noqa
99+
or input_link.startswith("http://") # noqa
100+
or input_link.startswith("https://") # noqa
101+
or validators.url(input_link) # noqa
101102
):
102103
return StorageType.URL
103104
else:

aixplain/modules/agent/tool/custom_python_code_tool.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from typing import Text, Union, Callable
2525
from aixplain.modules.agent.tool import Tool
26+
import logging
2627

2728

2829
class CustomPythonCodeTool(Tool):
@@ -42,9 +43,13 @@ def to_dict(self):
4243
}
4344

4445
def validate(self):
45-
from aixplain.modules.model.utils import parse_code
46+
from aixplain.modules.model.utils import parse_code_decorated
4647

47-
self.code, _, description, name = parse_code(self.code)
48+
if not str(self.code).startswith("s3://"):
49+
self.code, _, description, name = parse_code_decorated(self.code)
50+
else:
51+
logging.info("Utility Model Already Exists, skipping code validation")
52+
return
4853

4954
# Set description from parsed code if not already set
5055
if not self.description or self.description.strip() == "":

aixplain/utils/file_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,16 @@ def upload_data(
146146
bucket_name = re.findall(r"https://(.*?).s3.amazonaws.com", presigned_url)[0]
147147
s3_link = f"s3://{bucket_name}/{path}"
148148
return s3_link
149-
except Exception as e:
149+
except Exception:
150150
if nattempts > 0:
151151
return upload_data(file_name, content_type, content_encoding, nattempts - 1)
152152
else:
153153
raise Exception("File Uploading Error: Failure on Uploading to S3.")
154154

155155

156-
def s3_to_csv(s3_url: Text, aws_credentials: Optional[Dict[Text, Text]] = {"AWS_ACCESS_KEY_ID": None, "AWS_SECRET_ACCESS_KEY": None}) -> Text:
156+
def s3_to_csv(
157+
s3_url: Text, aws_credentials: Optional[Dict[Text, Text]] = {"AWS_ACCESS_KEY_ID": None, "AWS_SECRET_ACCESS_KEY": None}
158+
) -> Text:
157159
"""Convert s3 url to a csv file and download the file in `download_path`
158160
159161
Args:
@@ -179,11 +181,11 @@ def s3_to_csv(s3_url: Text, aws_credentials: Optional[Dict[Text, Text]] = {"AWS_
179181
aws_secret_access_key = aws_credentials.get("AWS_SECRET_ACCESS_KEY") or os.getenv("AWS_SECRET_ACCESS_KEY")
180182
s3 = boto3.client("s3", aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
181183
response = s3.list_objects_v2(Bucket=bucket_name, Prefix=prefix)
182-
except NoCredentialsError as e:
184+
except NoCredentialsError:
183185
raise Exception(
184186
"to use the s3 bucket option you need to set the right AWS credentials [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY]"
185187
)
186-
except Exception as e:
188+
except Exception:
187189
raise Exception("the bucket you are trying to use does not exist")
188190

189191
try:
@@ -222,10 +224,10 @@ def s3_to_csv(s3_url: Text, aws_credentials: Optional[Dict[Text, Text]] = {"AWS_
222224
main_file_name = Path(data[first_key][i]).stem
223225
for val in data.values():
224226
if Path(val[i]).stem != main_file_name:
225-
raise Exception(f"all the files in different directories should have the same prefix")
227+
raise Exception("all the files in different directories should have the same prefix")
226228

227229
elif prefix == "":
228-
raise Exception(f"ERROR the files can't be at the root of the bucket ")
230+
raise Exception("ERROR the files can't be at the root of the bucket ")
229231
else:
230232
data = {prefix: [f"s3://{bucket_name}/{file}" for file in files]}
231233

0 commit comments

Comments
 (0)