Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
23b2898
Update Finetuner search metadata functional tests (#172)
lucas-aixplain May 2, 2024
208a081
Downgrade dataclasses-json for compatibility (#170)
thiago-aixplain May 2, 2024
a837e1a
Fix model cost parameters (#179)
thiago-aixplain May 10, 2024
754f478
Treat label URLs (#176)
thiago-aixplain May 15, 2024
f1c9935
Add new metric test (#181)
thiago-aixplain Jun 4, 2024
a48ccfd
LLMModel class and parameters (#184)
thiago-aixplain Jun 5, 2024
c7f59ce
Gpus (#185)
mikelam-us-aixplain Jun 5, 2024
16eb2e1
Create and get Pipelines with api key as input parameter (#187)
thiago-aixplain Jun 7, 2024
2849d6f
Merge branch 'test' into development
thiago-aixplain Jun 11, 2024
04246b1
M 6769474660 save pipelines (#191)
thiago-aixplain Jun 17, 2024
73021a7
M 6769474660 save pipelines (#192)
thiago-aixplain Jun 18, 2024
474602b
Solving bug when LLM parameters are set on data (#196)
thiago-aixplain Jun 26, 2024
c471703
Merge branch 'test' into development
thiago-aixplain Jun 26, 2024
3695686
Fix pipeline functional test (#200)
lucas-aixplain Jul 3, 2024
9014061
M 6656407247 agentification (#197)
thiago-aixplain Jul 13, 2024
e9091c2
Fixing circular import in the SDK (#211)
thiago-aixplain Jul 30, 2024
f437815
create model/pipeline tools from AgentFactory (#214)
thiago-aixplain Aug 2, 2024
8457087
Merge branch 'test' into development
thiago-aixplain Aug 6, 2024
03009c6
Set model ID as a parameter (#216)
thiago-aixplain Aug 7, 2024
02f7482
Content inputs to be processed according to the query. (#215)
thiago-aixplain Aug 7, 2024
4947959
ENG-1: programmatic api introduced (#219)
kadirpekel Aug 9, 2024
ef16dd5
Updated image upload tests (#213)
mikelam-us-aixplain Aug 12, 2024
d0ad51d
Eng 217 local path (#220)
thiago-aixplain Aug 13, 2024
dca1a37
Eng 389 fix tests (#222)
thiago-aixplain Aug 13, 2024
d43f67f
Merge branch 'test' into development
thiago-aixplain Aug 13, 2024
b113368
Tool Validation when creating agents (#226)
xainaz Aug 19, 2024
0032947
Eng 398 sdk get users credits - Initial (#232)
xainaz Aug 20, 2024
a567535
Eng 398 sdk get users credits (#234)
thiago-aixplain Aug 20, 2024
e919fab
Removed wallet_factoy.py (#235)
xainaz Aug 21, 2024
9ffe3f7
Merge branch 'test' into development
thiago-aixplain Aug 22, 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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ dmypy.json

# Vscode
.vscode
.DS_Store

1 change: 1 addition & 0 deletions aixplain/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
from .model_factory import ModelFactory
from .pipeline_factory import PipelineFactory
from .finetune_factory import FinetuneFactory
from .wallet_factory import WalletFactory
2 changes: 2 additions & 0 deletions aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def create(
tool_payload = []
for tool in tools:
if isinstance(tool, ModelTool):
tool.validate()
tool_payload.append(
{
"function": tool.function.value if tool.function is not None else None,
Expand All @@ -76,6 +77,7 @@ def create(
}
)
elif isinstance(tool, PipelineTool):
tool.validate()
tool_payload.append(
{
"assetId": tool.pipeline,
Expand Down
26 changes: 26 additions & 0 deletions aixplain/factories/wallet_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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)}")
16 changes: 13 additions & 3 deletions aixplain/modules/agent/tool/model_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,23 @@ def __init__(

if model is not None:
if isinstance(model, Text) is True:
from aixplain.factories.model_factory import ModelFactory

model = ModelFactory.get(model)
self.model = model
model = self.validate()
function = model.function
if isinstance(model.supplier, Supplier):
supplier = model.supplier
model = model.id
self.supplier = supplier
self.model = model
self.function = function

def validate(self) -> Model:
from aixplain.factories.model_factory import ModelFactory

try:
model = None
if self.model is not None:
model = ModelFactory.get(self.model)
return model
except Exception:
raise Exception(f"Model Tool Unavailable. Make sure Model '{self.model}' exists or you have access to it.")
8 changes: 8 additions & 0 deletions aixplain/modules/agent/tool/pipeline_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ def __init__(
if isinstance(pipeline, Pipeline):
pipeline = pipeline.id
self.pipeline = pipeline

def validate(self):
from aixplain.factories.pipeline_factory import PipelineFactory

try:
PipelineFactory.get(self.pipeline)
except Exception:
raise Exception(f"Pipeline Tool Unavailable. Make sure Pipeline '{self.pipeline}' exists or you have access to it.")
34 changes: 34 additions & 0 deletions aixplain/modules/wallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
__author__ = "aixplain"

"""
Copyright 2024 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: August 20th 2024
Description:
Wallet Class
"""


class Wallet:
def __init__(self, total_balance: float, reserved_balance: float):
"""Create a Wallet with the necessary information

Args:
total_balance (float): total credit balance
reserved_balance (float): reserved credit balance
"""
self.total_balance = total_balance
self.reserved_balance = reserved_balance
16 changes: 16 additions & 0 deletions tests/unit/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import requests_mock
from aixplain.modules import Agent
from aixplain.utils import config
from aixplain.factories import AgentFactory
from aixplain.modules.agent import PipelineTool, ModelTool


def test_fail_no_data_query():
Expand Down Expand Up @@ -61,3 +63,17 @@ def test_sucess_query_content():
response = agent.run_async(data={"query": "Translate the text: {{input1}}"}, content={"input1": "Hello, how are you?"})
assert response["status"] == ref_response["status"]
assert response["url"] == ref_response["data"]


def test_invalid_pipelinetool():
with pytest.raises(Exception) as exc_info:
AgentFactory.create(
name="Test", tools=[PipelineTool(pipeline="309851793", description="Test")], llm_id="6646261c6eb563165658bbb1"
)
assert str(exc_info.value) == "Pipeline Tool Unavailable. Make sure Pipeline '309851793' exists or you have access to it."


def test_invalid_modeltool():
with pytest.raises(Exception) as exc_info:
AgentFactory.create(name="Test", tools=[ModelTool(model="309851793")], llm_id="6646261c6eb563165658bbb1")
assert str(exc_info.value) == "Model Tool Unavailable. Make sure Model '309851793' exists or you have access to it."
16 changes: 16 additions & 0 deletions tests/unit/wallet_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__author__ = "aixplain"

from aixplain.factories import WalletFactory
import aixplain.utils.config as config
import requests_mock


def test_wallet_service():
with requests_mock.Mocker() as mock:
url = f"{config.BACKEND_URL}/sdk/billing/wallet"
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()
assert wallet.total_balance == ref_response["totalBalance"]
assert wallet.reserved_balance == ref_response["reservedBalance"]