Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 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
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
1 change: 1 addition & 0 deletions aixplain/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""
from .asset_factory import AssetFactory
from .agent_factory import AgentFactory
from .team_agent_factory import TeamAgentFactory
from .benchmark_factory import BenchmarkFactory
from .corpus_factory import CorpusFactory
from .data_factory import DataFactory
Expand Down
27 changes: 10 additions & 17 deletions aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from aixplain.utils import config
from typing import Dict, List, Optional, Text, Union

from aixplain.factories.agent_factory.utils import build_agent, validate_llm
from aixplain.factories.agent_factory.utils import build_agent, validate_llm, validate_name
from aixplain.utils.file_utils import _request_with_retry
from urllib.parse import urljoin

Expand All @@ -44,36 +44,31 @@ class AgentFactory:
def create(
cls,
name: Text,
llm_id: Text,
description: Text,
llm_id: Text = "669a63646eb56306647e1091",
tools: List[Tool] = [],
description: Text = "",
api_key: Text = config.TEAM_API_KEY,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
use_mentalist_and_inspector: bool = False,
) -> Agent:
"""Create a new agent in the platform.

Args:
name (Text): name of the agent
llm_id (Text): aiXplain ID of the large language model to be used as agent.
description (Text): description of the agent role.
llm_id (Text, optional): aiXplain ID of the large language model to be used as agent. Defaults to "669a63646eb56306647e1091" (GPT-4o mini).
tools (List[Tool], optional): list of tool for the agent. Defaults to [].
description (Text, optional): description of the agent role. Defaults to "".
api_key (Text, optional): team/user API key. Defaults to config.TEAM_API_KEY.
supplier (Union[Dict, Text, Supplier, int], optional): owner of the agent. Defaults to "aiXplain".
version (Optional[Text], optional): version of the agent. Defaults to None.
use_mentalist_and_inspector (bool, optional): flag to enable mentalist and inspector agents (which only works when a supervisor is enabled). Defaults to False.

Returns:
Agent: created Agent
"""
validate_name(name)
# validate LLM ID
validate_llm(llm_id)

orchestrator_llm_id, mentalist_and_inspector_llm_id = llm_id, None
if use_mentalist_and_inspector is True:
mentalist_and_inspector_llm_id = llm_id

try:
agent = None
url = urljoin(config.BACKEND_URL, "sdk/agents")
Expand Down Expand Up @@ -117,8 +112,6 @@ def create(
"supplier": supplier,
"version": version,
"llmId": llm_id,
"supervisorId": orchestrator_llm_id,
"plannerId": mentalist_and_inspector_llm_id,
}

logging.info(f"Start service for POST Create Agent - {url} - {headers} - {json.dumps(payload)}")
Expand All @@ -128,13 +121,13 @@ def create(
agent = build_agent(payload=response, api_key=api_key)
else:
error = r.json()
error_msg = "Agent Onboarding Error: Please contant the administrators."
error_msg = "Agent Onboarding Error: Please contact the administrators."
if "message" in error:
msg = error["message"]
if error["message"] == "err.name_already_exists":
msg = "Agent name already exists."
elif error["message"] == "err.asset_is_not_available":
msg = "Some the tools are not available."
msg = "Some tools are not available."
error_msg = f"Agent Onboarding Error (HTTP {r.status_code}): {msg}"
logging.exception(error_msg)
raise Exception(error_msg)
Expand Down Expand Up @@ -190,7 +183,7 @@ def list(cls) -> Dict:
agents.append(build_agent(agent))
return {"results": agents, "page_total": page_total, "page_number": 0, "total": total}
else:
error_msg = "Agent Listing Error: Please contant the administrators."
error_msg = "Agent Listing Error: Please contact the administrators."
if "message" in resp:
msg = resp["message"]
error_msg = f"Agent Listing Error (HTTP {r.status_code}): {msg}"
Expand All @@ -214,7 +207,7 @@ def get(cls, agent_id: Text, api_key: Optional[Text] = None) -> Agent:
if 200 <= r.status_code < 300:
return build_agent(resp)
else:
msg = "Please contant the administrators."
msg = "Please contact the administrators."
if "message" in resp:
msg = resp["message"]
error_msg = f"Agent Get Error (HTTP {r.status_code}): {msg}"
Expand Down
12 changes: 11 additions & 1 deletion aixplain/factories/agent_factory/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from typing import Dict, Text
from urllib.parse import urljoin

GPT_4o_ID = "6646261c6eb563165658bbb1"


def build_agent(payload: Dict, api_key: Text = config.TEAM_API_KEY) -> Agent:
"""Instantiate a new agent in the platform."""
Expand Down Expand Up @@ -41,7 +43,7 @@ def build_agent(payload: Dict, api_key: Text = config.TEAM_API_KEY) -> Agent:
supplier=payload["teamId"] if "teamId" in payload else None,
version=payload["version"] if "version" in payload else None,
cost=payload["cost"] if "cost" in payload else None,
llm_id=payload["llmId"] if "llmId" in payload else "6646261c6eb563165658bbb1",
llm_id=payload["llmId"] if "llmId" in payload else GPT_4o_ID,
api_key=api_key,
status=AssetStatus(payload["status"]),
)
Expand All @@ -57,3 +59,11 @@ def validate_llm(model_id: Text) -> None:
assert llm.function == Function.TEXT_GENERATION, "Large Language Model must be a text generation model."
except Exception:
raise Exception(f"Large Language Model with ID '{model_id}' not found.")


