Use this article to learn more about enabling Google Cloud AI Building Blocks for use in your K2 solutions. While this article does not cover using Google AI services, it does show you how to authenticate and configure Google AI services. This article is intended for administrators of K2 and the Google Cloud Platform (GCP) to enable Google Cloud AI Building Blocks for use with the K2 platform.
It is recommended that you are familiar with the OpenAPI specification before starting. OpenAPI (also known as Swagger) forms the basis of how you configure REST integration in K2, which is what is used to connect K2 to the AI Building Blocks. For more information about working with the REST service broker and Swagger, see Resources for Working with the REST Service Broker.
Before you begin, you need the following items. The recommended items are needed if you plan to create your own custom Swagger definitions and are helpful for troubleshooting communication with REST services.
To use Cloud AI Building Blocks with K2, you need a way to authenticate your requests with GCP. One way is by using an API key. You, as a GCP administrator, can get an API key from the GCP console. For more information see Google Cloud > Documentation > Using API Keys.
Before you can configure an instance of the REST broker, you need a Swagger definition file for the endpoints with which you wish to integrate.
It is necessary to create your own Swagger definition for the specific Cloud AI Building Block with which you are integrating. Google does not provide Swagger definitions for the AI Building Blocks, so when you create your own, you can tailor the Swagger definition file to meet your project needs. The K2 administrator and K2 developer should work together to decide what information is needed from the endpoint and create the Swagger definition to meet the project’s use cases.
Whether you decide to customize the provided Swagger or generate your own, you must upload the file to a location on the Internet that can be accessed anonymously. You can use services such as Azure Blob Storage or Google Firebase.
Once you have an URL for your Swagger definition file, you configure the instance of the REST broker to make those endpoints available in K2 via SmartObjects.
For more detail on configuring the REST broker see REST in the K2 Cloud User Guide.
For the purposes of this article that demonstrates authentication using an API key, you pass the API Key value as a query string parameter in your method calls. Your Swagger definition must include this parameter in every API endpoint method call.
For example, an endpoint method call looks like this:
When using RESTUnited.com to create your Swagger, specify a Key as a parameter on the Request page:
When you specify a Key for the parameter on each call in RESTUnited, you see it on all method definitions in the Swagger as shown here:
To reuse this key in K2 Designer, create an environment field to hold its value and use it in your SmartObject calls. You could instead add it as a Specific value in each SmartObject method definition. For more information see Advanced SmartObjects.
When configuring the instance of the REST broker, you must provide the URL to the Swagger descriptor location. In this example, the ModerationSwagger.json Swagger definition file is saved in a Firebase storage location. Click OK to create the instance.
Now that you have registered your instance of the REST broker using the Cloud AI Building Blocks API endpoint, you can create your SmartObjects for use in SmartForms and workflows to call the Google APIs in your K2 solutions. You can use K2 Designer to manually create advanced SmartObjects, or alternatively: