# AI Transformers

<a id="opengate_data.ai_transformers.ai_transformers"></a>

## opengate\_data.ai\_transformers.ai\_transformers

AITransformersBuilder

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder"></a>

### AITransformersBuilder Objects

```python
class AITransformersBuilder()
```

Class transformer builder

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_organization_name"></a>

---
#### with\_organization\_name

```python
def with_organization_name(organization_name: str) -> "AITransformersBuilder"
```

Specify the organization name.

**Arguments**:

- `organization_name` _str_ - The name of the organization.
  

**Returns**:

- `AITransformersBuilder` - Returns self for chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('organization_name')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_identifier"></a>

---
#### with\_identifier

```python
def with_identifier(identifier: str) -> "AITransformersBuilder"
```

Specify the identifier for the pipeline.

**Arguments**:

- `identifier` _str_ - The identifier for the pipeline.
  

**Returns**:

- `AITransformersBuilder` - Returns self for chaining.
  

**Example**:

  ~~~python
  builder.with_identifier('identifier')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_env"></a>

---
#### with\_env

```python
def with_env(data_env: str) -> "AITransformersBuilder"
```

Specify the environment variable.

**Arguments**:

- `data_env` _str_ - The environment variable.
  

**Returns**:

- `AITransformersBuilder` - Returns self for chaining.
  

**Example**:

  ~~~python
  builder.with_env('TRANSFORMER_ID')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_config_file"></a>

---
#### with\_config\_file

```python
def with_config_file(config_file: str, section: str,
                     config_key: str) -> "AITransformersBuilder"
```

This method allows specifying a configuration file, a section within that file,
and a key to retrieve a specific value from the section.

**Arguments**:

- `config_file` _str_ - The path to the.ini configuration file.
- `section` _str_ - The section name within the.ini file where the desired configuration is located.
- `config_key` _str_ - The key within the specified section whose value will be retrieved.
  

**Raises**:

- `TypeError` - If the provided config_file is not a string.
- `TypeError` - If the provided section is not a string.
- `TypeError` - If the provided config_key is not a string.

**Returns**:

  AITransformersBuilder
  

**Example**:

  ~~~python
  [id]
  model_id = afe07216-14ec-4134-97ae-c483b11d965a
  
  config_file_path = os.path.join(os.path.dirname(__file__), 'config_test.ini')
  builder.with_config_file(config_file_path, 'id', 'model_id')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.add_file"></a>

---
#### add\_file

```python
def add_file(file_path: str, filetype: str = None)
```

Adds a file to the transformer resource.

This method allows specifying one or more files to be included in the transformer resource being created. The content type for each file can be specified if needed.

**Arguments**:

- `file_path` _str_ - Full path to the file to add.
- `filetype` _str, optional_ - Content type of the file. Defaults to None, meaning the content type will be automatically inferred.
  

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  ai_transformer_create = client.new_ai_transformers_builder().with_organization_name('organization')
  .add_file('exittransformer.py', 'text/python')
  .add_file('pkl_encoder.pkl')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_find_by_name"></a>

---
#### with\_find\_by\_name

```python
def with_find_by_name(find_name: str) -> "AITransformersBuilder"
```

Specify the name to find.

**Arguments**:

- `find_name` _str_ - The name of the transformer.
  

**Returns**:

- `AITransformersBuilder` - Returns self for chaining.
  

**Example**:

  ~~~python
  builder.with_find_by_name('transformer_name')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_evaluate"></a>

---
#### with\_evaluate

```python
def with_evaluate(data_evaluate: dict) -> "AITransformersBuilder"
```

Evaluate with transformer

**Arguments**:

- `data_evaluate` _dict_ - Evaluate
  

**Raises**:

- `TypeError` - If to evaluate is not a dict.
  

**Returns**:

- `AITransformersBuilder` - Returns itself to allow for method chaining.
  

