Skip to content

Commit

Permalink
Version 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Zielman committed Apr 11, 2024
1 parent 514387c commit 9f18560
Show file tree
Hide file tree
Showing 267 changed files with 4,162 additions and 904 deletions.
2 changes: 1 addition & 1 deletion abacusai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .streaming_client import StreamingClient


__version__ = "1.2.1"
__version__ = "1.2.2"
25 changes: 20 additions & 5 deletions abacusai/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .agent_version import AgentVersion
from .api_class import WorkflowGraph
from .code_source import CodeSource
from .return_class import AbstractApiClass

Expand All @@ -24,7 +25,7 @@ class Agent(AbstractApiClass):
codeSource (CodeSource): If a python model, information on the source code
"""

def __init__(self, client, name=None, agentId=None, createdAt=None, projectId=None, notebookId=None, predictFunctionName=None, sourceCode=None, agentConfig=None, memory=None, trainingRequired=None, agentExecutionConfig=None, codeSource={}, latestAgentVersion={}):
def __init__(self, client, name=None, agentId=None, createdAt=None, projectId=None, notebookId=None, predictFunctionName=None, sourceCode=None, agentConfig=None, memory=None, trainingRequired=None, agentExecutionConfig=None, codeSource={}, latestAgentVersion={}, workflowGraph={}):
super().__init__(client, agentId)
self.name = name
self.agent_id = agentId
Expand All @@ -40,11 +41,12 @@ def __init__(self, client, name=None, agentId=None, createdAt=None, projectId=No
self.code_source = client._build_class(CodeSource, codeSource)
self.latest_agent_version = client._build_class(
AgentVersion, latestAgentVersion)
self.workflow_graph = client._build_class(WorkflowGraph, workflowGraph)
self.deprecated_keys = {}

def __repr__(self):
repr_dict = {f'name': repr(self.name), f'agent_id': repr(self.agent_id), f'created_at': repr(self.created_at), f'project_id': repr(self.project_id), f'notebook_id': repr(self.notebook_id), f'predict_function_name': repr(self.predict_function_name), f'source_code': repr(
self.source_code), f'agent_config': repr(self.agent_config), f'memory': repr(self.memory), f'training_required': repr(self.training_required), f'agent_execution_config': repr(self.agent_execution_config), f'code_source': repr(self.code_source), f'latest_agent_version': repr(self.latest_agent_version)}
repr_dict = {f'name': repr(self.name), f'agent_id': repr(self.agent_id), f'created_at': repr(self.created_at), f'project_id': repr(self.project_id), f'notebook_id': repr(self.notebook_id), f'predict_function_name': repr(self.predict_function_name), f'source_code': repr(self.source_code), f'agent_config': repr(
self.agent_config), f'memory': repr(self.memory), f'training_required': repr(self.training_required), f'agent_execution_config': repr(self.agent_execution_config), f'code_source': repr(self.code_source), f'latest_agent_version': repr(self.latest_agent_version), f'workflow_graph': repr(self.workflow_graph)}
class_name = "Agent"
repr_str = ',\n '.join([f'{key}={value}' for key, value in repr_dict.items(
) if getattr(self, key, None) is not None and key not in self.deprecated_keys])
Expand All @@ -57,8 +59,8 @@ def to_dict(self):
Returns:
dict: The dict value representation of the class parameters
"""
resp = {'name': self.name, 'agent_id': self.agent_id, 'created_at': self.created_at, 'project_id': self.project_id, 'notebook_id': self.notebook_id, 'predict_function_name': self.predict_function_name, 'source_code': self.source_code, 'agent_config': self.agent_config,
'memory': self.memory, 'training_required': self.training_required, 'agent_execution_config': self.agent_execution_config, 'code_source': self._get_attribute_as_dict(self.code_source), 'latest_agent_version': self._get_attribute_as_dict(self.latest_agent_version)}
resp = {'name': self.name, 'agent_id': self.agent_id, 'created_at': self.created_at, 'project_id': self.project_id, 'notebook_id': self.notebook_id, 'predict_function_name': self.predict_function_name, 'source_code': self.source_code, 'agent_config': self.agent_config, 'memory': self.memory,
'training_required': self.training_required, 'agent_execution_config': self.agent_execution_config, 'code_source': self._get_attribute_as_dict(self.code_source), 'latest_agent_version': self._get_attribute_as_dict(self.latest_agent_version), 'workflow_graph': self._get_attribute_as_dict(self.workflow_graph)}
return {key: value for key, value in resp.items() if value is not None and key not in self.deprecated_keys}

