Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 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
ffb997e
Merge to test (#301)
ikxplain Nov 5, 2024
705e44c
Development 2 Test (#308)
thiago-aixplain Nov 11, 2024
fe5dd2f
Fixing pipeline poll (#310)
thiago-aixplain Nov 13, 2024
3af70da
Merge branch 'main' into test
thiago-aixplain Nov 18, 2024
a472790
Hotfix: Increase benchmark test timeout
shreyasXplain Nov 18, 2024
a3435df
Merge to test (#315)
ikxplain Nov 20, 2024
778dd26
Development 2 Test (#322)
thiago-aixplain Nov 25, 2024
c01ade5
Merge branch 'main' into test
thiago-aixplain Nov 26, 2024
a31878c
Merge to test (#328)
ikxplain Dec 4, 2024
a3d4bb2
Development 2 Test (#333)
thiago-aixplain Dec 10, 2024
0744a4f
Development 2 Test (#335)
thiago-aixplain Dec 11, 2024
9ccaf1d
Development 2 Test (#338)
thiago-aixplain Dec 12, 2024
49ea399
Development 2 Test (#341)
thiago-aixplain Dec 16, 2024
88f18fc
Merge
thiago-aixplain Dec 16, 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
2 changes: 1 addition & 1 deletion aixplain/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
from .supplier import Supplier
from .sort_by import SortBy
from .sort_order import SortOrder
from .response_status import ResponseStatus
from .response_status import ResponseStatus
1 change: 1 addition & 0 deletions aixplain/enums/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DataType(str, Enum):
VIDEO = "video"
EMBEDDING = "embedding"
NUMBER = "number"
BOOLEAN = "boolean"

def __str__(self):
return self._value_
26 changes: 16 additions & 10 deletions aixplain/enums/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@
Function Enum
"""

import logging

from aixplain.utils import config
from aixplain.utils.request_utils import _request_with_retry
from enum import Enum
from urllib.parse import urljoin
from aixplain.utils.cache_utils import save_to_cache, load_from_cache, CACHE_FOLDER

CACHE_FILE = f"{CACHE_FOLDER}/functions.json"


def load_functions():
api_key = config.TEAM_API_KEY
backend_url = config.BACKEND_URL

url = urljoin(backend_url, "sdk/functions")
resp = load_from_cache(CACHE_FILE)
if resp is None:
url = urljoin(backend_url, "sdk/functions")

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Functions could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
save_to_cache(CACHE_FILE, resp)

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Functions could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
functions = Enum("Function", {w["id"].upper().replace("-", "_"): w["id"] for w in resp["items"]}, type=str)
functions_input_output = {
function["id"]: {
Expand All @@ -57,4 +62,5 @@ def load_functions():
}
return functions, functions_input_output


Function, FunctionInputOutput = load_functions()
37 changes: 21 additions & 16 deletions aixplain/enums/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@
Language Enum
"""

import logging

from aixplain.utils import config
from aixplain.utils.request_utils import _request_with_retry
from enum import Enum
from urllib.parse import urljoin
from aixplain.utils import config
from aixplain.utils.request_utils import _request_with_retry
from aixplain.utils.cache_utils import save_to_cache, load_from_cache, CACHE_FOLDER

CACHE_FILE = f"{CACHE_FOLDER}/languages.json"


def load_languages():
api_key = config.TEAM_API_KEY
backend_url = config.BACKEND_URL

url = urljoin(backend_url, "sdk/languages")

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Languages could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
resp = load_from_cache(CACHE_FILE)
if resp is None:
api_key = config.TEAM_API_KEY
backend_url = config.BACKEND_URL

url = urljoin(backend_url, "sdk/languages")

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Languages could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
save_to_cache(CACHE_FILE, resp)

languages = {}
for w in resp:
language = w["value"]
Expand Down
41 changes: 24 additions & 17 deletions aixplain/enums/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,36 @@
"""

import logging

from aixplain.utils import config
from aixplain.utils.request_utils import _request_with_retry
from enum import Enum
from urllib.parse import urljoin
from aixplain.utils import config
from aixplain.utils.request_utils import _request_with_retry
from aixplain.utils.cache_utils import save_to_cache, load_from_cache, CACHE_FOLDER

CACHE_FILE = f"{CACHE_FOLDER}/licenses.json"


def load_licenses():
resp = load_from_cache(CACHE_FILE)

try:
api_key = config.TEAM_API_KEY
backend_url = config.BACKEND_URL

url = urljoin(backend_url, "sdk/licenses")

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Licenses could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
return Enum("License", {"_".join(w["name"].split()): w["id"] for w in resp}, type=str)
except Exception as e:
if resp is None:
api_key = config.TEAM_API_KEY
backend_url = config.BACKEND_URL

url = urljoin(backend_url, "sdk/licenses")

headers = {"x-api-key": api_key, "Content-Type": "application/json"}
r = _request_with_retry("get", url, headers=headers)
if not 200 <= r.status_code < 300:
raise Exception(
f'Licenses could not be loaded, probably due to the set API key (e.g. "{api_key}") is not valid. For help, please refer to the documentation (https://github.com/aixplain/aixplain#api-key-setup)'
)
resp = r.json()
save_to_cache(CACHE_FILE, resp)
licenses = {"_".join(w["name"].split()): w["id"] for w in resp}
return Enum("License", licenses, type=str)
except Exception:
logging.exception("License Loading Error")
raise Exception("License Loading Error")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
Description:
Model Factory Class
"""
from typing import Dict, List, Optional, Text, Tuple, Union
from typing import Callable, Dict, List, Optional, Text, Tuple, Union
import json
import logging
from aixplain.modules.model import Model
from aixplain.modules.model.llm_model import LLM
from aixplain.modules.model.utility_model import UtilityModel, UtilityModelInput
from aixplain.enums import Function, Language, OwnershipType, Supplier, SortBy, SortOrder
from aixplain.utils import config
from aixplain.utils.file_utils import _request_with_retry
from urllib.parse import urljoin
from warnings import warn
from aixplain.enums.function import FunctionInputOutput
from datetime import datetime


class ModelFactory:
Expand All @@ -44,53 +41,58 @@ class ModelFactory:
backend_url = config.BACKEND_URL

@classmethod
def _create_model_from_response(cls, response: Dict) -> Model:
"""Converts response Json to 'Model' object
def create_utility_model(
cls,
name: Text,
code: Union[Text, Callable],
inputs: List[UtilityModelInput] = [],
description: Optional[Text] = None,
output_examples: Text = "",
) -> UtilityModel:
"""Create a utility model

Args:
response (Dict): Json from API
name (Text): name of the model
code (Union[Text, Callable]): code of the model
description (Text, optional): description of the model
inputs (List[UtilityModelInput], optional): inputs of the model
output_examples (Text, optional): output examples

Returns:
Model: Coverted 'Model' object
UtilityModel: created utility model
"""
if "api_key" not in response:
response["api_key"] = config.TEAM_API_KEY

parameters = {}
if "params" in response:
for param in response["params"]:
if "language" in param["name"]:
parameters[param["name"]] = [w["value"] for w in param["values"]]

function = Function(response["function"]["id"])
ModelClass = Model
if function == Function.TEXT_GENERATION:
ModelClass = LLM

created_at = None
if "createdAt" in response and response["createdAt"]:
created_at = datetime.fromisoformat(response["createdAt"].replace("Z", "+00:00"))
function_id = response["function"]["id"]
function = Function(function_id)
function_io = FunctionInputOutput.get(function_id, None)
input_params = {param["code"]: param for param in function_io["spec"]["params"]}
output_params = {param["code"]: param for param in function_io["spec"]["output"]}

return ModelClass(
response["id"],
response["name"],
description=response.get("description", ""),
supplier=response["supplier"],
api_key=response["api_key"],
cost=response["pricing"],
function=function,
created_at=created_at,
parameters=parameters,
input_params=input_params,
output_params=output_params,
is_subscribed=True if "subscription" in response else False,
version=response["version"]["id"],
utility_model = UtilityModel(
id="",
name=name,
description=description,
inputs=inputs,
code=code,
function=Function.UTILITIES,
api_key=config.TEAM_API_KEY,
output_examples=output_examples,
)
utility_model.validate()
payload = utility_model.to_dict()
url = urljoin(cls.backend_url, "sdk/utilities")
headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"}
try:
logging.info(f"Start service for POST Utility Model - {url} - {headers} - {payload}")
r = _request_with_retry("post", url, headers=headers, json=payload)
resp = r.json()
except Exception as e:
logging.error(f"Error creating utility model: {e}")
raise e

if 200 <= r.status_code < 300:
utility_model.id = resp["id"]
logging.info(f"Utility Model Creation: Model {utility_model.id} instantiated.")
return utility_model
else:
error_message = (
f"Utility Model Creation: Failed to create utility model. Status Code: {r.status_code}. Error: {resp}"
)
logging.error(error_message)
raise Exception(error_message)

@classmethod
def get(cls, model_id: Text, api_key: Optional[Text] = None) -> Model:
Expand Down Expand Up @@ -125,95 +127,16 @@ def get(cls, model_id: Text, api_key: Optional[Text] = None) -> Model:
resp["api_key"] = config.TEAM_API_KEY
if api_key is not None:
resp["api_key"] = api_key
model = cls._create_model_from_response(resp)
from aixplain.factories.model_factory.utils import create_model_from_response

model = create_model_from_response(resp)
logging.info(f"Model Creation: Model {model_id} instantiated.")
return model
else:
error_message = f"Model GET Error: Failed to retrieve model {model_id}. Status Code: {r.status_code}. Error: {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def create_asset_from_id(cls, model_id: Text) -> Model:
warn(
'This method will be deprecated in the next versions of the SDK. Use "get" instead.',
DeprecationWarning,
stacklevel=2,
)
return cls.get(model_id)

@classmethod
def _get_assets_from_page(
cls,
query,
page_number: int,
page_size: int,
function: Function,
suppliers: Union[Supplier, List[Supplier]],
source_languages: Union[Language, List[Language]],
target_languages: Union[Language, List[Language]],
is_finetunable: bool = None,
ownership: Optional[Tuple[OwnershipType, List[OwnershipType]]] = None,
sort_by: Optional[SortBy] = None,
sort_order: SortOrder = SortOrder.ASCENDING,
) -> List[Model]:
try:
url = urljoin(cls.backend_url, "sdk/models/paginate")
filter_params = {"q": query, "pageNumber": page_number, "pageSize": page_size}
if is_finetunable is not None:
filter_params["isFineTunable"] = is_finetunable
if function is not None:
filter_params["functions"] = [function.value]
if suppliers is not None:
if isinstance(suppliers, Supplier) is True:
suppliers = [suppliers]
filter_params["suppliers"] = [supplier.value["id"] for supplier in suppliers]
if ownership is not None:
if isinstance(ownership, OwnershipType) is True:
ownership = [ownership]
filter_params["ownership"] = [ownership_.value for ownership_ in ownership]

lang_filter_params = []
if source_languages is not None:
if isinstance(source_languages, Language):
source_languages = [source_languages]
if function == Function.TRANSLATION:
lang_filter_params.append({"code": "sourcelanguage", "value": source_languages[0].value["language"]})
else:
lang_filter_params.append({"code": "language", "value": source_languages[0].value["language"]})
if source_languages[0].value["dialect"] != "":
lang_filter_params.append({"code": "dialect", "value": source_languages[0].value["dialect"]})
if target_languages is not None:
if isinstance(target_languages, Language):
target_languages = [target_languages]
if function == Function.TRANSLATION:
code = "targetlanguage"
lang_filter_params.append({"code": code, "value": target_languages[0].value["language"]})
if sort_by is not None:
filter_params["sort"] = [{"dir": sort_order.value, "field": sort_by.value}]
if len(lang_filter_params) != 0:
filter_params["ioFilter"] = lang_filter_params

headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"}

logging.info(f"Start service for POST Models Paginate - {url} - {headers} - {json.dumps(filter_params)}")
r = _request_with_retry("post", url, headers=headers, json=filter_params)
resp = r.json()

except Exception as e:
error_message = f"Listing Models: Error in getting Models on Page {page_number}: {e}"
logging.error(error_message, exc_info=True)
return []
if 200 <= r.status_code < 300:
logging.info(f"Listing Models: Status of getting Models on Page {page_number}: {r.status_code}")
all_models = resp["items"]
model_list = [cls._create_model_from_response(model_info_json) for model_info_json in all_models]
return model_list, resp["total"]
else:
error_message = f"Listing Models Error: Failed to retrieve models. Status Code: {r.status_code}. Error: {resp}"
logging.error(error_message)
raise Exception(error_message)

@classmethod
def list(
cls,
Expand Down Expand Up @@ -244,7 +167,9 @@ def list(
Returns:
List[Model]: List of models based on given filters
"""
models, total = cls._get_assets_from_page(
from aixplain.factories.model_factory.utils import get_assets_from_page

models, total = get_assets_from_page(
query,
page_number,
page_size,
Expand Down
Loading