Creating a Component#

Before diving into the example of creating a pipeline, it’s crucial to have an overview of the steps required to create an individual component. This section outlines the key steps involved in the process, focusing on the rationale behind each step and the expected outcomes. We won’t delve deeply into the practical details yet; the goal is to provide a clear understanding of the entire process.

The AI on-demand platform introduces some guidelines that we must follow when creating the components to successfully deploy the pipeline. The services must use grpc for communication, and the functions that will be available on the servers must be defined in protofiles. The components and their code will be containerized using docker. The platform also expects the servers and optional web applications to run on specific ports, but we will delve deeper into this at a later stage.

To create a component deployable with AI on-demand tools, you will need to write the necessary service functions, create a proto file based on these services, generate the gRPC code, implement both the client and the server, and, if desired, implement a web application. All of this should be containerized using Docker, and the container image (Docker image) can then be uploaded to Docker Hub. From there, you can upload the Docker image along with the proto file to the AI Builder platform, creating a component that can be used within a pipeline. We will now explore these steps in more detail.

These steps assume that you have already identified your problem, objectives, and deliverables, as well as planned what components to create and their respective inputs and outputs. You should now be ready to start coding.

1. Writing the Service#

First, determine the type of service you need—whether it’s data filtering, model training, making predictions, etc. Once the service is defined, choose a language supported by Protocol Buffers (protobuf) that is suitable for implementing the necessary functions. Protobuf supports languages like C++, C#, Dart, Go, Java, Kotlin, Objective-C, Python, and Ruby. The service should consist of one or more functions that take input and produce output.

For example, you might create a clean_data function that processes raw data into a format suitable for the next component. This illustrates why it’s essential to define the inputs and outputs of all components before coding begins.

Before proceeding, it is vital to test your service to ensure it functions as expected. Testing can be done by calling the service functions directly and verifying the output, or by developing unit tests with known values.

2. Create a Proto File#

Once the service has been tested and verified, you are ready to define the proto file based on your functions. This will be explained in more detail later, but essentially, you need to consider the data required by the functions and define the necessary message structures and services in the proto file.

3. Generate gRPC Code#

With the proto file defined, you can generate the necessary gRPC code for your service. The process of generating this code, as well as the resulting code, will vary depending on the language you have chosen. As discussed in the gRPC notebook, the generated code will include the service interface, as well as the gRPC client and server code.

4. Implement the gRPC Server#

Next, implement the gRPC server using the generated gRPC code. The server should implement the services defined in the proto file. Since you have already defined the functions when creating the service, you can simply import them and ensure that the return values are sent in the correct format, following the messages defined in the proto file.

Again, it’s important to test your application before moving on to the next step. You can test the gRPC server by creating a gRPC client to call the functions available on the server. This will help ensure that all server functions work correctly and that the communication is functioning properly.

5. Write the Web Application#

If you want your component to include a web UI, you’ll need to implement it at this stage. For example, you might create a web UI that allows users to interact with the pipeline or view results, such as predicted values. Since the web application and server will be containerized into a single container, ensure that both can be started with a single command.

After implementing the web application, test it thoroughly—first on its own and then in combination with the server.

6. Containerize the Component#

Finally, create the Dockerfile. This file should copy over the necessary code, run installation commands, and include an entry point command. After writing the Dockerfile, build the Docker image. Once the image is built, test it by running it via the command line or with Docker Desktop to ensure everything works as expected.

Conclusion#

These are the essential steps for creating a component, and this process is the primary focus of this material. Before we move on to more in-depth instructions and examples on how to create these components, we still need to prepare our environment.