def refresh(self):
Expand All @@ -83,6 +85,19 @@ def describe(self):
"""
return self.client.describe_agent(self.agent_id)

def list_versions(self, limit: int = 100, start_after_version: str = None):
"""
List all versions of an agent.
Args:
limit (int): If provided, limits the number of agent versions returned.
start_after_version (str): Unique string identifier of the version after which the list starts.
Returns:
list[AgentVersion]: An array of Agent versions.
"""
return self.client.list_agent_versions(self.agent_id, limit, start_after_version)

def wait_for_publish(self, timeout=None):
"""
A waiting call until agent is published.
Expand Down
12 changes: 7 additions & 5 deletions abacusai/agent_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .api_class import WorkflowGraph
from .code_source import CodeSource
from .return_class import AbstractApiClass

Expand All @@ -21,7 +22,7 @@ class AgentVersion(AbstractApiClass):
codeSource (CodeSource): If a python model, information on where the source code is located.
"""

def __init__(self, client, agentVersion=None, status=None, agentId=None, agentConfig=None, publishingStartedAt=None, publishingCompletedAt=None, pendingDeploymentIds=None, failedDeploymentIds=None, error=None, agentExecutionConfig=None, codeSource={}):
def __init__(self, client, agentVersion=None, status=None, agentId=None, agentConfig=None, publishingStartedAt=None, publishingCompletedAt=None, pendingDeploymentIds=None, failedDeploymentIds=None, error=None, agentExecutionConfig=None, codeSource={}, workflowGraph={}):
super().__init__(client, agentVersion)
self.agent_version = agentVersion
self.status = status
Expand All @@ -34,11 +35,12 @@ def __init__(self, client, agentVersion=None, status=None, agentId=None, agentCo
self.error = error
self.agent_execution_config = agentExecutionConfig
self.code_source = client._build_class(CodeSource, codeSource)
self.workflow_graph = client._build_class(WorkflowGraph, workflowGraph)
self.deprecated_keys = {}

def __repr__(self):
repr_dict = {f'agent_version': repr(self.agent_version), f'status': repr(self.status), f'agent_id': repr(self.agent_id), f'agent_config': repr(self.agent_config), f'publishing_started_at': repr(self.publishing_started_at), f'publishing_completed_at': repr(
self.publishing_completed_at), f'pending_deployment_ids': repr(self.pending_deployment_ids), f'failed_deployment_ids': repr(self.failed_deployment_ids), f'error': repr(self.error), f'agent_execution_config': repr(self.agent_execution_config), f'code_source': repr(self.code_source)}
repr_dict = {f'agent_version': repr(self.agent_version), f'status': repr(self.status), f'agent_id': repr(self.agent_id), f'agent_config': repr(self.agent_config), f'publishing_started_at': repr(self.publishing_started_at), f'publishing_completed_at': repr(self.publishing_completed_at), f'pending_deployment_ids': repr(
self.pending_deployment_ids), f'failed_deployment_ids': repr(self.failed_deployment_ids), f'error': repr(self.error), f'agent_execution_config': repr(self.agent_execution_config), f'code_source': repr(self.code_source), f'workflow_graph': repr(self.workflow_graph)}
class_name = "AgentVersion"
repr_str = ',\n '.join([f'{key}={value}' for key, value in repr_dict.items(
) if getattr(self, key, None) is not None and key not in self.deprecated_keys])
Expand All @@ -51,8 +53,8 @@ def to_dict(self):
Returns:
dict: The dict value representation of the class parameters
"""
resp = {'agent_version': self.agent_version, 'status': self.status, 'agent_id': self.agent_id, 'agent_config': self.agent_config, 'publishing_started_at': self.publishing_started_at, 'publishing_completed_at': self.publishing_completed_at,
'pending_deployment_ids': self.pending_deployment_ids, 'failed_deployment_ids': self.failed_deployment_ids, 'error': self.error, 'agent_execution_config': self.agent_execution_config, 'code_source': self._get_attribute_as_dict(self.code_source)}
resp = {'agent_version': self.agent_version, 'status': self.status, 'agent_id': self.agent_id, 'agent_config': self.agent_config, 'publishing_started_at': self.publishing_started_at, 'publishing_completed_at': self.publishing_completed_at, 'pending_deployment_ids': self.pending_deployment_ids,
'failed_deployment_ids': self.failed_deployment_ids, 'error': self.error, 'agent_execution_config': self.agent_execution_config, 'code_source': self._get_attribute_as_dict(self.code_source), 'workflow_graph': self._get_attribute_as_dict(self.workflow_graph)}
return {key: value for key, value in resp.items() if value is not None and key not in self.deprecated_keys}

