From 6c4ea1507cf10aa2629db0873e11c1bff4fbdd40 Mon Sep 17 00:00:00 2001 From: xainaz Date: Wed, 21 Aug 2024 16:22:05 +0300 Subject: [PATCH 1/3] Removed extra wallet_factoy.py --- aixplain/factories/wallet_factoy.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 aixplain/factories/wallet_factoy.py diff --git a/aixplain/factories/wallet_factoy.py b/aixplain/factories/wallet_factoy.py deleted file mode 100644 index 59ec7c14..00000000 --- a/aixplain/factories/wallet_factoy.py +++ /dev/null @@ -1,26 +0,0 @@ -import aixplain.utils.config as config -from aixplain.modules.wallet import Wallet -from aixplain.utils.file_utils import _request_with_retry -import logging - - -class WalletFactory: - aixplain_key = config.AIXPLAIN_API_KEY - backend_url = config.BACKEND_URL - - @classmethod - def get(cls) -> Wallet: - """Get wallet information""" - try: - resp = None - # Check for code 200, other code will be caught when trying to return a Wallet object - url = f"{cls.backend_url}/sdk/billing/wallet" - - headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} - logging.info(f"Start fetching billing information from - {url} - {headers}") - headers = {"Content-Type": "application/json", "x-api-key": config.TEAM_API_KEY} - r = _request_with_retry("get", url, headers=headers) - resp = r.json() - return Wallet(total_balance=resp["totalBalance"], reserved_balance=resp["reservedBalance"]) - except Exception as e: - raise Exception(f"Failed to get the wallet credit information. Error: {str(e)}") From f657f7a88f27e2edd4314ebe9920640118c0b149 Mon Sep 17 00:00:00 2001 From: xainaz Date: Fri, 23 Aug 2024 14:57:44 +0300 Subject: [PATCH 2/3] Wallet API issue --- aixplain/factories/wallet_factory.py | 8 +++----- tests/unit/wallet_test.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/aixplain/factories/wallet_factory.py b/aixplain/factories/wallet_factory.py index 59ec7c14..55c9a2a9 100644 --- a/aixplain/factories/wallet_factory.py +++ b/aixplain/factories/wallet_factory.py @@ -9,16 +9,14 @@ class WalletFactory: backend_url = config.BACKEND_URL @classmethod - def get(cls) -> Wallet: + def get(cls, api_key) -> Wallet: """Get wallet information""" try: resp = None - # Check for code 200, other code will be caught when trying to return a Wallet object url = f"{cls.backend_url}/sdk/billing/wallet" - - headers = {"Authorization": f"Token {config.TEAM_API_KEY}", "Content-Type": "application/json"} + headers = {"Authorization": f"Token {api_key}", "Content-Type": "application/json"} logging.info(f"Start fetching billing information from - {url} - {headers}") - headers = {"Content-Type": "application/json", "x-api-key": config.TEAM_API_KEY} + headers = {"Content-Type": "application/json", "x-api-key": api_key} r = _request_with_retry("get", url, headers=headers) resp = r.json() return Wallet(total_balance=resp["totalBalance"], reserved_balance=resp["reservedBalance"]) diff --git a/tests/unit/wallet_test.py b/tests/unit/wallet_test.py index 48ee19ab..16561dba 100644 --- a/tests/unit/wallet_test.py +++ b/tests/unit/wallet_test.py @@ -11,6 +11,6 @@ def test_wallet_service(): headers = {"x-api-key": config.TEAM_API_KEY, "Content-Type": "application/json"} ref_response = {"totalBalance": 5, "reservedBalance": "0"} mock.get(url, headers=headers, json=ref_response) - wallet = WalletFactory.get() + wallet = WalletFactory.get(config.AIXPLAIN_API_KEY) assert wallet.total_balance == ref_response["totalBalance"] assert wallet.reserved_balance == ref_response["reservedBalance"] From 96907b03084409e3397e4b8443a573912acd883b Mon Sep 17 00:00:00 2001 From: xainaz Date: Fri, 23 Aug 2024 17:22:46 +0300 Subject: [PATCH 3/3] Added changed --- aixplain/factories/wallet_factory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aixplain/factories/wallet_factory.py b/aixplain/factories/wallet_factory.py index 55c9a2a9..b0a55b65 100644 --- a/aixplain/factories/wallet_factory.py +++ b/aixplain/factories/wallet_factory.py @@ -2,6 +2,7 @@ from aixplain.modules.wallet import Wallet from aixplain.utils.file_utils import _request_with_retry import logging +from typing import Text class WalletFactory: @@ -9,7 +10,7 @@ class WalletFactory: backend_url = config.BACKEND_URL @classmethod - def get(cls, api_key) -> Wallet: + def get(cls, api_key: Text = config.TEAM_API_KEY) -> Wallet: """Get wallet information""" try: resp = None