aixplain.modules.agent.tool.custom_python_code_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
CustomPythonCodeTool Objects
class CustomPythonCodeTool(Tool)
A tool for executing custom Python code in the aiXplain platform.
This tool allows users to define and execute custom Python functions or code snippets as part of their workflow. It supports both direct code input and callable functions.
Attributes:
code
Union[Text, Callable] - The Python code to execute, either as a string or callable.id
str - The identifier for the code interpreter model.status
AssetStatus - The current status of the tool (DRAFT or ONBOARDED).
__init__
def __init__(code: Union[Text, Callable],
description: Text = "",
name: Optional[Text] = None,
**additional_info) -> None
Initialize a new CustomPythonCodeTool instance.
Arguments:
code
Union[Text, Callable] - The Python code to execute, either as a string or callable function.description
Text, optional - Description of what the code does. Defaults to "".name
Optional[Text], optional - Name of the tool. Defaults to None.**additional_info
- Additional keyword arguments for tool configuration.
Notes:
If description or name are not provided, they may be automatically extracted from the code's docstring if available.
to_dict
def to_dict()
Convert the tool instance to a dictionary representation.
Returns:
dict
- A dictionary containing the tool's configuration with keys:- id: The tool's identifier
- name: The tool's name
- description: The tool's description
- type: Always "utility"
- utility: Always "custom_python_code"
- utilityCode: The Python code to execute
validate
def validate()
Validate the tool's configuration and code.
This method performs several checks:
- Parses and validates the Python code if it's not an S3 URL
- Extracts description and name from code's docstring if not provided
- Ensures all required fields (description, code, name) are non-empty
- Verifies the tool status is either DRAFT or ONBOARDED
Raises:
AssertionError
- If any validation check fails, with a descriptive error message.
__repr__
def __repr__() -> Text
Return a string representation of the tool.
Returns:
Text
- A string in the format "CustomPythonCodeTool(name=<tool_name>)".
deploy
def deploy()
Deploy the custom Python code tool.
This is a placeholder method as custom Python code tools are automatically deployed when created.