AI Pipelines

opengate_data.ai_pipelines

opengate_data.ai_pipelines.ai_pipelines

AIPipelinesBuilder

AIPipelinesBuilder Objects

class AIPipelinesBuilder()

Builder pipelines


with_organization_name
def with_organization_name(organization_name: str) -> 'AIPipelinesBuilder'

Specify the organization name.

Arguments:

  • organization_name str - The name of the organization.

Returns:

  • AIModelsBuilder - Returns self for chaining.

Example:

builder.with_organization_name('organization_name')


with_identifier
def with_identifier(identifier: str) -> 'AIPipelinesBuilder'

Specify the identifier for the pipeline.

Arguments:

  • identifier str - The identifier for the pipeline.

Returns:

  • AIModelsBuilder - Returns self for chaining.

Example:

builder.with_identifier('identifier')


with_env
def with_env(data_env: str) -> 'AIPipelinesBuilder'

Specify the environment variable.

Arguments:

  • data_env str - The environment variable.

Returns:

  • AIModelsBuilder - Returns self for chaining.

Example:

builder.with_env('PIPELINE_ID')


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

builder.with_find_by_name('pipeline_name')


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

[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.


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

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


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

builder.with_name(name_prediction)


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

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


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

  • OperationsSearchBuilder - 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:

builder.build()


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

builder.build_execute()


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

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


find_all
def find_all() -> 'AIPipelinesBuilder'

Retrieves all available pipelines.

Returns:

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

Example:

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


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

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


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

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()


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

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


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

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


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

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()


set_config_file_identifier
def set_config_file_identifier() -> 'AIPipelinesBuilder'

Set the model identifier from a configuration file.

This method sets up the AIModelsBuilder instance to retrieve the model identifier from a specified configuration file. It reads the identifier from the given section and key within the configuration file and sets it for the builder instance.

Returns:

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

Example:

config_file_path = os.path.join(os.path.dirname(__file__), 'config_test.ini')
builder.with_config_file(config_file_path, 'id', 'model_id').set_config_file_identifier().build().execute()


set_env_identifier
def set_env_identifier() -> 'AIPipelinesBuilder'

Set the model identifier from an environment variable.

This method sets up the AIModelsBuilder instance to retrieve the model identifier from a specified environment variable. It reads the identifier from the environment variable and sets it for the builder instance.

Returns:

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

Example:

builder.with_env("MODEL_ENV_VAR").set_env_identifier().build().execute()


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

builder.execute()