How to connect to Azure OpenAI in Dialogue Studio
Introduction
This guide will show you how to connect to Azure OpenAI to use AI functionalities in your Dialogue Studio flow.
Prerequisites
For this scenario the following point must be done first:
-
UCC A Unified Contact Center, or UCC, is a queue of interactions (voice, email, IM, etc.) that are handled by Agents. Each UCC has its own settings, IVR menus and Agents. Agents can belong to one or several UCCs and can have multiple skills (competencies). A UCC can be visualized as a contact center “micro service”. Customers can utilize one UCC (e.g. a global helpdesk), a few UCC’s (e.g. for each department or regional office) or hundreds of UCC’s (e.g. for each bed at a hospital). They are interconnected and can all be managed from one central location. configured with Dialogue Studio
-
Azure OpenAI resource in Azure (for more information see: Azure OpenAI resource creation)
Deploying a Model and Retrieving an API Key
-
Navigate to Azure OpenAI.
-
Ensure you have a resource. If not, see Azure OpenAI resource creation.
-
Go to Shared resources > Deployments.
-
If you already have the model you want deployed, select it and continue on step 9.
Note
You need a model for Text Completion.
-
If not, click on Deploy model and select Deploy a Base Model.
-
Choose the model you want, and click Confirm.
Note
You need a model for Text Completion
-
Configure the deployment settings (Deployment name, Model Version, Tokens per Minute Rate Limit) and click Deploy.
-
Once your model is deployed, you will see it in the list. Open it.
-
In the Details section, copy the Target URI and Key. You will use these in the Dialogue Studio flow.
Store Azure OpenAI Configuration in Dialogue Studio
-
Navigate to your Dialogue Studio and sign in.
-
Press
Ctrl+i
to import the following JSON into your Dialogue Studio:CopyJSON[{"id":"9760b1e2ed0cafda","type":"group","z":"97b7ba1c633f04d4","name":"Placeholder central configuration","style":{"label":true},"nodes":["2473a183e0e2a60b","15979c1d5aece365"],"x":1174,"y":79,"w":472,"h":82},{"id":"2473a183e0e2a60b","type":"function","z":"97b7ba1c633f04d4","g":"9760b1e2ed0cafda","name":"Configuration","func":"global.set(\"AzureOpenAI-Config\", {\n apiKey: \"\",\n url: \"\"\n});\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":120,"wires":[[]]},{"id":"15979c1d5aece365","type":"inject","z":"97b7ba1c633f04d4","g":"9760b1e2ed0cafda","name":"Click to save settings","props":[],"repeat":"3600","crontab":"","once":true,"onceDelay":"10","topic":"","x":1320,"y":120,"wires":[["2473a183e0e2a60b"]]}]
-
Import it into the flow you prefer.
-
Open the Configuration node (Function node).
-
Enter the URL and Key you copied from Deploying a Model and Retrieving an API Key
-
Click Deploy to save the changes. (Note: The Inject node’s repeat function will automatically inject.)
Simple Interaction with Azure OpenAI
-
Press Ctrl+i to import the following JSON into your Dialogue Studio:
CopyJSON[{"id":"8bfaa77a9d043fd6","type":"inject","z":"97b7ba1c633f04d4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"what is 1 + 1 ?","payloadType":"str","x":560,"y":280,"wires":[["d5cfb649254c136a"]]},{"id":"7a328eaea28b5e0f","type":"debug","z":"97b7ba1c633f04d4","name":"Output: Simple Chat","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1400,"y":280,"wires":[]},{"id":"6cddd53295e53f8b","type":"group","z":"97b7ba1c633f04d4","name":"Node blueprint: Simple Chat from OpenAI","style":{"label":true},"nodes":["26ba9ac1503af363","d5cfb649254c136a","4a80997dd8e8d17e"],"x":654,"y":239,"w":632,"h":82},{"id":"26ba9ac1503af363","type":"http request","z":"97b7ba1c633f04d4","g":"6cddd53295e53f8b","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1010,"y":280,"wires":[["4a80997dd8e8d17e"]]},{"id":"d5cfb649254c136a","type":"function","z":"97b7ba1c633f04d4","g":"6cddd53295e53f8b","name":"Prepare request for OpenAI","func":"const url = global.get(\"AzureOpenAI-Config.url\");\nconst key = global.get(\"AzureOpenAI-Config.apiKey\");\nconst message = msg.payload;\n\nmsg.headers = {\n \"Content-Type\": \"application/json\",\n \"api-key\": key\n};\n\nmsg.url = url;\n\n// Main JSON structure, referencing the variables\nmsg.payload = {\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are an AI assistant that helps people find information.\"\n },\n {\n \"role\": \"user\",\n \"content\": message\n } \n ],\n \"temperature\": 0.7,\n \"top_p\": 0.95,\n \"n\": 2,\n \"stream\": false,\n \"max_tokens\": 4096,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0\n};\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":280,"wires":[["26ba9ac1503af363"]]},{"id":"4a80997dd8e8d17e","type":"change","z":"97b7ba1c633f04d4","g":"6cddd53295e53f8b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.choices[0].message.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":280,"wires":[["7a328eaea28b5e0f"]]}]
-
Click Deploy to save the changes.
-
Press the inject node to trigger the flow.
-
In the debug window, you should see the response from OpenAI.