def validate_name(name: Text) -> None:
import re

assert (
re.match("^[a-zA-Z0-9 ]*$", name) is not None
), "Agent Creation Error: Agent name must not contain special characters."
2 changes: 1 addition & 1 deletion aixplain/factories/pipeline_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def create(
pipeline = json.load(f)

for i, node in enumerate(pipeline["nodes"]):
if "functionType" in node and node["functionType"] == "AI":
if "functionType" in node:
pipeline["nodes"][i]["functionType"] = pipeline["nodes"][i]["functionType"].lower()
# prepare payload
payload = {
Expand Down
11 changes: 7 additions & 4 deletions aixplain/factories/pipeline_factory/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from aixplain.modules.pipeline.designer import (
Input,
Output,
AssetNode,
BareAsset,
BareMetric,
Decision,
Router,
Route,
Expand Down Expand Up @@ -36,14 +37,16 @@ def build_from_response(response: Dict, load_architecture: bool = False) -> Pipe
try:
# instantiating nodes
for node_json in response["nodes"]:
print(node_json)
if node_json["type"].lower() == "input":
node = Input(
data=node_json["data"] if "data" in node_json else None,
data_types=[DataType(dt) for dt in node_json["dataType"]],
)
elif node_json["type"].lower() == "asset":
node = AssetNode(asset_id=node_json["assetId"])
if node_json["functionType"] == "metric":
node = BareMetric(asset_id=node_json["assetId"])
else:
node = BareAsset(asset_id=node_json["assetId"])
elif node_json["type"].lower() == "segmentor":
raise NotImplementedError()
elif node_json["type"].lower() == "reconstructor":
Expand All @@ -53,7 +56,7 @@ def build_from_response(response: Dict, load_architecture: bool = False) -> Pipe
elif node_json["type"].lower() == "router":
node = Router(routes=[Route(**route) for route in node_json["routes"]])
elif node_json["type"].lower() == "script":
node = Script(fileId=node_json["fileId"])
node = Script(fileId=node_json["fileId"], fileMetadata=node_json["fileMetadata"])
elif node_json["type"].lower() == "output":
node = Output()

Expand Down
9 changes: 3 additions & 6 deletions aixplain/factories/script_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@


class ScriptFactory:

@classmethod
def upload_script(cls, script_path: str) -> Tuple[str, str]:
try:
url = f"{config.BACKEND_URL}/sdk/pipelines/script"
headers = {"Authorization": f"Token {config.TEAM_API_KEY}"}
r = requests.post(
url, headers=headers, files={"file": open(script_path, "rb")}
)
r = requests.post(url, headers=headers, files={"file": open(script_path, "rb")})
if 200 <= r.status_code < 300:
response = r.json()
else:
Expand All @@ -26,6 +23,6 @@ def upload_script(cls, script_path: str) -> Tuple[str, str]:

# get metadata info
fname = os.path.splitext(os.path.basename(script_path))[0]
file_size_kb = int(os.path.getsize(script_path) / 1024)
metadata = json.dumps({"name": fname, "size": file_size_kb})
file_size = int(os.path.getsize(script_path))
metadata = json.dumps({"name": fname, "size": file_size})
return response["fileId"], metadata
166 changes: 166 additions & 0 deletions aixplain/factories/team_agent_factory/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
__author__ = "lucaspavanelli"

"""
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: Thiago Castro Ferreira and Lucas Pavanelli
Date: August 15th 2024
Description:
TeamAgent Factory Class
"""

import json
import logging

from aixplain.enums.supplier import Supplier
from aixplain.factories.agent_factory import AgentFactory
from aixplain.factories.agent_factory.utils import validate_llm, validate_name
from aixplain.modules.agent import Agent
from aixplain.modules.team_agent import TeamAgent
from aixplain.utils import config
from aixplain.factories.team_agent_factory.utils import build_team_agent
from aixplain.utils.file_utils import _request_with_retry
from typing import Dict, List, Optional, Text, Union
from urllib.parse import urljoin


class TeamAgentFactory:
@classmethod
def create(
cls,
name: Text,
agents: List[Union[Text, Agent]],
llm_id: Text = "669a63646eb56306647e1091",
description: Text = "",
api_key: Text = config.TEAM_API_KEY,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
use_mentalist_and_inspector: bool = True,
) -> TeamAgent:
"""Create a new team agent in the platform."""
validate_name(name)
# validate LLM ID
validate_llm(llm_id)
assert len(agents) > 0, "TeamAgent Onboarding Error: At least one agent must be provided."
for agent in agents:
if isinstance(agent, Text) is True:
try:
agent = AgentFactory.get(agent)
except Exception:
raise Exception(f"TeamAgent Onboarding Error: Agent {agent} does not exist.")
else:
assert isinstance(agent, Agent), "TeamAgent Onboarding Error: Agents must be instances of Agent class"

mentalist_and_inspector_llm_id = None
if use_mentalist_and_inspector is True:
mentalist_and_inspector_llm_id = llm_id
try:
team_agent = None
url = urljoin(config.BACKEND_URL, "sdk/agent-communities")
headers = {"x-api-key": api_key}

if isinstance(supplier, dict):
supplier = supplier["code"]
elif isinstance(supplier, Supplier):
supplier = supplier.value["code"]

agent_list = []
for idx, agent in enumerate(agents):
agent_list.append({"assetId": agent.id, "number": idx, "type": "AGENT", "label": "AGENT"})

payload = {
"name": name,
"agents": agent_list,
"links": [],
"description": description,
"llmId": llm_id,
"supervisorId": llm_id,
"plannerId": mentalist_and_inspector_llm_id,
"supplier": supplier,
"version": version,
}

logging.info(f"Start service for POST Create TeamAgent - {url} - {headers} - {json.dumps(payload)}")
r = _request_with_retry("post", url, headers=headers, json=payload)
if 200 <= r.status_code < 300:
response = r.json()
team_agent = build_team_agent(payload=response, api_key=api_key)
else:
error = r.json()
error_msg = "TeamAgent Onboarding Error: Please contact the administrators."
if "message" in error:
msg = error["message"]
if error["message"] == "err.name_already_exists":
msg = "TeamAgent name already exists."
elif error["message"] == "err.asset_is_not_available":
msg = "Some tools are not available."
error_msg = f"TeamAgent Onboarding Error (HTTP {r.status_code}): {msg}"
logging.exception(error_msg)
raise Exception(error_msg)
except Exception as e:
raise Exception(e)
return team_agent

@classmethod
def list(cls) -> Dict:
"""List all agents available in the platform."""
url = urljoin(config.BACKEND_URL, "sdk/agent-communities")
headers = {"x-api-key": config.TEAM_API_KEY, "Content-Type": "application/json"}

payload = {}
logging.info(f"Start service for GET List Agents - {url} - {headers} - {json.dumps(payload)}")
try:
r = _request_with_retry("get", url, headers=headers)
resp = r.json()

if 200 <= r.status_code < 300:
agents, page_total, total = [], 0, 0
results = resp
page_total = len(results)
total = len(results)
logging.info(f"Response for GET List Agents - Page Total: {page_total} / Total: {total}")
for agent in results:
agents.append(build_team_agent(agent))
return {"results": agents, "page_total": page_total, "page_number": 0, "total": total}
else:
error_msg = "Agent Listing Error: Please contact the administrators."
if "message" in resp:
msg = resp["message"]
error_msg = f"Agent Listing Error (HTTP {r.status_code}): {msg}"
logging.exception(error_msg)
raise Exception(error_msg)
except Exception as e:
raise Exception(e)

@classmethod
def get(cls, agent_id: Text, api_key: Optional[Text] = None) -> Agent:
"""Get agent by id."""
url = urljoin(config.BACKEND_URL, f"sdk/agent-communities/{agent_id}")
if config.AIXPLAIN_API_KEY != "":
headers = {"x-aixplain-key": f"{config.AIXPLAIN_API_KEY}", "Content-Type": "application/json"}
else:
api_key = api_key if api_key is not None else config.TEAM_API_KEY
headers = {"x-api-key": api_key, "Content-Type": "application/json"}
logging.info(f"Start service for GET Agent - {url} - {headers}")
r = _request_with_retry("get", url, headers=headers)
resp = r.json()
if 200 <= r.status_code < 300:
return build_team_agent(resp)
else:
msg = "Please contact the administrators."
if "message" in resp:
msg = resp["message"]
error_msg = f"Agent Get Error (HTTP {r.status_code}): {msg}"
raise Exception(error_msg)
Loading