AIModelTransformer (autotransform.transformer.aimodel)

The implementation for the AIModelTransformer.

class autotransform.transformer.aimodel.AIModelTransformer(*, model: Model, commands: List[Command] = None, max_completion_attempts: int = 3, max_validation_attempts: int = 3, validators: List[Validator] = None)

Bases: SingleTransformer

A transformer which uses AI models to perform a completion to generate code.

model

The AI Model to use for completions.

Type:

Model

commands

A set of commands to use on transformed files before validation. Useful for correcting things like formatting. Defaults to an empty list.

Type:

optional, List[Command]

max_completion_attempts

The maximum number of times to try the Model. Defaults to 3.

Type:

optional, int

max_validation_attempts

The maximum number of times to validate results. Defaults to 3.

Type:

optional, int

validators

A set of validators to use to provide feedback to the Model with issues it may have produced. Defaults to an empty list.

Type:

optional, List[Validator]

name

The name of the component.

Type:

ClassVar[TransformerName]

commands: List[Command]
classmethod from_data(data: Dict[str, Any]) AIModelTransformer

Produces an instance of the component from decoded data.

Parameters:

data (Mapping[str, Any]) – The JSON decoded data.

Returns:

An instance of the component.

Return type:

AIModelTransformer

max_completion_attempts: int
classmethod max_completion_attempts_must_be_positive(v: int) int

Validates the max_completion_attempts is a positive number.

Parameters:

v (int) – The maximum number of completion attempts for the Model.

Raises:

ValueError – Raises an error when the max_completion_attempts is not positive.

Returns:

The unmodified max_completion_attempts.

Return type:

int

max_validation_attempts: int
classmethod max_validation_attempts_must_be_positive(v: int) int

Validates the max_validation_attempts is a positive number.

Parameters:

v (int) – The maximum number of validation attempts for completion.

Raises:

ValueError – Raises an error when the max_validation_attempts is not positive.

Returns:

The unmodified max_validation_attempts.

Return type:

int

model: Model
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'commands': FieldInfo(annotation=List[Command], required=False, default_factory=list), 'max_completion_attempts': FieldInfo(annotation=int, required=False, default=3), 'max_validation_attempts': FieldInfo(annotation=int, required=False, default=3), 'model': FieldInfo(annotation=Model, required=True), 'validators': FieldInfo(annotation=List[Validator], required=False, default_factory=list)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

name: ClassVar[TransformerName] = 'ai_model'
validators: List[Validator]