-
Notifications
You must be signed in to change notification settings - Fork 23
Update model running endpoints from v1 to v2 #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8bd12fd
Update model running endpoints from v1 to v2
thiago-aixplain c8947d1
Support v1/v2 model serving endpoints
thiago-aixplain ca07aa6
Adding the details in case of validation error
thiago-aixplain bbc37b2
Adding one more test for asynchronous method in new endpoint
thiago-aixplain 5f8f1db
Merge branch 'development' into ENG-711-newModelEndpoints
thiago-aixplain e4a679a
Setting error details and treating when data is null
thiago-aixplain 27bef29
Merge branch 'ENG-711-newModelEndpoints' of https://github.com/aixpla…
thiago-aixplain dc17462
Adding missing import in unit tests for models
thiago-aixplain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| __author__ = "thiagocastroferreira" | ||
|
|
||
| import json | ||
| import logging | ||
| from aixplain.utils.file_utils import _request_with_retry | ||
| from typing import Dict, Text, Union | ||
|
|
||
|
|
||
| def build_payload(data: Union[Text, Dict], parameters: Dict = {}): | ||
| from aixplain.factories import FileFactory | ||
|
|
||
| data = FileFactory.to_link(data) | ||
| if isinstance(data, dict): | ||
| payload = data | ||
| else: | ||
| try: | ||
| payload = json.loads(data) | ||
| if isinstance(payload, dict) is False: | ||
| if isinstance(payload, int) is True or isinstance(payload, float) is True: | ||
| payload = str(payload) | ||
| payload = {"data": payload} | ||
| except Exception: | ||
| payload = {"data": data} | ||
| payload.update(parameters) | ||
| payload = json.dumps(payload) | ||
| return payload | ||
|
|
||
|
|
||
| def call_run_endpoint(url: Text, api_key: Text, payload: Dict) -> Dict: | ||
| headers = {"x-api-key": api_key, "Content-Type": "application/json"} | ||
|
|
||
| resp = "unspecified error" | ||
| try: | ||
| r = _request_with_retry("post", url, headers=headers, data=payload) | ||
| resp = r.json() | ||
| except Exception as e: | ||
| logging.error(f"Error in request: {e}") | ||
| response = { | ||
| "status": "FAILED", | ||
| "completed": True, | ||
| "error_message": "Model Run: An error occurred while processing your request.", | ||
| } | ||
|
|
||
| if 200 <= r.status_code < 300: | ||
| logging.info(f"Result of request: {r.status_code} - {resp}") | ||
| status = resp.get("status", "IN_PROGRESS") | ||
hadi-aix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| data = resp.get("data", None) | ||
| if status == "IN_PROGRESS": | ||
| if data is not None: | ||
| response = {"status": status, "url": data, "completed": True} | ||
| else: | ||
| response = { | ||
| "status": "FAILED", | ||
| "completed": True, | ||
| "error_message": "Model Run: An error occurred while processing your request.", | ||
| } | ||
| else: | ||
| response = {"status": status, "data": data, "completed": True} | ||
| else: | ||
| if r.status_code == 401: | ||
| error = f"Unauthorized API key: Please verify the spelling of the API key and its current validity. Details: {resp}" | ||
| elif 460 <= r.status_code < 470: | ||
| error = f"Subscription-related error: Please ensure that your subscription is active and has not expired. Details: {resp}" | ||
| elif 470 <= r.status_code < 480: | ||
| error = f"Billing-related error: Please ensure you have enough credits to run this model. Details: {resp}" | ||
| elif 480 <= r.status_code < 490: | ||
| error = f"Supplier-related error: Please ensure that the selected supplier provides the model you are trying to access. Details: {resp}" | ||
| elif 490 <= r.status_code < 500: | ||
hadi-aix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| error = f"Validation-related error: Please ensure all required fields are provided and correctly formatted. Details: {resp}" | ||
| else: | ||
| status_code = str(r.status_code) | ||
| error = f"Status {status_code} - Unspecified error: {resp}" | ||
| response = {"status": "FAILED", "error_message": error, "completed": True} | ||
| logging.error(f"Error in request: {r.status_code}: {error}") | ||
| return response | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.