PaaS4GenAI: Connecting Generative AI (WatsonX) On IBM Cloud Platform From Oracle Integration Cloud
Solution of multi-cloud connectivity by leveraging Oracle Integration Cloud with Generative AI WatsonX on IBM Cloud Platform.
Join the DZone community and get the full member experience.
Join For FreeGenerative AI has been the talk of the hour due to its powerful capabilities for doing multiple things like sentiment analysis, summary generation, fact extraction, name entity extraction, email generation, etc.
The powerful capabilities and established use cases of generative AI can be used in different business scenarios, and business flows to perform certain tasks automatically. Capabilities to connect WatsonX from Oracle Cloud through products like Oracle Integration Cloud (OIC) further facilitate using WatsonX for doing certain things by feeding prompts to WatsonX to get desired output.
This will remove the necessity of writing custom logic to extract the required information from an extract of data and instead use Generative AI for doing things that can easily be done through AI capabilities. This will not only help organizations reduce the time required to develop complex applications but also do additional things with the data in hand (data that can be used internally as per data usage terms and policies of an organization), like deriving customer satisfaction with customer feedback, extracting important information from extracts of data.
The document describes the solution of connecting the AI Platform (WatsonX) from the Oracle Integration Cloud and different configurations in the integration that have been developed with the intent to make the solution generic and reusable. With the emergence of generative AI, it is obvious that it is going to be used and integrated into different business processes.
Using Generative UI in business processes may necessarily mean creating the input for the AI engine from data available in different data sources to extract and fetch required pieces of information from the available data automatically using the least effort by automating the process of creating input data for feeding to AI platform and extracting required output from it that can be used in different downstream process. To achieve this, a generic ready-to-use OIC interface is developed that gets the input data (from the application invoking it) and provides the output generated by AI (WatsonX) as a response.
Solution Overview
The app-driven OIC integration requires a mandatory input parameter (the prompt), which it will send to the watsonx.ai REST API for getting output generated from the prompt. The OIC Integration uses an OIC lookup for storing dynamic values that are required to call the watsonx.ai API so that they can be changed and updated as required from time to time as per requirement.
High-Level Architecture
The diagram below shows how Integration between OIC and WatsonX is leveraged so that we can get output against an input prompt directly from OIC Integration without logging into the WatsonX platform.
Security
Access to the OIC interface will be limited to user accesses configured for the OIC Instance as per IDCS configurations for access control. OIC Interface will connect to IBM Cloud with the help of an API Key created in IBM Cloud to get a token to connect to the watsonx.ai project. The token is required for calling the watsonx.ai project (prompt lab) API to get an output against an input prompt.
Technical Details
This section will describe the technical details of the generic solution developed to call watson.ai prompt lab assets to get output against a given prompt directly from Oracle Integration Cloud.
API Key in IBM Cloud
- Step 1: Login into Identity and Access Management — IBM Cloud
- Step 2: Select your Cloud Account
- Step 3: Create a New API Key and give it a meaningful name and description. Save it.
- Step 4: Make sure the API Key shows unlocked.
- Step 5: Get the API key ID by checking the details of the newly created API Key.
watsonx.ai project in IBM Cloud
Step 1: Login
Step 2: Click on the Navigation menu in the top left and select all Projects.
Step 3: Create a New Project (create an empty project)
Step 4: Open the Project. Go to Manage, Select General, and copy the Project ID
OIC Integration
App-driven OIC Integration with REST trigger is created so that it can be run from external clients.
OIC Integration I/P and O/P
Input payload for invoking OIC Integration:
{
"prompt" : "testprompt"
}
Output of OIC Integration:
{
"response" : "testresponse"
}
Assign the Below Variable from an OIC Lookup
APIKey |
Key Created in IBM Cloud for achieving connectivity from Oracle Cloud to IBM Cloud (As shown in section 3.1) |
Model |
The AI model to be used from different preconfigured models available in watsonx.ai |
Version |
Version of the selected model to be used |
WatsonxProjectId |
Project Id of the Project used for creating required Prompt lab assets in watsonx.ai (As shown in section 3.2) |
WatsonxDecodingMethod |
Parameter for watsonx.ai prompt(Sample/Greedy) |
MinToken |
Parameter for watsonx.ai prompt for defining minimum new tokens allowed to be generated for the output against a prompt |
MaxToken |
Parameter for watsonx.ai prompt for defining maximum new tokens allowed to be generated for the output against a prompt |
WatsonxTemperature |
Parameter for watsonx.ai prompt |
top_k |
Parameter for watsonx.ai prompt |
top_p |
Parameter for watsonx.ai prompt |
repetition_penalty |
Parameter for watsonx.ai prompt |
OIC Connections
IBM Cloud connection — REST Invoke Type connection for connecting to URL. No security policy needs to be attached.
WatsonX.ai connection — REST Invoke Type connection for connecting to URL. No security policy needs to be attached.
Get Token from IBM Cloud
Once the above connections are created in OIC, first, we would need to get a token calling a watsonx.ai project. For the same in the OIC integration, use the IBM Cloud Connection (created in Section 3.3.3) and configure a REST endpoint trigger connection for connecting to IBM Cloud by passing the API key to get an access token.
- HTTP Method: POST
- Query Parameters: grant_type, apikey
- HTTP Header Name: Content-Type
Sample Response:
{
"access_token" : "abc",
"refresh_token" : "abc",
"token_type" : "abc",
"expires_in" : 123,
"expiration" : 123,
"scope" : "abc"
}
Mapping:
Standard HTTP Headers: Content Type |
“application/x-www-form-urlencoded” |
Query Parameters: Grant Type |
“urn:ibm:params:oauth:grant-type:apikey” |
Query Parameters: Apikey |
APIKey initialized in section 3.3.1 above |
The access token received in the response of this REST Call would be passed for calling the watsonx.ai project to get a response against an input prompt.
Response Against I/P Prompt From watsonx.ai
Now that we have a token to call the watsonx.ai project to send a prompt and get a response against it, we will use the OIC connection WatsonX.ai connection (Created in Section 3.3.3) to get o/p against the I/P received by the OIC Integration.
- HTTP Method: POST
- Query Parameters: version
Sample Request:
{
"model_id" : "",
"input" : "",
"parameters" : {
"decoding_method" : "",
"max_new_tokens" : 123,
"min_new_tokens" : 456,
"random_seed" : null,
"stop_sequences" : [ 0, 1 ],
"temperature" : 0.0,
"top_k" : 100,
"top_p" : 1,
"repetition_penalty" : 1
},
"project_id" : ""
}
HTTP Header Name: Content-Type, Accept, Authorization
Sample Response:
{
"model_id" : "",
"created_at" : "",
"results" : [ {
"generated_text" : "abcdefghijklmn",
"generated_token_count" : 300,
"input_token_count" : 200,
"stop_reason" : "",
"seed" : 123456
} ]
}
Mapping:
Standard HTTP Headers: Accept |
“application/json” |
Standard HTTP Headers: Authorization |
concat( "Bearer ", Access Token) Access token in the access token received from Step 3.3.3 |
Standard HTTP Headers: Content Type |
“application/json” |
Query Parameters: Version |
Version initialized in section 3.3.1 above |
Model_id |
APIKey initialized in section 3.3.1 above |
Input |
Input parameter received in the request for the OIC Integrtaion |
Decoding Method |
WatsonxDecodingMethod initialized in section 3.3.1 above |
Max New Tokens |
MaxToken initialized in section 3.3.1 above |
Min New Tokens |
MinToken initialized in section 3.3.1 above |
Temperature |
WatsonxTemperature initialized in section 3.3.1 above |
Top K |
top_k initialized in section 3.3.1 above |
Top P |
top_p initialized in section 3.3.1 above |
Repetition Penalty |
repetition_penalty initialized in section 3.3.1 above |
Project Id |
WatsonxProjectId initialized in section 3.3.1 above |
Lastly, Map the “generated_text” output element of this step to the output element of the OIC Integration "response."
Error Handling
Standard error handling practices are to be followed.
- Global error handler configured to send any error to the desired list of recipients obtained from OIC lookup.
- Additionally, a call to watsonx.ai API might be encapsulated with a scope, and both the default handler and API invocation error handler can be configured to perform desired actions in case of any error as per requirement.
Conclusion
Generative AI and its powerful capabilities offer a huge scope and can be used in different business processes and flows for doing repetitive tasks innovatively by minimizing or nullifying manual tasks to the greatest extent possible.
WatsonX’s powerful AI capabilities and features, like being open, trusted, targeted, and empowering, along with preconfigured and trained models for doing tasks like sentiment analysis, information extraction, classification, etc., provide strong use cases that can be leveraged by clients to understand and evaluate different business parameters and outcomes.
Hybrid cloud solutions and multi-cloud solutions are being used by different industry giants to drive their business processes, strategies, and planning. The use of generative AI is already the trend of the hour.
Using the solution described in this article, customers who are in the Oracle Cloud platform and using Oracle Integration can connect to IBM WatsonX directly to get important insights from information in hand without the need to write complex code or implement logic for achieving things like extracting important information from data, and many similar use cases.
OIC Integration for connecting to WatsonX for generative AI tasks can be designed to work in real-time (using app-driven orchestration) or configured to run in specific fixed schedules to do tasks automatically (using scheduled orchestration). With this solution, we have established the proof of connecting to generative AI platforms like WatsonX from other cloud platforms like Oracle.
Future Enhancements and Roadmap
Presently, the connection from OIC (Oracle) to WatsonX is a two-step process where, firstly, a token must be fetched from IBM Cloud IAM API, and then that token is used to interact with the watsonx.ai platform for getting an output against an input prompt. There is a scope to simplify the solution further by using a single OAuth2.0 connection and getting client secret credentials.
The solution has been developed to connect with the IBM Generative AI Platform WatsonX. However, it has been researched and validated that connectivity to other Gen AI platforms like ChatGPT can also be established with small changes in the Integration design. Further enhancement can be made to make the solution generic, where the user would be given the flexibility to choose the Gen AI platform by passing an additional I/P parameter to the OIC Integration, and the integration will have capabilities to get responses against provided input by connecting to the chosen Gen AI platform.
Opinions expressed by DZone contributors are their own.
Comments