Azure OpenAI Integration
Azure OpenAI enables organizations to stay current with AI technology, and is intended to be used as a catalyst to help customers curate the Azure OpenAI integration to their specific needs. A start-up package has been created that provides examples of how this integration could be used to optimize business processes, such as the creation of generative AI-powered product descriptions, or the ability to utilize automated translations. This integration enables organizations to work more efficiently, broaden their delivery base, and improve market responsiveness.
Important: The use of Azure OpenAI integration requires customers to independently obtain an API key through Azure.
Getting Started with OpenAI
Your Azure administrator will need to deploy an Azure OpenAI service and provide you with the endpoint URL and the API key associated with the deployed resource. The URL will be used in the REST Gateway Integration Endpoint, and your API key will be used in the Gateway Integration Authentication function. The format is as follows:
https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions
Additionally, you will need an API version of the Chat Completions Model for the Gateway Integration Authentication function. Search the web for an Azure Chat Completions API version. It is recommended not to use preview versions. For example the API version could be the following:
2024-02-01
After you have acquired an API key through Azure, and you have installed the necessary license and components on your system, the AI Setup group displays in the System Setup tab.
Follow the steps below to get familiar with the starter package provided for OpenAI:
-
Expand the AI Setup folder to display the folders below.
-
Expand the Text Generation folder and its subsequent folders. Each of these subfolders together contain, business rules, a business functions, a Generation Gateway Endpoint, and an Event Processor.
-
Starting with the Text Generation Endpoint folder, configure a REST AI Text Generation Gateway Endpoint as needed. For more information on how to configure the AI Text Generation Gateway Endpoint, refer to the Configuring a Gateway Integration Endpoint topic in the Data Exchange documentation.
For this example, the following REST gateway integration endpoint was configured:
-
Configure the AI Text Generation Gateway Authentication Function.
-
Update the secret bind, in this example the variable is called 'apiKey,' with your Azure OpenAI API key
-
Ensure that the return type is set to Map<String, String>
Important: You need to put Parameter: in front of the key API-version.
In the example below, the following JavaScript Function was created:
Copyvar resultMap = new java.util.HashMap();
resultMap.put("api-key",apiKey);
resultMap.put("Parameter:api-version","2024-02-01");
return resultMap;Important: Should additional Azure OpenAI regions need to be configured, each one requires its own gateway integration endpoint and corresponding authentication header value function. All endpoints that use the same 'your-resource-name' at the start of the URL can use the same authentication function.
-
Business Rule Examples
Users can create business rules to suit their needs when working with OpenAI. For more information on how to create business rules, refer to the Business Rules topic in the Business Rules documentation.
Three example business rules have been provided to create starting points. The binds will have to be modified, and attributes will need to be selected from your data model.
-
Generate Image Alt Text - This example will analyze images and create alternative text suitable for a shopping website.
Note: When selecting the attribute for the Attribute bind intended to hold alternate text, in this example it is called 'aiAltText,' ensure that the attribute has a large enough character limit to accommodate the expected result from Azure OpenAI.
Copy// Generate Alt-Text For Image version 1.0 AI Text Generation.
// NOTE: A bind must be made to the relevant gateway integration endpoint and attributes for this to produce alt-text.
// Text will be stored in the attribute with the binding id "aiAltText".
var role = "Act as a professional copywriter for an online store.";
var task = "You are responsible for analyzing images and creating alt-text suitable for describing the image on a shopping website.";
var format = "The response should focus on being descriptive for people with visual impairments, be less than 100 characters and start with a capital letter.";
var systemInstruction = role + task + format;
var generationRequest = "Generate alt-text for the image";
var result = aiService.buildTextGenerationRequest(openAIEndpoint)
.withSystemMessage(systemInstruction)
.withAssets(currentObject)
.withMessage(generationRequest)
.execute();
currentObject.getValue(aiAltText.getID()).setSimpleValue(result);
logger.info(result);
-
Generate Product Descriptions - This example creates product descriptions for an online clothing store.
Copy// Generate Product Description Action version 1.0 AI Text Generation.
// NOTE: A bind must be made to the relevant gateway integration endpoint and attributes for this to produce a product description.
// The product description will be stored in the attribute with the binding id "aiDescription".
var systemInstruction = "You are an AI assistant, responsible for creating product descriptions for an online clothing store." +
"Your descriptions should be captivating, and evoke a sense of exhilaration. " +
"Emphasize the quality of the materials, craftsmanship, and how the product can enhance the customer's enjoyment.";
var generationRequest = "Write a product description for a product with the following attributes:" +
"Product Name: " + currentObject.getTitle() + "\n"
var brandNameValue = currentObject.getValue(brandName.getID());
if (categoryValue != null && brandNameValue.getSimpleValue() != null) {
generationRequest = generationRequest +
"Brand Name: " + brandNameValue.getSimpleValue() + "\n";
}
var categoryValue = currentObject.getValue(category.getID());
if (categoryValue != null && categoryValue.getSimpleValue() != null) {
generationRequest = generationRequest +
"Category: " + categoryValue.getSimpleValue() + "\n";
}
var featureValues = currentObject.getValue(features.getID());
if (featureValues != null && featureValues.getSimpleValue() != null) {
generationRequest = generationRequest +
"Features: " + featureValues.getSimpleValue().replaceAll("<multisep/>", ", ");
}
// Note, that by increasing the temperature, which is 0.5 by default, the model will produce more random and creative output.
var builder = aiService.buildTextGenerationRequest(openAIEndpoint)
.withSystemMessage(systemInstruction)
.withMessage(generationRequest)
.withTemperature(0.8)
var result = builder.execute();
currentObject.getValue(aiDescription.getID()).setSimpleValue(result);
logger.info(result); -
Generate Translation - This example translates English to German.
Copy// Generate Translation Action version 1.0 AI Text Generation.
// NOTE: A bind must be made to the relevant gateway integration endpoint and attributes for this to produce a translation.
// Translation will be stored in the attribute with the binding id "aiDescription".
function setValueInContext(contextID, value) {
manager.executeInContext(contextID, function(contextManager) {
return contextManager.getObjectFromOtherManager(currentObject).getValue(aiDescription.getID()).setSimpleValue(value);
});
}
var systemInstruction = "You are an AI assistant that translates English to German.";
var generationRequest = currentObject.getValue(description.getID()).getSimpleValue();
if (generationRequest == null) {
logger.info("Nothing to generate");
return;
}
generationRequest = "Translate the following:\n" + generationRequest;
var result = aiService.buildTextGenerationRequest(openAIEndpoint).withSystemMessage(systemInstruction).withMessage(generationRequest).execute();
setValueInContext("DE All All", result);
logger.info(result);
Event Processor Example
Event Processors allow for the collection of events to be logically processed, and actions automatically performed, based upon each event processor's specific configuration. For example, organizations can use event processors to process events via business rules asynchronous in the background, if desired, when working with Azure OpenAI. For more information on how to configure and use event processors, refer to the Event Processors topic in the System Setup documentation. An example event processor has been provided to create a starting point.
-
This example business rule ensures that the event gets picked up by the Azure OpenAI event processor.
CopyeventQueue.queueDerivedEvent(derivedEvent, currentObject);