def refresh(self):
Expand Down
151 changes: 150 additions & 1 deletion abacusai/api_class/ai_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from typing import Union
from typing import List, Union

from . import enums
from .abstract import ApiClass
Expand All @@ -20,3 +20,152 @@ class FieldDescriptor(ApiClass):
description: str = dataclasses.field(default=None)
example_extraction: Union[str, int, bool, float, list, dict] = dataclasses.field(default=None)
type: enums.FieldDescriptorType = dataclasses.field(default=enums.FieldDescriptorType.STRING)


@dataclasses.dataclass
class WorkflowNodeInputMapping(ApiClass):
"""
A mapping of input to a workflow node.
Args:
name (str): The name of the input.
variable_type (str): The type of the input.
workflow_variable_source (str): The workflow source stage of the input.
is_required (bool): Whether the input is required.
"""
name: str
variable_type: enums.WorkflowNodeInputType
workflow_variable_source: str = dataclasses.field(default=None)
is_required: bool = dataclasses.field(default=True)

def to_dict(self):
return {
'name': self.name,
'variable_type': self.variable_type,
'workflow_variable_source': self.workflow_variable_source,
'is_required': self.is_required
}


@dataclasses.dataclass
class WorkflowNodeOutputMapping(ApiClass):
"""
A mapping of output to a workflow node.
Args:
name (str): The name of the output.
variable_type (str): The type of the output.
"""
name: str
variable_type: enums.WorkflowNodeOutputType = dataclasses.field(default=enums.WorkflowNodeOutputType.STRING)

def to_dict(self):
return {
'name': self.name,
'variable_type': self.variable_type
}


@dataclasses.dataclass
class WorkflowGraphNode(ApiClass):
"""
A node in an Agent workflow graph.
Args:
name (str): Display name of the worflow node.
input_mappings (List[WorkflowNodeInputMapping]): List of input mappings for the node.
output_mappings (List[WorkflowNodeOutputMapping]): List of output mappings for the node.
function (callable): The callable node function reference if available.
function_name (str): The name of the function if available.
source_code (str): The source code of the function if available.
input_schema (dict): The react json schema for the input form if applicable.
output_schema (dict): The react json schema for the output if applicable.
package_requirements (list): List of package requirements for the node.
"""

