# AI Pipelines

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

## opengate\_data.ai\_pipelines.ai\_pipelines

AIPipelinesBuilder

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder"></a>

### AIPipelinesBuilder Objects

```python
class AIPipelinesBuilder()
```

Builder pipelines

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_organization_name"></a>

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

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

Specify the organization name.

**Arguments**:

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

**Returns**:

- `AIPipelinesBuilder` - Returns self for chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_identifier"></a>

---
#### with\_identifier

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

Specify the identifier for the pipeline.

**Arguments**:

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

**Returns**:

- `AIPipelinesBuilder` - Returns self for chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_env"></a>

---
#### with\_env

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

Specify the environment variable.

**Arguments**:

- `data_env` _str_ - The environment variable.
  

**Returns**:

- `AIPipelinesBuilder` - Returns self for chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_find_by_name"></a>

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

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

Specify the name to find.

**Arguments**:

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

**Returns**:

- `AIPipelinesBuilder` - Returns self for chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_config_file"></a>

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

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

Sets up the configuration file (.ini).

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.
  

**Example**:

  ~~~python
  [id]
  pipeline_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', 'pipeline_id')
  ~~~

**Returns**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_prediction"></a>

---
#### with\_prediction

```python
def with_prediction(data_prediction: dict) -> "AIPipelinesBuilder"
```

Prediction with a model

**Arguments**:

- `data_prediction` _dict_ - Prediction
  

**Raises**:

- `TypeError` - If the prediction is not a dict.
  

**Returns**:

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

**Example**:

  ~~~python
  {
- `"input"` - {},
- `"collect"` - {
- `"deviceId"` - "123456",
- `"datastream"` - "PredictionDatastream"
  }
  }
  builder.with_prediction(prediction)
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.with_name"></a>

---
#### with\_name

```python
def with_name(name: str) -> "AIPipelinesBuilder"
```

Name a new pipeline

**Arguments**:

- `name` _str_ - Name a new pipeline
  

**Raises**:

- `TypeError` - If the name is not a string.
  

**Returns**:

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

**Example**:

  ~~~python
  builder.with_name(name_prediction)
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.add_action"></a>

---
#### add\_action

```python
def add_action(file_name: str,
               type_action: str | None = None) -> "AIPipelinesBuilder"
```

Add action name and type of model or transform exist.

**Arguments**:

- `file_name` _str_ - The name of the file representing the action.
- `type_action` _str | None_ - The type of the action, either 'MODEL' or 'TRANSFORMER'. If None, it will be inferred from the file extension.
  

**Raises**:

- `TypeError` - If file_name is not a string.
- `TypeError` - If type_action is not a string or None.
  

**Returns**:

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

**Example**:

  ~~~python
  builder.add_action('transform.py', 'TRANSFORMER')
  builder.add_action('test/file_create.onnx', 'MODEL')
  builder.add_action('test/file_update.onnx')
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.build"></a>

---
#### build

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

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**:

- `AIPipelinesBuilder` - 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.
  

**Notes**:

  This method should be used as a final step before `execute` to prepare the operations search configuration. It does not modify the state but ensures that the builder's state is ready for execution.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.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_pipelines.ai_pipelines.AIPipelinesBuilder.create"></a>

---
#### create

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

Creates a new pipeline.

This method prepares the request to create a new pipeline using the specified configuration in the object. It is necessary to define the name (`with_name`) and actions (`add_action`) before calling this method.

**Returns**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name(organization)
  .with_name('MyPipeline').add_action('transform.py', 'TRANSFORMER')
  .add_action('test/file_create.onnx', 'MODEL')
  .create()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.find_all"></a>

---
#### find\_all

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

Retrieves all available pipelines.

**Returns**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.find_one"></a>

---
#### find\_one

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

Finds a specific pipeline by its identifier.

This method prepares the request to find a specific pipeline 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**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

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

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.update"></a>

