Skip to content
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,3 @@ dmypy.json
# Vscode
.vscode
.DS_Store

26 changes: 21 additions & 5 deletions aixplain/modules/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,27 @@ def run_async(self, data: Union[Text, Dict], name: Text = "model_process", param

resp = None
try:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")

poll_url = resp["data"]
response = {"status": "IN_PROGRESS", "url": poll_url}
if 200 <= r.status_code < 300:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")
poll_url = resp["data"]
response = {"status": "IN_PROGRESS", "url": poll_url}
else:
if r.status_code == 401:
error = "Unauthorized API key: Please verify the spelling of the API key and its current validity."
elif 460 <= r.status_code < 470:
error = "Subscription-related error: Please ensure that your subscription is active and has not expired."
elif 470 <= r.status_code < 480:
error = "Billing-related error: Please ensure you have enough credits to run this model. "
elif 480 <= r.status_code < 490:
error = "Supplier-related error: Please ensure that the selected supplier provides the model you are trying to access."
elif 490 <= r.status_code < 500:
error = "Validation-related error: Please ensure all required fields are provided and correctly formatted."
else:
status_code = str(r.status_code)
error = f"Status {status_code}: Unspecified error: An unspecified error occurred while processing your request."
response = {"status": "FAILED", "error_message": error}
logging.error(f"Error in request for {name} - {r.status_code}: {error}")
except Exception:
response = {"status": "FAILED"}
msg = f"Error in request for {name} - {traceback.format_exc()}"
Expand Down
26 changes: 21 additions & 5 deletions aixplain/modules/model/llm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,27 @@ def run_async(

resp = None
try:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")

poll_url = resp["data"]
response = {"status": "IN_PROGRESS", "url": poll_url}
if 200 <= r.status_code < 300:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")
poll_url = resp["data"]
response = {"status": "IN_PROGRESS", "url": poll_url}
else:
if r.status_code == 401:
error = "Unauthorized API key: Please verify the spelling of the API key and its current validity."
elif 460 <= r.status_code < 470:
error = "Subscription-related error: Please ensure that your subscription is active and has not expired."
elif 470 <= r.status_code < 480:
error = "Billing-related error: Please ensure you have enough credits to run this model. "
elif 480 <= r.status_code < 490:
error = "Supplier-related error: Please ensure that the selected supplier provides the model you are trying to access."
elif 490 <= r.status_code < 500:
error = "Validation-related error: Please ensure all required fields are provided and correctly formatted."
else:
status_code = str(r.status_code)
error = f"Status {status_code}: Unspecified error: An unspecified error occurred while processing your request."
response = {"status": "FAILED", "error_message": error}
logging.error(f"Error in request for {name} - {r.status_code}: {error}")
except Exception:
response = {"status": "FAILED"}
msg = f"Error in request for {name} - {traceback.format_exc()}"
Expand Down
26 changes: 21 additions & 5 deletions aixplain/modules/pipeline/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,27 @@ def run_async(

resp = None
try:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")

poll_url = resp["url"]
response = {"status": "IN_PROGRESS", "url": poll_url}
if 200 <= r.status_code < 300:
resp = r.json()
logging.info(f"Result of request for {name} - {r.status_code} - {resp}")
poll_url = resp["url"]
response = {"status": "IN_PROGRESS", "url": poll_url}
else:
if r.status_code == 401:
error = "Unauthorized API key: Please verify the spelling of the API key and its current validity."
elif 460 <= r.status_code < 470:
error = "Subscription-related error: Please ensure that your subscription is active and has not expired."
elif 470 <= r.status_code < 480:
error = "Billing-related error: Please ensure you have enough credits to run this pipeline. "
elif 480 <= r.status_code < 490:
error = "Supplier-related error: Please ensure that the selected supplier provides the pipeline you are trying to access."
elif 490 <= r.status_code < 500:
error = "Validation-related error: Please ensure all required fields are provided and correctly formatted."
else:
status_code = str(r.status_code)
error = f"Status {status_code}: Unspecified error: An unspecified error occurred while processing your request."
response = {"status": "FAILED", "error_message": error}
logging.error(f"Error in request for {name} - {r.status_code}: {error}")
except Exception:
response = {"status": "FAILED"}
if resp is not None:
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/llm_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from dotenv import load_dotenv
from urllib.parse import urljoin
import requests_mock
from aixplain.enums import Function

load_dotenv()
from aixplain.utils import config
from aixplain.modules import LLM

import pytest

@pytest.mark.parametrize(
"status_code,error_message",
[
(401,"Unauthorized API key: Please verify the spelling of the API key and its current validity."),
(465,"Subscription-related error: Please ensure that your subscription is active and has not expired."),
(475,"Billing-related error: Please ensure you have enough credits to run this model. "),
(485, "Supplier-related error: Please ensure that the selected supplier provides the model you are trying to access."),
(495, "Validation-related error: Please ensure all required fields are provided and correctly formatted."),
(501, "Status 501: Unspecified error: An unspecified error occurred while processing your request."),

],
)

def test_run_async_errors(status_code, error_message):
base_url = config.MODELS_RUN_URL
llm_id = "llm-id"
execute_url = urljoin(base_url, f"execute/{llm_id}")

with requests_mock.Mocker() as mock:
mock.post(execute_url, status_code=status_code)
test_llm = LLM(id=llm_id, name="Test llm",url=base_url, function=Function.TEXT_GENERATION)
response = test_llm.run_async(data="input_data")
assert response["status"] == "FAILED"
assert response["error_message"] == error_message
29 changes: 28 additions & 1 deletion tests/unit/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"""

from dotenv import load_dotenv
from urllib.parse import urljoin
import requests_mock

load_dotenv()
import re
import requests_mock
from aixplain.utils import config
from aixplain.modules import Model

Expand Down Expand Up @@ -57,3 +58,29 @@ def test_failed_poll():
assert hyp_response["error"] == ref_response["error"]
assert hyp_response["supplierError"] == ref_response["supplierError"]
assert hyp_response["status"] == "FAILED"


@pytest.mark.parametrize(
"status_code,error_message",
[
(401,"Unauthorized API key: Please verify the spelling of the API key and its current validity."),
(465,"Subscription-related error: Please ensure that your subscription is active and has not expired."),
(475,"Billing-related error: Please ensure you have enough credits to run this model. "),
(485, "Supplier-related error: Please ensure that the selected supplier provides the model you are trying to access."),
(495, "Validation-related error: Please ensure all required fields are provided and correctly formatted."),
(501, "Status 501: Unspecified error: An unspecified error occurred while processing your request."),

],
)

def test_run_async_errors(status_code, error_message):
base_url = config.MODELS_RUN_URL
model_id = "model-id"
execute_url = urljoin(base_url, f"execute/{model_id}")

with requests_mock.Mocker() as mock:
mock.post(execute_url, status_code=status_code)
test_model = Model(id=model_id, name="Test Model",url=base_url)
response = test_model.run_async(data="input_data")
assert response["status"] == "FAILED"
assert response["error_message"] == error_message
26 changes: 26 additions & 0 deletions tests/unit/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

from dotenv import load_dotenv
import pytest

load_dotenv()
import requests_mock
Expand All @@ -36,3 +37,28 @@ def test_create_pipeline():
hyp_pipeline = PipelineFactory.create(pipeline={"nodes": []}, name="Pipeline Test")
assert hyp_pipeline.id == ref_pipeline.id
assert hyp_pipeline.name == ref_pipeline.name

@pytest.mark.parametrize(
"status_code,error_message",
[
(401,"Unauthorized API key: Please verify the spelling of the API key and its current validity."),
(465,"Subscription-related error: Please ensure that your subscription is active and has not expired."),
(475,"Billing-related error: Please ensure you have enough credits to run this pipeline. "),
(485, "Supplier-related error: Please ensure that the selected supplier provides the pipeline you are trying to access."),
(495, "Validation-related error: Please ensure all required fields are provided and correctly formatted."),
(501, "Status 501: Unspecified error: An unspecified error occurred while processing your request."),

],
)

def test_run_async_errors(status_code, error_message):
base_url = config.BACKEND_URL
pipeline_id = "pipeline_id"
execute_url = f"{base_url}/assets/pipeline/execution/run/{pipeline_id}"

with requests_mock.Mocker() as mock:
mock.post(execute_url, status_code=status_code)
test_pipeline = Pipeline(id=pipeline_id, api_key=config.TEAM_API_KEY, name="Test Pipeline", url=base_url)
response = test_pipeline.run_async(data="input_data")
assert response["status"] == "FAILED"
assert response["error_message"] == error_message