def __init__(self, name: str, input_mappings: List[WorkflowNodeInputMapping], output_mappings: List[WorkflowNodeOutputMapping], function: callable = None, function_name: str = None, source_code: str = None, input_schema: dict = None, output_schema: dict = None, package_requirements: list = None):
if function:
import inspect
self.function_name = function.__name__
self.source_code = inspect.getsource(function)
elif function_name and source_code:
self.function_name = function_name
self.source_code = source_code
else:
raise ValueError('Either function or function_name and source_code must be provided.')

self.name = name
self.input_mappings = input_mappings
self.output_mappings = output_mappings
self.input_schema = input_schema if input_schema else {}
self.output_schema = output_schema if output_schema else {}
self.package_requirements = package_requirements if package_requirements else []

def to_dict(self):
return {
'name': self.name,
'function_name': self.function_name,
'source_code': self.source_code,
'input_mappings': [mapping.to_dict() for mapping in self.input_mappings],
'output_mappings': [mapping.to_dict() for mapping in self.output_mappings],
'input_schema': self.input_schema,
'output_schema': self.output_schema,
'package_requirements': self.package_requirements
}

@classmethod
def from_dict(cls, node: dict):
return cls(
name=node['name'],
function_name=node['function_name'],
source_code=node['source_code'],
input_mappings=[WorkflowNodeInputMapping(**mapping) for mapping in node['input_mappings']],
output_mappings=[WorkflowNodeOutputMapping(**mapping) for mapping in node['output_mappings']],
input_schema=node.get('input_schema', {}),
output_schema=node.get('output_schema', {}),
package_requirements=node.get('package_requirements', [])
)


@dataclasses.dataclass
class WorkflowGraphEdge(ApiClass):
"""
An edge in an Agent workflow graph.
Args:
source (str): The source node of the edge.
target (str): The target node of the edge.
details (dict): Additional details about the edge.
"""
source: str
target: str
details: dict = dataclasses.field(default_factory=dict)

def to_nx_edge(self):
return [self.source, self.target, self.details]


@dataclasses.dataclass
class WorkflowGraph(ApiClass):
"""
An Agent workflow graph.
Args:
nodes (List[WorkflowGraphNode]): A list of nodes in the workflow graph.
edges (List[WorkflowGraphEdge]): A list of edges in the workflow graph, where each edge is a tuple of source, target and details.
"""
nodes: List[WorkflowGraphNode] = dataclasses.field(default_factory=list)
edges: List[WorkflowGraphEdge] = dataclasses.field(default_factory=list)

def to_dict(self):
return {
'nodes': [node.to_dict() for node in self.nodes],
'edges': [edge.to_dict() for edge in self.edges]
}