---
#### update

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

Updates an existing pipeline.

This method prepares the request to update an existing pipeline. It is necessary to define the organization's name (`with_organization_name`) and the pipeline's name (`with_name`) before calling this method.

**Returns**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('MyOrganization').with_identifier("pipeline_identifier").with_name('MyPipeline').update()
  config_file_path = os.path.join(os.path.dirname(__file__), 'config_test.ini')
  builder.with_organization_name('MyOrganization').with_find_by_name("pipeline_name").with_config_file(config_file_path, 'id', 'model').with_name('MyPipeline').update()
  builder.with_organization_name('MyOrganization').with_name('MyPipeline').update()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.delete"></a>

---
#### delete

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

Deletes an existing pipeline.

This method prepares the request to delete an existing pipeline. It is necessary to define the organization's name (`with_organization_name`) and the pipeline's identifier (`with_identifier`) before calling this method.

**Returns**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

  ~~~python
  builder.with_organization_name('MyOrganization').with_identifier('pipeline_identifier').delete()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.prediction"></a>

---
#### prediction

```python
def prediction() -> "AIPipelinesBuilder"
```

Performs a prediction with a model.

This method prepares the request to perform a prediction using the model associated with the specified pipeline. It is necessary to define the organization's name (`with_organization_name`), the pipeline's identifier (`with_identifier`), and provide prediction data (`with_prediction`) before calling this method.

**Returns**:

- `AIPipelinesBuilder` - Returns the same object to allow method chaining.
  

**Example**:

  ~~~python
- `builder.with_organization_name('MyOrganization').with_identifier('pipeline_identifier').with_prediction({'input'` - {}, 'collect': {'deviceId': '123456', 'datastream': 'PredictionDatastream'}}).prediction()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.save"></a>

---
#### save

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

Save the model configuration.

This method sets up the AIPipelinesBuilder instance to save the configuration of a model associated with the specified organization. It configures the URL endpoint for the save operation and sets the operation type to 'save'.

**Returns**:

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

**Example**:

  ~~~python
  builder.with_organization_name("MyOrganization").with_env("MODEL_ENV_VAR").save().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').save().build().execute()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.set_config_file_identifier"></a>

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

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

Selects the operation that writes the pipeline identifier into a
configuration file.

It stores the identifier given to `with_identifier()` under the section
and key named with `with_config_file()`, so a later run can pick the
pipeline up from the file instead of carrying its identifier in the code.
The key must already exist in the file.

**Returns**:

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

**Example**:

  ~~~python
  builder.with_identifier("pipeline_identifier").with_config_file(
  'pipeline_config.ini', 'id', 'pipeline_id'
  ).set_config_file_identifier().build().execute()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.set_env_identifier"></a>

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

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

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

It stores the identifier given to `with_identifier()` under the variable
named with `with_env()`, so a later run can pick the pipeline up from the
environment. The variable must already exist in the `.env` file.

**Returns**:

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

**Raises**:

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

**Example**:

  ~~~python
  builder.with_identifier("pipeline_identifier").with_env(
  "PIPELINE_ID"
  ).set_env_identifier().build().execute()
  ~~~

<a id="opengate_data.ai_pipelines.ai_pipelines.AIPipelinesBuilder.execute"></a>

---
#### execute

```python
def execute()
```

Execute the configured operation and return the response.

This method executes the operation that has been configured using the builder pattern. It ensures that the `build` method has been called and that it is the last method invoked before `execute`. Depending on the configured method (e.g., create, find, update, delete), it calls the appropriate internal execution method.

**Returns**:

- `requests.Response` - The response object from the executed request.
  

**Raises**:

- `Exception` - If the `build` method has not been called or if it is not the last method invoked before `execute`.
- `ValueError` - If the configured method is unsupported.
  

**Example**:

  ~~~python
  builder.execute()
  ~~~

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

## opengate\_data.ai\_pipelines

