Azure OpenAI service offers text generation using models like GPT. They are trained to generate a response or content from a prompt supplied to them. We can use this offering in our Power Virtual Agents (PVAs) to create automated responses, generate texts, and more.
In this article, we will explore how to integrate the Azure OpenAI service text generation with GPT in Power Virtual Agents.
Set up Azure OpenAI Service
Access to Azure OpenAI is on a request basis. If you do not have one, you need to raise a request at: https://aka.ms/oai/access.
From the Azure portal, find and create a resource, Azure OpenAI.
Deploy a model
Once the Azure OpenAI service is ready, deploy the gpt-35-turbo model.
Once the model is deployed, click open the chat playground to test it out. Use a system message template as an Xbox customer support agent.
In Chat Completion API there are distinct sections of the prompt that are sent to the API in the form of an array of dictionaries with associated roles:
System : The system’s role is to process user inputs, interpret their intent, and generate appropriate and relevant outputs. It leverages the trained models and prompt engineering techniques to understand and respond to user queries or requests.
User : The user represents the person interacting with the conversational AI system. They input their queries, requests, or commands through text or speech. The user’s role is to communicate their needs or seek information from the assistant.
Assistant : The assistant is the virtual entity that interacts with the user and provides responses or assistance.
Clicking the View code will show you the options to start integrating your current prompt and settings into your application.
The sample code makes it clear that we can use the REST APIs to consume Azure OpenAI in our applications.
Use Custom Connector
You can either build a custom connector from scratch to interact with the OpenAI APIs or can use the one available on GitHub.
Follow the steps below to use a custom connector.
- Navigate to the Power Automate page (https://make.powerautomate.com).
- Under Data, click Custom Connectors.
- Click New custom connector > Import from GitHub.
AzureOpenAIServiceconnector as shown below:
After you create the connector, click the Test tab and select New Connection.
To make a connection, provide the Azure OpenAI service instance name and API Key.
Using the Chat Completion API in Power Virtual Agent
Follow the below steps to use the custom connector in PVA.
- Create a new chatbot.
- Create a new topic inside it with the name xbox.
Add the phrases as xbox and gaming.
- Add an Ask a question node to get the user response and store it in a variable (e.g., VarUserQuestion).
- We will now add a node Call an action > Create a flow.
Accept the user question to start with the flow.
Add an action to use our OpenAI custom connector.
Configure the chat completion API as follows:
Return the answer from the Chat completion API.
- Configure the action with input and output.
Add a node with Send a message with an output of flow.
Test the PVA
Start an interaction with xbox intention to see the answer being generated from the chat completions API.
Azure OpenAI service offers text generation using models like GPT. They are trained to generate a response or content from a prompt supplied to them. We can build or use custom connectors to surface the REST APIs to consume Azure OpenAI in our applications.