**Example**:

  ~~~python
  evaluate_data = {
- `"data"` - {
- `"PPLast12H"` - 0,
- `"PPLast24H"` - 0,
- `"PPLast72H"` - 1,
- `"currentTemp"` - -2,
- `"changeTemp"` - -2
  },
- `"date"` - "2022-06-13T13:59:34.779+02:00"
  }
  builder.with_evaluate(evaluate_data)
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_output_file_path"></a>

---
#### with\_output\_file\_path

```python
def with_output_file_path(output_file_path: str) -> "AITransformersBuilder"
```

Sets the output file path for the transformer.

This method allows you to specify the path where the output file will be saved.
It is particularly useful for operations that involve downloading or saving files.

**Arguments**:

- `output_file_path` _str_ - The path where the output file will be saved.
  

**Returns**:

- `AITransformersBuilder` - The instance of the AIModelsBuilder class.
  

**Example**:

  ~~~python
  builder.with_output_file_path("rute/prueba.onnx")
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.with_file_name"></a>

---
#### with\_file\_name

```python
def with_file_name(file_name: str) -> "AITransformersBuilder"
```

Specifies the name of the file to be processed.

This method allows you to specify the name of the file that will be used in operations such as download or evaluation. It is particularly useful when working with specific files that require unique identifiers or names for processing.

**Arguments**:

- `file_name` _str_ - The name of the file to be processed.
  

**Returns**:

- `AITransformersBuilder` - Returns self for chaining.
  

**Example**:

  ~~~python
  builder.with_file_name('pkl_encoder.pkl')
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.create"></a>

---
#### create

```python
def create() -> "AITransformersBuilder"
```

Prepares the creation of the transformer resource.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('organization').add_file(
  'exittransformer.py', 'text/python'
  ).add_file('pkl_encoder.pkl').create().build().execute()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.find_all"></a>

---
#### find\_all

```python
def find_all() -> "AITransformersBuilder"
```

Searches for all available transformer resources.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').find_all()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.find_one"></a>

---
#### find\_one

```python
def find_one() -> "AITransformersBuilder"
```

Searches for a single transformer resource by its identifier.

This method prepares the request to find a specific transformer based on its identifier. The identifier is obtained automatically if not explicitly defined or can be obtained from a configuration file or environment variables.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').with_identifier('identifier').find_one()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.update"></a>

---
#### update

```python
def update() -> "AITransformersBuilder"
```

Updates an existing transformer resource.

This method prepares the URL and HTTP method necessary to send a PUT request to the API to update an existing transformer. It is necessary to configure the relevant attributes of the `AITransformersBuilder` instance, including the `identifier` of the transformer to update, before calling this method.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').with_identifier('identifier').update()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.delete"></a>

---
#### delete

```python
def delete() -> "AITransformersBuilder"
```

Deletes an existing transformer resource.

This method prepares the URL and HTTP method necessary to send a DELETE request to the API to delete an existing transformer. It is necessary to configure the `identifier` attribute of the `AITransformersBuilder` instance before calling this method.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').with_identifier('identifier').delete()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.download"></a>

---
#### download

```python
def download() -> "AITransformersBuilder"
```

Download the model file.

This method sets up the AIModelsBuilder instance to download the file of a specific model associated with the specified organization and identifier. It configures the URL endpoint for the download operation and sets the operation type to 'download'.

**Returns**:

- `AITransformersBuilder` - The instance of the AIModelsBuilder class itself, allowing for method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name("MyOrganization").with_identifier("model_identifier").with_output_file_path("model.onnx").download().build().execute()
  builder.with_organization_name("MyOrganization").with_find_by_name("model_name.onnx").with_output_file_path("model.onnx").download().build().execute()
  config_file_path = os.path.join(os.path.dirname(__file__), 'config_test.ini')
  builder.with_organization_name("MyOrganization").with_config_file(config_file_path, 'id', 'model').with_output_file_path("model.onnx").download().build().execute()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.evaluate"></a>

---
#### evaluate

```python
def evaluate() -> "AITransformersBuilder"
```

