Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
1b67aed
Create bounds for FineTune hyperparameters (#103)
lucas-aixplain Jan 15, 2024
61359d8
Fixing pipeline general asset test (#106)
thiago-aixplain Jan 15, 2024
c293a69
Merge dev to test (#107)
lucas-aixplain Jan 16, 2024
572750c
Development to Test (#109)
thiago-aixplain Jan 17, 2024
adfe272
Merge to test (#111)
ikxplain Jan 24, 2024
8365218
Update Finetuner functional tests (#112)
lucas-aixplain Jan 29, 2024
43a2b00
Merge branch 'test' into development
thiago-aixplain Jan 29, 2024
846e300
Merge dev to test (#113)
lucas-aixplain Jan 29, 2024
359209a
Hf deployment test (#114)
mikelam-us-aixplain Jan 29, 2024
74af040
Hf deployment test (#115)
mikelam-us-aixplain Jan 29, 2024
ffddc00
Hf deployment test (#118)
mikelam-us-aixplain Jan 30, 2024
7adfddd
Hf deployment test (#117)
mikelam-us-aixplain Jan 30, 2024
367ad74
Merge branch 'main' into test
ikxplain Jan 31, 2024
4c5358c
Do not download textual URLs (#120)
thiago-aixplain Feb 1, 2024
cb14b5a
Enable api key parameter in data asset creation (#122)
thiago-aixplain Feb 5, 2024
607852e
Merge to test (#124)
ikxplain Feb 6, 2024
66a043b
Update Finetuner hyperparameters (#125)
lucas-aixplain Feb 7, 2024
3b7f8b7
Merge dev to test (#126)
lucas-aixplain Feb 7, 2024
3bc04d3
Add new LLMs finetuner models (mistral and solar) (#128)
lucas-aixplain Feb 13, 2024
5954b63
Merge dev to test (#129)
lucas-aixplain Feb 13, 2024
58855c1
Enabling dataset ID and model ID as parameters for finetuner creation…
thiago-aixplain Feb 15, 2024
426213e
Fix supplier representation of a model (#132)
thiago-aixplain Feb 16, 2024
d62ad83
Fixing indentation in documentation sample code (#134)
thiago-aixplain Feb 21, 2024
7593033
Merge to test (#135)
ikxplain Feb 28, 2024
2f107e7
Update FineTune unit and functional tests (#136)
lucas-aixplain Mar 1, 2024
b5112dc
Merge branch 'test' into development
lucas-aixplain Mar 1, 2024
e6f1f02
Merge dev to test (#137)
lucas-aixplain Mar 1, 2024
32179d6
Click fix (#140)
mikelam-us-aixplain Mar 5, 2024
501e27b
Merge branch 'main' into test
thiago-aixplain Mar 7, 2024
94cf5f0
Merge branch 'test' into development
lucas-aixplain Mar 12, 2024
e0e260c
Merge to test (#142)
ikxplain Mar 12, 2024
34861a3
M 5905660469 enhance benchmark job response (#145)
shreyasXplain Mar 18, 2024
6fc9646
M 5905660469 enhance benchmark job response (#146)
shreyasXplain Mar 19, 2024
b4e5b67
New pipeline functional tests (#143)
thiago-aixplain Mar 19, 2024
873cb6a
M 6107719447 check finetuner status (#133)
thiago-aixplain Mar 21, 2024
c2a2cfd
Update metric.py (#147)
shreyasXplain Mar 22, 2024
88ab478
Dev 2 Test version 0.2.11 (#149)
thiago-aixplain Mar 22, 2024
e4b076b
Fixing finetune checker test and doc (#150)
thiago-aixplain Mar 22, 2024
84bd827
Development to Test (#151)
thiago-aixplain Mar 22, 2024
451f309
Skip model onboard and deployment tests (#153)
thiago-aixplain Mar 25, 2024
8df2bd0
Saving/Update Pipeline Services (#154)
thiago-aixplain Mar 26, 2024
bdf33b1
Merge to test. (#156)
ikxplain Mar 27, 2024
28f3092
Do not run service mode tests for specific pipelines (#159)
thiago-aixplain Apr 3, 2024
b86cf45
Merge branch 'test' into development
thiago-aixplain Apr 3, 2024
d1debf5
Development 2 Test (#160)
thiago-aixplain Apr 3, 2024
b45f12e
Fix on Metadata (#162)
thiago-aixplain Apr 9, 2024
dc45128
Merge to test (#163)
ikxplain Apr 10, 2024
5d75317
Interval label new structures (#157)
thiago-aixplain Apr 15, 2024
b43e7ec
Development 2 Test - Release 0.2.11 (#165)
thiago-aixplain Apr 15, 2024
da84847
Merge branch 'main' into test
ikxplain Apr 16, 2024
e4b2b22
Support text labels (#167)
thiago-aixplain Apr 17, 2024
4ccaa36
SDK's UML diagram (#169)
thiago-aixplain Apr 19, 2024
b1997cf
Merge remote-tracking branch 'origin/development' into test
ikxplain Apr 29, 2024
d3da2d2
Merge remote-tracking branch 'origin/test' into test
ikxplain Apr 29, 2024
d66d7d9
Merge dev to test (#173)
lucas-aixplain May 2, 2024
9d6f009
Merge to test (#177)
ikxplain May 8, 2024
ff6e204
Merge to test (#183)
ikxplain May 28, 2024
6ac5e63
Michael dev merge (#190)
mikelam-us-aixplain Jun 11, 2024
e9aa472
Merge to test (#188)
ikxplain Jun 11, 2024
662104f
Merge branch 'main' into test
thiago-aixplain Jun 18, 2024
d342800
Merge to test (#199)
ikxplain Jun 26, 2024
ff688c2
Fix pipeline functional test (#201)
lucas-aixplain Jul 3, 2024
815dde8
Merge branch 'main' into test
lucas-aixplain Jul 4, 2024
93f57bd
Merge to test. (#203)
ikxplain Jul 11, 2024
78c3bd9
Merge dev to test (#205)
lucas-aixplain Jul 13, 2024
a532df2
Merge to test (#209)
hadi-aix Jul 24, 2024
d8031c8
Merge to test (#217)
ikxplain Aug 13, 2024
024381f
Development 2 Test (#223)
thiago-aixplain Aug 13, 2024
d77fb93
Solving conflicts
thiago-aixplain Aug 14, 2024
419eed3
Removing duplicated test
thiago-aixplain Aug 14, 2024
348eead
Merge to test (#236)
ikxplain Aug 22, 2024
a3b19e5
Merge branch 'main' into test
thiago-aixplain Aug 27, 2024
93d0e11
Development 2 Test (#239)
thiago-aixplain Aug 27, 2024
272488b
Merge to test (#246)
ikxplain Sep 4, 2024
e3f261e
Merge branch 'main' into test
ikxplain Sep 10, 2024
45d4c3f
Merge to test (#250)
ikxplain Sep 19, 2024
a747d69
Development 2 Test (#252)
thiago-aixplain Sep 23, 2024
357aaf2
Development 2 Test (#254)
thiago-aixplain Sep 24, 2024
350e563
Development 2 Test (#256)
thiago-aixplain Sep 26, 2024
14f9000
Merge branch 'main' into test
ikxplain Sep 27, 2024
5b1d481
Merge to test (#263)
ikxplain Oct 8, 2024
f515da6
Merge branch 'main' into test
thiago-aixplain Oct 9, 2024
b9e8739
Development 2 Test (#267)
thiago-aixplain Oct 9, 2024
629e934
Development (#269)
ikxplain Oct 9, 2024
b74af97
Merge branch 'main' into test
thiago-aixplain Oct 9, 2024
9149952
Development 2 Test (#273)
thiago-aixplain Oct 10, 2024
f6b783b
Merge branch 'main' into test
thiago-aixplain Oct 10, 2024
5f8ee84
Merge to test (#280)
ikxplain Oct 22, 2024
50746a8
Development 2 Test (#287)
thiago-aixplain Oct 29, 2024
5a0f40b
Development 2 Test (#289)
thiago-aixplain Oct 29, 2024
529b247
Development 2 Test (#293)
thiago-aixplain Oct 30, 2024
680e355
Merge branch 'main' into test
ikxplain Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions aixplain/factories/api_key_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
from datetime import datetime
from typing import Text, List, Optional, Dict, Union
from aixplain.utils.file_utils import _request_with_retry
from aixplain.modules.api_key import APIKey, APIKeyGlobalLimits, APIKeyUsageLimit
from aixplain.modules.api_key import APIKey, APIKeyLimits, APIKeyUsageLimit


class APIKeyFactory:
backend_url = config.BACKEND_URL

@classmethod
def get(cls, api_key: Text) -> APIKey:
"""Get an API key"""
for api_key_obj in cls.list():
if str(api_key_obj.access_key).startswith(api_key[:4]) and str(api_key_obj.access_key).endswith(api_key[-4:]):
return api_key_obj
raise Exception(f"API Key Error: API key {api_key} not found")

@classmethod
def list(cls) -> List[APIKey]:
"""List all API keys"""
Expand All @@ -30,7 +38,7 @@ def list(cls) -> List[APIKey]:
name=key["name"],
budget=key["budget"] if "budget" in key else None,
global_limits=key["globalLimits"] if "globalLimits" in key else None,
asset_limits=key["assetLimits"] if "assetLimits" in key else [],
asset_limits=key["assetsLimits"] if "assetsLimits" in key else [],
expires_at=key["expiresAt"] if "expiresAt" in key else None,
access_key=key["accessKey"],
is_admin=key["isAdmin"],
Expand All @@ -46,8 +54,8 @@ def create(
cls,
name: Text,
budget: int,
global_limits: Union[Dict, APIKeyGlobalLimits],
asset_limits: List[Union[Dict, APIKeyGlobalLimits]],
global_limits: Union[Dict, APIKeyLimits],
asset_limits: List[Union[Dict, APIKeyLimits]],
expires_at: datetime,
) -> APIKey:
"""Create a new API key"""
Expand Down Expand Up @@ -84,6 +92,7 @@ def create(
@classmethod
def update(cls, api_key: APIKey) -> APIKey:
"""Update an existing API key"""
api_key.validate()
try:
resp = "Unspecified error"
url = f"{cls.backend_url}/sdk/api-keys/{api_key.id}"
Expand Down Expand Up @@ -112,12 +121,10 @@ def update(cls, api_key: APIKey) -> APIKey:
raise Exception(f"API Key Update Error: Failed to update API key with ID {api_key.id}. Error: {str(resp)}")

@classmethod
def get_usage_limit(cls, api_key: Text = config.TEAM_API_KEY, asset_id: Optional[Text] = None) -> APIKeyUsageLimit:
"""Get API key usage limit"""
def get_usage_limits(cls, api_key: Text = config.TEAM_API_KEY, asset_id: Optional[Text] = None) -> List[APIKeyUsageLimit]:
"""Get API key usage limits"""
try:
url = f"{config.BACKEND_URL}/sdk/api-keys/usage-limits"
if asset_id is not None:
url += f"?assetId={asset_id}"
headers = {"Authorization": f"Token {api_key}", "Content-Type": "application/json"}
logging.info(f"Start service for GET API Key Usage - {url} - {headers}")
r = _request_with_retry("GET", url, headers=headers)
Expand All @@ -128,11 +135,16 @@ def get_usage_limit(cls, api_key: Text = config.TEAM_API_KEY, asset_id: Optional
raise Exception(f"{message}")

if 200 <= r.status_code < 300:
return APIKeyUsageLimit(
request_count=resp["requestCount"],
request_count_limit=resp["requestCountLimit"],
token_count=resp["tokenCount"],
token_count_limit=resp["tokenCountLimit"],
)
return [
APIKeyUsageLimit(
daily_request_count=limit["requestCount"],
daily_request_limit=limit["requestCountLimit"],
daily_token_count=limit["tokenCount"],
daily_token_limit=limit["tokenCountLimit"],
model=limit["assetId"] if "assetId" in limit else None,
)
for limit in resp
if asset_id is None or ("assetId" in limit and limit["assetId"] == asset_id)
]
else:
raise Exception(f"API Key Usage Error: Failed to get usage. Error: {str(resp)}")
55 changes: 37 additions & 18 deletions aixplain/factories/benchmark_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"""

import logging
from typing import Dict, List, Optional, Text
from typing import Dict, List, Text
import json
import pandas as pd
from pathlib import Path
from aixplain.enums.supplier import Supplier
from aixplain.modules import Dataset, Metric, Model
from aixplain.modules.benchmark_job import BenchmarkJob
Expand All @@ -34,9 +32,8 @@
from aixplain.factories.dataset_factory import DatasetFactory
from aixplain.factories.model_factory import ModelFactory
from aixplain.utils import config
from aixplain.utils.file_utils import _request_with_retry, save_file
from aixplain.utils.file_utils import _request_with_retry
from urllib.parse import urljoin
from warnings import warn


class BenchmarkFactory:
Expand Down Expand Up @@ -117,18 +114,25 @@ def get(cls, benchmark_id: str) -> Benchmark:
logging.info(f"Start service for GET Benchmark - {url} - {headers}")
r = _request_with_retry("get", url, headers=headers)
resp = r.json()
benchmark = cls._create_benchmark_from_response(resp)

except Exception as e:
status_code = 400
if resp is not None and "statusCode" in resp:
status_code = resp["statusCode"]
message = resp["message"]
message = f"Benchmark Creation: Status {status_code} - {message}"
else:
message = f"Benchmark Creation: Unspecified Error"
message = "Benchmark Creation: Unspecified Error"
logging.error(f"Benchmark Creation Failed: {e}")
raise Exception(f"Status {status_code}: {message}")
return benchmark
if 200 <= r.status_code < 300:
benchmark = cls._create_benchmark_from_response(resp)
logging.info(f"Benchmark {benchmark_id} retrieved successfully.")
return benchmark
else:
error_message = f"Benchmark GET Error: Status {r.status_code} - {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def get_job(cls, job_id: Text) -> BenchmarkJob:
Expand Down Expand Up @@ -189,7 +193,7 @@ def create(cls, name: str, dataset_list: List[Dataset], model_list: List[Model],
"""
payload = {}
try:
url = urljoin(cls.backend_url, f"sdk/benchmarks")
url = urljoin(cls.backend_url, "sdk/benchmarks")
headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}
payload = {
"name": name,
Expand All @@ -204,12 +208,19 @@ def create(cls, name: str, dataset_list: List[Dataset], model_list: List[Model],
payload = json.dumps(clean_payload)
r = _request_with_retry("post", url, headers=headers, data=payload)
resp = r.json()
logging.info(f"Creating Benchmark Job: Status for {name}: {resp}")
return cls.get(resp["id"])

except Exception as e:
error_message = f"Creating Benchmark Job: Error in Creating Benchmark with payload {payload} : {e}"
logging.error(error_message, exc_info=True)
return None
raise Exception(error_message)

if 200 <= r.status_code < 300:
logging.info(f"Benchmark {name} created successfully.")
return cls.get(resp["id"])
else:
error_message = f"Benchmark Creation Error: Status {r.status_code} - {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def list_normalization_options(cls, metric: Metric, model: Model) -> List[str]:
Expand All @@ -223,21 +234,28 @@ def list_normalization_options(cls, metric: Metric, model: Model) -> List[str]:
List[str]: List of supported normalization options
"""
try:
url = urljoin(cls.backend_url, f"sdk/benchmarks/normalization-options")
url = urljoin(cls.backend_url, "sdk/benchmarks/normalization-options")
if cls.aixplain_key != "":
headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"}
else:
headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}
payload = json.dumps({"metricId": metric.id, "modelIds": [model.id]})
r = _request_with_retry("post", url, headers=headers, data=payload)
resp = r.json()
logging.info(f"Listing Normalization Options: Status of listing options: {resp}")
normalization_options = [item["value"] for item in resp]
return normalization_options

except Exception as e:
error_message = f"Listing Normalization Options: Error in getting Normalization Options: {e}"
logging.error(error_message, exc_info=True)
return []
raise Exception(error_message)

if 200 <= r.status_code < 300:
logging.info("Listing Normalization Options: ")
normalization_options = [item["value"] for item in resp]
return normalization_options
else:
error_message = f"Error listing normalization options: Status {r.status_code} - {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def get_benchmark_job_scores(cls, job_id):
Expand All @@ -255,7 +273,8 @@ def __get_model_name(model_id):
if model.version is not None:
name = f"{name}({model.version})"
return name

benchmarkJob = cls.get_job(job_id)
scores_df = benchmarkJob.get_scores()
scores_df["Model"] = scores_df["Model"].apply(lambda x: __get_model_name(x))
return scores_df
return scores_df
91 changes: 56 additions & 35 deletions aixplain/factories/corpus_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Corpus Factory Class
"""

import aixplain.utils.config as config
import aixplain.processes.data_onboarding.onboard_functions as onboard_functions
import json
import logging
Expand Down Expand Up @@ -86,12 +85,12 @@ def __from_response(cls, response: Dict) -> Corpus:

try:
license = License(response["license"]["typeId"])
except:
except Exception:
license = None

try:
length = int(response["segmentsCount"])
except:
except Exception:
length = None

corpus = Corpus(
Expand All @@ -116,17 +115,27 @@ def get(cls, corpus_id: Text) -> Corpus:
Returns:
Corpus: Created 'Corpus' object
"""
url = urljoin(cls.backend_url, f"sdk/corpora/{corpus_id}/overview")
if cls.aixplain_key != "":
headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"}
try:
url = urljoin(cls.backend_url, f"sdk/corpora/{corpus_id}/overview")
if cls.aixplain_key != "":
headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"}
else:
headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}
logging.info(f"Start service for GET Corpus - {url} - {headers}")
r = _request_with_retry("get", url, headers=headers)
resp = r.json()

except Exception as e:
error_message = f"Error retrieving Corpus {corpus_id}: {str(e)}"
logging.error(error_message, exc_info=True)
raise Exception(error_message)
if 200 <= r.status_code < 300:
logging.info(f"Corpus {corpus_id} retrieved successfully.")
return cls.__from_response(resp)
else:
headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}
logging.info(f"Start service for GET Corpus - {url} - {headers}")
r = _request_with_retry("get", url, headers=headers)
resp = r.json()
if "statusCode" in resp and resp["statusCode"] == 404:
raise Exception(f"Corpus GET Error: Dataset {corpus_id} not found.")
return cls.__from_response(resp)
error_message = f"Corpus GET Error: Status {r.status_code} - {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def create_asset_from_id(cls, corpus_id: Text) -> Corpus:
Expand Down Expand Up @@ -168,7 +177,7 @@ def list(
else:
headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}

assert 0 < page_size <= 100, f"Corpus List Error: Page size must be greater than 0 and not exceed 100."
assert 0 < page_size <= 100, "Corpus List Error: Page size must be greater than 0 and not exceed 100."
payload = {"pageSize": page_size, "pageNumber": page_number, "sort": [{"field": "createdAt", "dir": -1}]}

if query is not None:
Expand All @@ -188,26 +197,38 @@ def list(
language = [language]
payload["language"] = [lng.value["language"] for lng in language]

logging.info(f"Start service for POST List Corpus - {url} - {headers} - {json.dumps(payload)}")
r = _request_with_retry("post", url, headers=headers, json=payload)
resp = r.json()
corpora, page_total, total = [], 0, 0
if "results" in resp:
results = resp["results"]
page_total = resp["pageTotal"]
total = resp["total"]
logging.info(f"Response for POST List Corpus - Page Total: {page_total} / Total: {total}")
for corpus in results:
corpus_ = cls.__from_response(corpus)
# add languages
languages = []
for lng in corpus["languages"]:
if "dialect" not in lng:
lng["dialect"] = ""
languages.append(Language(lng))
corpus_.kwargs["languages"] = languages
corpora.append(corpus_)
return {"results": corpora, "page_total": page_total, "page_number": page_number, "total": total}
try:
logging.info(f"Start service for POST List Corpus - {url} - {headers} - {json.dumps(payload)}")
r = _request_with_retry("post", url, headers=headers, json=payload)
resp = r.json()

except Exception as e:
error_message = f"Error listing corpora: {str(e)}"
logging.error(error_message, exc_info=True)
raise Exception(error_message)

if 200 <= r.status_code < 300:
corpora, page_total, total = [], 0, 0
if "results" in resp:
results = resp["results"]
page_total = resp["pageTotal"]
total = resp["total"]
logging.info(f"Response for POST List Corpus - Page Total: {page_total} / Total: {total}")
for corpus in results:
corpus_ = cls.__from_response(corpus)
# add languages
languages = []
for lng in corpus["languages"]:
if "dialect" not in lng:
lng["dialect"] = ""
languages.append(Language(lng))
corpus_.kwargs["languages"] = languages
corpora.append(corpus_)
return {"results": corpora, "page_total": page_total, "page_number": page_number, "total": total}
else:
error_message = f"Corpus List Error: Status {r.status_code} - {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def get_assets_from_page(
Expand Down Expand Up @@ -245,7 +266,7 @@ def create(
functions: List[Function] = [],
privacy: Privacy = Privacy.PRIVATE,
error_handler: ErrorHandler = ErrorHandler.SKIP,
api_key: Optional[Text] = None
api_key: Optional[Text] = None,
) -> Dict:
"""Asynchronous call to Upload a corpus to the user's dashboard.

Expand Down
Loading