aixplain.v2.code_utils
from aixplain import UtilityModelInput, UtilityModelInputDict
Code parsing utilities for v2 utility models.
Adapted from aixplain.modules.model.utils to avoid v1 import chain that triggers env var validation.
UtilityModelInputDict Objects
class UtilityModelInputDict(TypedDict)
The dict form of UtilityModelInput, on the same field names.
total=True: name and description have no default on the struct,
so marking them optional would let a dict type-check and then fail at
runtime. Only type defaults.
UtilityModelInput Objects
@dataclass
class UtilityModelInput()
Input parameter for a utility model.
Attributes:
name- The name of the input parameter.description- A description of what this input parameter represents.type- The data type of the input parameter -- aDataTypeor its string value ("text","boolean","number").
__setattr__
def __setattr__(name: str, value: Any) -> None
Coerce a string type into a DataType on every assignment.
to_dict reads self.type.value, so a plain string left as-is would
reach the wire as an AttributeError. Coercing on assignment (not only
in __post_init__) keeps construction and later assignment identical.
validate
def validate()
Validate that the input type is one of TEXT, BOOLEAN, or NUMBER.
to_dict
def to_dict()
Convert to dictionary representation.
parse_code
def parse_code(
code: Union[Text, Callable],
api_key: Optional[Text] = None,
backend_url: Optional[Text] = None) -> Tuple[Text, List, Text, Text]
Parse and process code for utility model creation.
Arguments:
code- The code to parse (callable, file path, URL, or raw code string).api_key- API key for authentication when uploading code.backend_url- Backend URL for file upload.
Returns:
Tuple of (code_url, inputs, description, name).
parse_code_decorated
def parse_code_decorated(
code: Union[Text, Callable],
api_key: Optional[Text] = None,
backend_url: Optional[Text] = None) -> Tuple[Text, List, Text, Text]
Parse and process code that may be decorated with @utility_tool.
Arguments:
code- The code to parse (decorated/non-decorated callable, file path, URL, or raw string).api_key- API key for authentication when uploading code.backend_url- Backend URL for file upload.
Returns:
Tuple of (code_url, inputs, description, name).