aixplain.modules.agent.tool.model_tool
__author__
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: Lucas Pavanelli and Thiago Castro Ferreira Date: May 16th 2024 Description: Agentification Class
set_tool_name
def set_tool_name(function: Function,
supplier: Supplier = None,
model: Model = None) -> Text
Sets the name of the tool based on the function, supplier, and model.
Arguments:
function
Function - The function to be used in the tool.supplier
Supplier - The supplier to be used in the tool.model
Model - The model to be used in the tool.
Returns:
Text
- The name of the tool.
ModelTool Objects
class ModelTool(Tool)
A tool that wraps AI models to execute specific tasks or functions based on user commands.
This class provides a standardized interface for working with various AI models, allowing them to be used as tools in the aiXplain platform. It handles model configuration, validation, and parameter management.
Attributes:
function
Optional[Function] - The task that the tool performs.supplier
Optional[Supplier] - The preferred supplier to perform the task.model
Optional[Union[Text, Model]] - The model ID or Model instance.model_object
Optional[Model] - The actual Model instance for parameter access.parameters
Optional[Dict] - Configuration parameters for the model.status
AssetStatus - The current status of the tool.
__init__
def __init__(function: Optional[Union[Function, Text]] = None,
supplier: Optional[Union[Dict, Supplier]] = None,
model: Optional[Union[Text, Model]] = None,
name: Optional[Text] = None,
description: Text = "",
parameters: Optional[Dict] = None,
**additional_info) -> None
Initialize a new ModelTool instance.
Arguments:
function
Optional[Union[Function, Text]], optional - The task that the tool performs. Can be a Function enum or a string that will be converted to a Function. Defaults to None.supplier
Optional[Union[Dict, Supplier]], optional - The preferred supplier to perform the task. Can be a Supplier enum or a dictionary with supplier information. Defaults to None.model
Optional[Union[Text, Model]], optional - The model to use, either as a Model instance or a model ID string. Defaults to None.name
Optional[Text], optional - The name of the tool. If not provided, will be generated from function, supplier, and model. Defaults to None.description
Text, optional - A description of the tool's functionality. If not provided, will be taken from model or function description. Defaults to "".parameters
Optional[Dict], optional - Configuration parameters for the model. Defaults to None.**additional_info
- Additional keyword arguments for tool configuration.
Raises:
Exception
- If the specified model doesn't exist or is inaccessible.
to_dict
def to_dict() -> Dict
Convert the tool instance to a dictionary representation.
This method handles the conversion of complex attributes like supplier and model into their serializable forms.
Returns:
Dict
- A dictionary containing the tool's configuration with keys:- function: The function value or None
- type: Always "model"
- name: The tool's name
- description: The tool's description
- supplier: The supplier code or None
- version: The tool's version or None
- assetId: The model's ID
- parameters: The tool's parameters
- status: The tool's status
validate
def validate() -> None
Validates the tool.
Notes:
- Checks if the tool has a function or model.
- If the function is a string, it converts it to a Function enum.
- Checks if the function is a utility function and if it has an associated model.
- Validates the supplier.
- Validates the model.
- If the description is empty, it sets the description to the function description or the model description.
get_parameters
def get_parameters() -> Dict
Get the tool's parameters, either from explicit settings or the model object.
Returns:
Dict
- The tool's parameters. If no explicit parameters were set and a model object exists with model_params, returns those parameters as a list.
validate_parameters
def validate_parameters(
received_parameters: Optional[List[Dict]] = None
) -> Optional[List[Dict]]
Validates and formats the parameters for the tool.
Arguments:
received_parameters
Optional[List[Dict]] - List of parameter dictionaries in format [{"name": "param_name", "value": param_value}]
Returns:
Optional[List[Dict]]
- Validated parameters in the required format
Raises:
ValueError
- If received parameters don't match the expected parameters from model or function
__repr__
def __repr__() -> Text
Return a string representation of the tool.
Returns:
Text
- A string in the format "ModelTool(name=<name>, function=<function>, supplier=<supplier>, model=<model>)".
deploy
def deploy()
Deploy the model tool.
This is a placeholder method as model tools are managed through the aiXplain platform and don't require explicit deployment.