@classmethod
def from_dict(cls, graph: dict):
return cls(
nodes=[WorkflowGraphNode.from_dict(node) for node in graph.get('nodes', [])],
edges=[WorkflowGraphEdge.from_dict(edge) for edge in graph.get('edges', [])]
)
6 changes: 3 additions & 3 deletions abacusai/api_class/batch_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ForecastingBatchPredictionArgs(BatchPredictionArgs):
forecasting_horizon (int): The number of timestamps to predict in the future. Range: [1, 1000].
item_attributes_to_include_in_the_result (list): List of columns to include in the prediction output.
explain_predictions (bool): If True, calculates explanations for the forecasted values along with predictions.
automate_monitoring (bool): If True, creates a monitor to calculate the drift for the batch prediction.
automate_monitoring (bool): Controls whether to automatically create a monitor to calculate the drift each time the batch prediction is run. Defaults to true if not specified.
"""
for_eval: bool = dataclasses.field(default=None)
predictions_start_date: str = dataclasses.field(default=None)
Expand Down Expand Up @@ -100,7 +100,7 @@ class PredictiveModelingBatchPredictionArgs(BatchPredictionArgs):
explanation_filter_label (str): For classification problems specifies the label to which the explanation bounds are applied.
output_columns (list): A list of column names to include in the prediction result.
explain_predictions (bool): If True, calculates explanations for the predicted values along with predictions.
automate_monitoring (bool): If True, creates a monitor to calculate the drift for the batch prediction.
automate_monitoring (bool): Controls whether to automatically create a monitor to calculate the drift each time the batch prediction is run. Defaults to true if not specified.
"""
for_eval: bool = dataclasses.field(default=None)
explainer_type: enums.ExplainerType = dataclasses.field(default=None)
Expand Down Expand Up @@ -194,7 +194,7 @@ class TrainablePlugAndPlayBatchPredictionArgs(BatchPredictionArgs):
Args:
for_eval (bool): If True, the test fold which was created during training and used for metrics calculation will be used as input data. These predictions are hence, used for model evaluation.
automate_monitoring (bool): If True, creates a monitor to calculate the drift for the batch prediction.
automate_monitoring (bool): Controls whether to automatically create a monitor to calculate the drift each time the batch prediction is run. Defaults to true if not specified.
"""
for_eval: bool = dataclasses.field(default=None)
automate_monitoring: bool = dataclasses.field(default=None)
Expand Down
11 changes: 11 additions & 0 deletions abacusai/api_class/dataset_application_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ def __post_init__(self):
self.application_connector_type = enums.ApplicationConnectorType.ABACUSUSAGEMETRICS


@dataclasses.dataclass
class FreshserviceDatasetConfig(DatasetConfig):
"""
Dataset config for Freshservice Application Connector
"""

def __post_init__(self):
self.application_connector_type = enums.ApplicationConnectorType.FRESHSERVICE


@dataclasses.dataclass
class _DatasetConfigFactory(_ApiClassFactory):
config_abstract_class = DatasetConfig
Expand All @@ -172,4 +182,5 @@ class _DatasetConfigFactory(_ApiClassFactory):
enums.ApplicationConnectorType.SHAREPOINT: SharepointDatasetConfig,
enums.ApplicationConnectorType.ZENDESK: ZendeskDatasetConfig,
enums.ApplicationConnectorType.ABACUSUSAGEMETRICS: AbacusUsageMetricsDatasetConfig,
enums.ApplicationConnectorType.FRESHSERVICE: FreshserviceDatasetConfig,
}
16 changes: 16 additions & 0 deletions abacusai/api_class/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class ApplicationConnectorType(ApiEnum):
TEAMS = 'TEAMS'
ABACUSUSAGEMETRICS = 'ABACUSUSAGEMETRICS'
MICROSOFTAUTH = 'MICROSOFTAUTH'
FRESHSERVICE = 'FRESHSERVICE'


class PythonFunctionArgumentType(ApiEnum):
Expand Down Expand Up @@ -419,6 +420,7 @@ class LLMName(ApiEnum):
PALM = 'PALM'
PALM_TEXT = 'PALM_TEXT'
GEMINI_PRO = 'GEMINI_PRO'
GEMINI_1_5_PRO = 'GEMINI_1_5_PRO'
MIXTRAL_CHAT = 'MIXTRAL_CHAT'
MISTRAL_MEDIUM = 'MISTRAL_MEDIUM'
ABACUS_SMAUG2 = 'ABACUS_SMAUG2'
Expand Down Expand Up @@ -484,6 +486,20 @@ class FieldDescriptorType(ApiEnum):
DATE = 'DATE'


class WorkflowNodeInputType(ApiEnum):
USER_INPUT = 'USER_INPUT'
WORKFLOW_VARIABLE = 'WORKFLOW_VARIABLE'


class WorkflowNodeOutputType(ApiEnum):
INTEGER = 'INTEGER'
STRING = 'STRING'
BOOLEAN = 'BOOLEAN'
FLOAT = 'FLOAT'
JSON = 'JSON'
LIST = 'LIST'


class OcrMode(ApiEnum):
DEFAULT = 'DEFAULT'
LAYOUT = 'LAYOUT'
Expand Down
Loading

0 comments on commit 9f18560

Please sign in to comment.