Prepares the evaluation of the transformer with provided data.

This method sets up the URL and method for evaluating the transformer using the provided data. The evaluation data should be set using the `with_evaluate` method before calling this method.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').with_identifier('identifier').with_evaluate(evaluate_data).evaluate()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.save"></a>

---
#### save

```python
def save() -> "AITransformersBuilder"
```

Saves the transformer configuration.

This method prepares the URL and method for saving the transformer configuration. It checks if the identifier is set from the environment or configuration file and then either updates or creates the transformer accordingly.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('my_organization').with_env('TRANSFORMER_ID').save()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.set_config_file_identifier"></a>

---
#### set\_config\_file\_identifier

```python
def set_config_file_identifier() -> "AITransformersBuilder"
```

Sets the transformer identifier in the configuration file.

This method sets the transformer identifier in the specified configuration file. It reads the configuration file, updates the identifier, and writes the changes back to the file.

**Returns**:

- `AITransformersBuilder` - Returns the current instance to allow method chaining.
  

**Example**:

  ~~~python
  config_file_path = os.path.join(os.path.dirname(__file__), 'config_test.ini')
  builder.with_config_file(config_file_path, 'id', 'transformer_id').set_config_file_identifier()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.set_env_identifier"></a>

---
#### set\_env\_identifier

```python
def set_env_identifier() -> "AITransformersBuilder"
```

Selects the operation that writes the transformer identifier into the
`.env` file.

It stores the identifier held by the builder under the variable named
with `with_env()`, so a later run can pick the transformer up from the
environment. The variable must already exist in the `.env` file.

**Returns**:

- `AITransformersBuilder` - Returns itself to allow for method chaining.
  

**Raises**:

- `ValueError` - If the variable is not in the `.env` file.
  

**Example**:

  ~~~python
  builder.with_identifier("transformer_identifier").with_env(
  "TRANSFORMER_ID"
  ).set_env_identifier().build().execute()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.build"></a>

---
#### build

```python
def build() -> "AITransformersBuilder"
```

Finalizes the construction of the IoT collection configuration.

This method prepares the builder to execute the collection by ensuring all necessary configurations are set and validates the overall integrity of the build. It should be called before executing the collection to ensure that the configuration is complete and valid.

The build process involves checking that mandatory fields such as the device identifier are set. It also ensures that method calls that are incompatible with each other (like `build` and `build_execute`) are not both used.

**Returns**:

- `AITransformersBuilder` - Returns itself to allow for method chaining, enabling further actions like `execute`.
  

**Raises**:

- `ValueError` - If required configurations are missing or if incompatible methods are used together.
  

**Example**:

  ~~~python
  builder.build()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.build_execute"></a>

---
#### build\_execute

```python
def build_execute()
```

Executes the data sets search immediately after building the configuration.

This method is a shortcut that combines building and executing in a single step.

**Returns**:

- `dict` - A dictionary containing the execution response which includes the status code and potentially other metadata about the execution.
  

**Raises**:

- `ValueError` - If `build` has already been called on this builder instance.
  

**Example**:

  ~~~python
  builder.build_execute()
  ~~~

<a id="opengate_data.ai_transformers.ai_transformers.AITransformersBuilder.execute"></a>

---
#### execute

```python
def execute() -> requests.Response
```

Sends the selected operation to the platform.

Which request goes out depends on the operation chosen in the chain:
create, find, update, delete, download, evaluate, save, or resolving the
identifier from a configuration file or from the environment.

**Returns**:

  requests.Response | dict | str: Whatever the selected operation
  produces — the transformer payload, the contents of a downloaded
  file, or a dict carrying `status_code` and either `data` or `error`.
  

**Raises**:

- `ValueError` - If no operation was selected in the chain.
  

**Example**:

  ~~~python
  builder.with_organization_name("organization").find_all().build().execute()
  ~~~

<a id="opengate_data.ai_transformers"></a>

## opengate\_data.ai\_transformers

