From 260d0749c8e7aee79a1c204122e0828200ad95ce Mon Sep 17 00:00:00 2001 From: Thiago Castro Ferreira Date: Wed, 22 Nov 2023 21:22:16 +0000 Subject: [PATCH 1/2] Ownership filter --- aixplain/enums/__init__.py | 1 + aixplain/enums/ownership_type.py | 32 +++++++++++++++++++ aixplain/factories/model_factory.py | 23 ++++++++++--- aixplain/modules/model.py | 11 ++----- .../general_assets/asset_functional_test.py | 8 ++++- 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 aixplain/enums/ownership_type.py diff --git a/aixplain/enums/__init__.py b/aixplain/enums/__init__.py index 76e2245b..eaed5a77 100644 --- a/aixplain/enums/__init__.py +++ b/aixplain/enums/__init__.py @@ -7,6 +7,7 @@ from .language import Language from .license import License from .onboard_status import OnboardStatus +from .ownership_type import OwnershipType from .privacy import Privacy from .storage_type import StorageType from .supplier import Supplier diff --git a/aixplain/enums/ownership_type.py b/aixplain/enums/ownership_type.py new file mode 100644 index 00000000..951a9f85 --- /dev/null +++ b/aixplain/enums/ownership_type.py @@ -0,0 +1,32 @@ +__author__ = "aiXplain" + +""" +Copyright 2023 The aiXplain SDK authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Author: aiXplain team +Date: November 22nd 2023 +Description: + Asset Ownership Type +""" + +from enum import Enum + + +class OwnershipType(Enum): + SUBSCRIBED = "SUBSCRIBED" + OWNED = "OWNED" + + def __str__(self): + return self._value_ diff --git a/aixplain/factories/model_factory.py b/aixplain/factories/model_factory.py index 029e8648..c16f0bc9 100644 --- a/aixplain/factories/model_factory.py +++ b/aixplain/factories/model_factory.py @@ -20,11 +20,11 @@ Description: Model Factory Class """ -from typing import Dict, List, Optional, Text, Union +from typing import Dict, List, Optional, Text, Tuple, Union import json import logging from aixplain.modules.model import Model -from aixplain.enums import Function, Language, Supplier +from aixplain.enums import Function, Language, OwnershipType, Supplier from aixplain.utils import config from aixplain.utils.file_utils import _request_with_retry from urllib.parse import urljoin @@ -70,6 +70,7 @@ def _create_model_from_response(cls, response: Dict) -> Model: pricing=response["pricing"], function=Function(response["function"]["id"]), parameters=parameters, + is_subscribed=True if "subscription" in response else False, ) @classmethod @@ -130,6 +131,7 @@ def _get_assets_from_page( source_languages: Union[Language, List[Language]], target_languages: Union[Language, List[Language]], is_finetunable: bool = None, + ownership: Optional[Tuple[OwnershipType, List[OwnershipType]]] = None, ) -> List[Model]: try: url = urljoin(cls.backend_url, f"sdk/models/paginate") @@ -142,6 +144,10 @@ def _get_assets_from_page( 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): @@ -186,6 +192,7 @@ def list( source_languages: Optional[Union[Language, List[Language]]] = None, target_languages: Optional[Union[Language, List[Language]]] = None, is_finetunable: Optional[bool] = None, + ownership: Optional[Tuple[OwnershipType, List[OwnershipType]]] = None, page_number: int = 0, page_size: int = 20, ) -> List[Model]: @@ -196,16 +203,24 @@ def list( source_languages (Optional[Union[Language, List[Language]]], optional): language filter of input data. Defaults to None. target_languages (Optional[Union[Language, List[Language]]], optional): language filter of output data. Defaults to None. is_finetunable (Optional[bool], optional): can be finetuned or not. Defaults to None. + ownership (Optional[Tuple[OwnershipType, List[OwnershipType]]], optional): Ownership filters (e.g. SUBSCRIBED, OWNER). Defaults to None. page_number (int, optional): page number. Defaults to 0. page_size (int, optional): page size. Defaults to 20. Returns: List[Model]: List of models based on given filters """ - print(f"Function: {function}") try: models, total = cls._get_assets_from_page( - query, page_number, page_size, function, suppliers, source_languages, target_languages, is_finetunable + query, + page_number, + page_size, + function, + suppliers, + source_languages, + target_languages, + is_finetunable, + ownership, ) return { "results": models, diff --git a/aixplain/modules/model.py b/aixplain/modules/model.py index 440181a1..69109565 100644 --- a/aixplain/modules/model.py +++ b/aixplain/modules/model.py @@ -61,6 +61,7 @@ def __init__( supplier: Text = "aiXplain", version: Text = "1.0", function: Optional[Text] = None, + is_subscribed: bool = False, **additional_info, ) -> None: """Model Init @@ -73,6 +74,7 @@ def __init__( supplier (Text, optional): model supplier. Defaults to "aiXplain". version (Text, optional): version of the model. Defaults to "1.0". function (Text, optional): model AI function. Defaults to None. + is_subscribed (bool, optional): Is the user subscribed. Defaults to False. **additional_info: Any additional Model info to be saved """ super().__init__(id, name, description, supplier, version) @@ -81,14 +83,7 @@ def __init__( self.url = config.MODELS_RUN_URL self.backend_url = config.BACKEND_URL self.function = function - - def _is_subscribed(self) -> bool: - """Returns if the model is subscribed to - - Returns: - bool: True if subscribed - """ - return self.api_key is not None + self.is_subscribed = is_subscribed def to_dict(self) -> Dict: """Get the model info as a Dictionary diff --git a/tests/functional/general_assets/asset_functional_test.py b/tests/functional/general_assets/asset_functional_test.py index 0c410df2..0c720fa2 100644 --- a/tests/functional/general_assets/asset_functional_test.py +++ b/tests/functional/general_assets/asset_functional_test.py @@ -4,7 +4,7 @@ load_dotenv() from aixplain.factories import ModelFactory, DatasetFactory, MetricFactory, PipelineFactory from pathlib import Path -from aixplain.enums import Function, Supplier +from aixplain.enums import Function, OwnershipType, Supplier import pytest @@ -63,6 +63,12 @@ def test_model_supplier(): assert model.supplier.value in [desired_supplier.value for desired_supplier in desired_suppliers] +def test_model_ownership(): + models = ModelFactory.list(ownership=OwnershipType.SUBSCRIBED)["results"] + for model in models: + assert model.is_subscribed == True + + def test_model_query(): query = "Mongo" models = ModelFactory.list(query=query)["results"] From 1cd76ef16e825b1c081f770e42d8ab3f81ccabbe Mon Sep 17 00:00:00 2001 From: Thiago Castro Ferreira Date: Thu, 23 Nov 2023 00:43:07 +0000 Subject: [PATCH 2/2] Replacing cls.api_key for config.TEAM_API_KEY --- aixplain/factories/asset_factory.py | 1 - aixplain/factories/benchmark_factory.py | 12 +++--- aixplain/factories/corpus_factory.py | 5 +-- aixplain/factories/data_factory.py | 4 +- aixplain/factories/dataset_factory.py | 6 +-- .../factories/finetune_factory/__init__.py | 4 +- aixplain/factories/metric_factory.py | 39 ++++++++++--------- aixplain/factories/model_factory.py | 22 +++++------ aixplain/factories/pipeline_factory.py | 12 +++--- 9 files changed, 47 insertions(+), 58 deletions(-) diff --git a/aixplain/factories/asset_factory.py b/aixplain/factories/asset_factory.py index 33edd13d..460f7cfa 100644 --- a/aixplain/factories/asset_factory.py +++ b/aixplain/factories/asset_factory.py @@ -28,7 +28,6 @@ class AssetFactory: - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL diff --git a/aixplain/factories/benchmark_factory.py b/aixplain/factories/benchmark_factory.py index b016f202..88d2411b 100644 --- a/aixplain/factories/benchmark_factory.py +++ b/aixplain/factories/benchmark_factory.py @@ -42,11 +42,9 @@ class BenchmarkFactory: """A static class for creating and managing the Benchmarking experience. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -76,7 +74,7 @@ def _get_benchmark_jobs_from_benchmark_id(cls, benchmark_id: Text) -> List[Bench if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} r = _request_with_retry("get", url, headers=headers) resp = r.json() job_list = [cls._create_benchmark_job_from_response(job_info) for job_info in resp] @@ -114,7 +112,7 @@ def get(cls, benchmark_id: str) -> Benchmark: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Benchmark - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() @@ -145,7 +143,7 @@ def get_job(cls, job_id: Text) -> BenchmarkJob: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} r = _request_with_retry("get", url, headers=headers) resp = r.json() benchmarkJob = cls._create_benchmark_job_from_response(resp) @@ -191,7 +189,7 @@ def create(cls, name: str, dataset_list: List[Dataset], model_list: List[Model], payload = {} try: url = urljoin(cls.backend_url, f"sdk/benchmarks") - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} payload = { "name": name, "datasets": [dataset.id for dataset in dataset_list], @@ -228,7 +226,7 @@ def list_normalization_options(cls, metric: Metric, model: Model) -> List[str]: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + 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() diff --git a/aixplain/factories/corpus_factory.py b/aixplain/factories/corpus_factory.py index d14cad10..4dbb981d 100644 --- a/aixplain/factories/corpus_factory.py +++ b/aixplain/factories/corpus_factory.py @@ -49,7 +49,6 @@ class CorpusFactory(AssetFactory): - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -121,7 +120,7 @@ def get(cls, corpus_id: Text) -> Corpus: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + 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() @@ -167,7 +166,7 @@ def list( if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + 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." payload = {"pageSize": page_size, "pageNumber": page_number, "sort": [{"field": "createdAt", "dir": -1}]} diff --git a/aixplain/factories/data_factory.py b/aixplain/factories/data_factory.py index cb5899fe..3f512aaf 100644 --- a/aixplain/factories/data_factory.py +++ b/aixplain/factories/data_factory.py @@ -43,11 +43,9 @@ class DataFactory(AssetFactory): """A static class for creating and exploring Dataset Objects. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -97,7 +95,7 @@ def get(cls, data_id: Text) -> Data: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Data - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() diff --git a/aixplain/factories/dataset_factory.py b/aixplain/factories/dataset_factory.py index 037910d3..04d04f47 100644 --- a/aixplain/factories/dataset_factory.py +++ b/aixplain/factories/dataset_factory.py @@ -56,11 +56,9 @@ class DatasetFactory(AssetFactory): """A static class for creating and exploring Dataset Objects. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -170,7 +168,7 @@ def get(cls, dataset_id: Text) -> Dataset: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Dataset - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() @@ -211,7 +209,7 @@ def list( if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} assert 0 < page_size <= 100, f"Dataset List Error: Page size must be greater than 0 and not exceed 100." payload = { diff --git a/aixplain/factories/finetune_factory/__init__.py b/aixplain/factories/finetune_factory/__init__.py index d24431dc..07b7b4c3 100644 --- a/aixplain/factories/finetune_factory/__init__.py +++ b/aixplain/factories/finetune_factory/__init__.py @@ -40,11 +40,9 @@ class FinetuneFactory: """A static class for creating and managing the FineTune experience. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -95,7 +93,7 @@ def create( prompt_template = validate_prompt(prompt_template, dataset_list) try: url = urljoin(cls.backend_url, f"sdk/finetune/cost-estimation") - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} payload = { "datasets": [ {"datasetId": dataset.id, "trainPercentage": train_percentage, "devPercentage": dev_percentage} diff --git a/aixplain/factories/metric_factory.py b/aixplain/factories/metric_factory.py index 9cc2ad55..a0372827 100644 --- a/aixplain/factories/metric_factory.py +++ b/aixplain/factories/metric_factory.py @@ -36,11 +36,9 @@ class MetricFactory: """A static class for creating and exploring Metric Objects. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -55,13 +53,13 @@ def _create_metric_from_response(cls, response: Dict) -> Metric: Metric: Coverted 'Metric' object """ return Metric( - id = response["id"], - name = response["name"], - supplier = response["supplier"], - is_reference_required = response["referenceRequired"], - is_source_required = response['sourceRequired'], - cost = response["normalizedPrice"], - function=response["function"] + id=response["id"], + name=response["name"], + supplier=response["supplier"], + is_reference_required=response["referenceRequired"], + is_source_required=response["sourceRequired"], + cost=response["normalizedPrice"], + function=response["function"], ) @classmethod @@ -81,7 +79,7 @@ def get(cls, metric_id: Text) -> Metric: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Metric - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() @@ -98,7 +96,14 @@ def get(cls, metric_id: Text) -> Metric: return metric @classmethod - def list(cls, model_id: Text=None, is_source_required: Optional[bool]=None, is_reference_required: Optional[bool]=None, page_number: int = 0, page_size: int = 20,) -> List[Metric]: + def list( + cls, + model_id: Text = None, + is_source_required: Optional[bool] = None, + is_reference_required: Optional[bool] = None, + page_number: int = 0, + page_size: int = 20, + ) -> List[Metric]: """Get list of supported metrics for the given filters Args: @@ -120,29 +125,27 @@ def list(cls, model_id: Text=None, is_source_required: Optional[bool]=None, is_r filter_params["sourceRequired"] = 1 if is_source_required else 0 if is_reference_required is not None: filter_params["referenceRequired"] = 1 if is_reference_required else 0 - + if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} r = _request_with_retry("get", url, headers=headers, params=filter_params) resp = r.json() logging.info(f"Listing Metrics: Status of getting metrics: {resp}") - all_metrics = resp['results'] + all_metrics = resp["results"] starting_model_index_overall = page_number * page_size ending_model_index_overall = starting_model_index_overall + page_size - 1 - filtered_metrics = all_metrics[starting_model_index_overall: ending_model_index_overall+1] + filtered_metrics = all_metrics[starting_model_index_overall : ending_model_index_overall + 1] total = len(filtered_metrics) metric_list = [cls._create_metric_from_response(metric_info_json) for metric_info_json in filtered_metrics] return { "results": metric_list, "page_total": min(page_size, len(metric_list)), "page_number": page_number, - "total": total + "total": total, } except Exception as e: error_message = f"Listing Metrics: Error in getting metrics: {e}" logging.error(error_message, exc_info=True) return [] - - diff --git a/aixplain/factories/model_factory.py b/aixplain/factories/model_factory.py index c16f0bc9..f9551381 100644 --- a/aixplain/factories/model_factory.py +++ b/aixplain/factories/model_factory.py @@ -35,11 +35,9 @@ class ModelFactory: """A static class for creating and exploring Model Objects. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -54,7 +52,7 @@ def _create_model_from_response(cls, response: Dict) -> Model: Model: Coverted 'Model' object """ if "api_key" not in response: - response["api_key"] = cls.api_key + response["api_key"] = config.TEAM_API_KEY parameters = {} if "params" in response: @@ -90,12 +88,12 @@ def get(cls, model_id: Text, api_key: Optional[Text] = None) -> Model: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Model - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() # set api key - resp["api_key"] = cls.api_key + 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) @@ -169,7 +167,7 @@ def _get_assets_from_page( if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + 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) @@ -249,7 +247,7 @@ def list_host_machines(cls, api_key: Optional[Text] = None) -> List[Dict]: if api_key: headers = {"x-api-key": f"{api_key}", "Content-Type": "application/json"} else: - headers = {"x-api-key": f"{cls.api_key}", "Content-Type": "application/json"} + headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"} response = _request_with_retry("get", machines_url, headers=headers) response_dicts = json.loads(response.text) for dictionary in response_dicts: @@ -274,7 +272,7 @@ def list_functions(cls, verbose: Optional[bool] = False, api_key: Optional[Text] if api_key: headers = {"x-api-key": f"{api_key}", "Content-Type": "application/json"} else: - headers = {"x-api-key": f"{cls.api_key}", "Content-Type": "application/json"} + headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"} response = _request_with_retry("get", functions_url, headers=headers) response_dict = json.loads(response.text) if verbose: @@ -320,7 +318,7 @@ def create_asset_repo( Dict: Backend response """ # Reconcile function name to be function ID in the backend - function_list = cls.list_functions(True, cls.api_key)["items"] + function_list = cls.list_functions(True, config.TEAM_API_KEY)["items"] function_id = None for function_dict in function_list: if function_dict["name"] == function: @@ -332,7 +330,7 @@ def create_asset_repo( if api_key: headers = {"x-api-key": f"{api_key}", "Content-Type": "application/json"} else: - headers = {"x-api-key": f"{cls.api_key}", "Content-Type": "application/json"} + headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"} always_on = False is_async = False # Hard-coded to False for first release payload = { @@ -366,7 +364,7 @@ def asset_repo_login(cls, api_key: Optional[Text] = None) -> Dict: if api_key: headers = {"x-api-key": f"{api_key}", "Content-Type": "application/json"} else: - headers = {"x-api-key": f"{cls.api_key}", "Content-Type": "application/json"} + headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"} response = _request_with_retry("post", login_url, headers=headers) response_dict = json.loads(response.text) return response_dict @@ -387,7 +385,7 @@ def onboard_model(cls, model_id: Text, image_tag: Text, image_hash: Text, api_ke if api_key: headers = {"x-api-key": f"{api_key}", "Content-Type": "application/json"} else: - headers = {"x-api-key": f"{cls.api_key}", "Content-Type": "application/json"} + headers = {"x-api-key": f"{config.TEAM_API_KEY}", "Content-Type": "application/json"} payload = {"image": image_tag, "sha": image_hash} payload = json.dumps(payload) logging.debug(f"Body: {str(payload)}") diff --git a/aixplain/factories/pipeline_factory.py b/aixplain/factories/pipeline_factory.py index f7b03666..078bcae6 100644 --- a/aixplain/factories/pipeline_factory.py +++ b/aixplain/factories/pipeline_factory.py @@ -38,11 +38,9 @@ class PipelineFactory: """A static class for creating and exploring Pipeline Objects. Attributes: - api_key (str): The TEAM API key used for authentication. backend_url (str): The URL for the backend. """ - api_key = config.TEAM_API_KEY aixplain_key = config.AIXPLAIN_API_KEY backend_url = config.BACKEND_URL @@ -57,7 +55,7 @@ def __from_response(cls, response: Dict) -> Pipeline: Pipeline: Coverted 'Pipeline' object """ if "api_key" not in response: - response["api_key"] = cls.api_key + response["api_key"] = config.TEAM_API_KEY return Pipeline(response["id"], response["name"], response["api_key"]) @classmethod @@ -77,12 +75,12 @@ def get(cls, pipeline_id: Text, api_key: Optional[Text] = None) -> Pipeline: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} logging.info(f"Start service for GET Pipeline - {url} - {headers}") r = _request_with_retry("get", url, headers=headers) resp = r.json() # set api key - resp["api_key"] = cls.api_key + resp["api_key"] = config.TEAM_API_KEY if api_key is not None: resp["api_key"] = api_key pipeline = cls.__from_response(resp) @@ -121,7 +119,7 @@ def get_assets_from_page(cls, page_number: int) -> List[Pipeline]: if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} r = _request_with_retry("get", url, headers=headers) resp = r.json() logging.info(f"Listing Pipelines: Status of getting Pipelines on Page {page_number}: {resp}") @@ -171,7 +169,7 @@ def list( if cls.aixplain_key != "": headers = {"x-aixplain-key": f"{cls.aixplain_key}", "Content-Type": "application/json"} else: - headers = {"Authorization": f"Token {cls.api_key}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} assert 0 < page_size <= 100, f"Pipeline List Error: Page size must be greater than 0 and not exceed 100." payload = {