On Premises

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:

Deploying a Model and Retrieving an API Key

  1. Navigate to Azure OpenAI.

  2. Ensure you have a resource. If not, see Azure OpenAI resource creation.

  3. Go to Shared resources > Deployments.

  4. If you already have the model you want deployed, select it and continue on step 9.

    Note

    You need a model for Text Completion.

  5. If not, click on Deploy model and select Deploy a Base Model.

  6. Choose the model you want, and click Confirm.

    Note

    You need a model for Text Completion

  7. Configure the deployment settings (Deployment name, Model Version, Tokens per Minute Rate Limit) and click Deploy.

  8. Once your model is deployed, you will see it in the list. Open it.

  9. 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

  1. Navigate to your Dialogue Studio and sign in.

  2. Press Ctrl+i to import the following JSON into your Dialogue Studio:

    Copy
    JSON
    [{"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"]]}]
  3. Import it into the flow you prefer.

  4. Open the Configuration node (Function node).

  5. Enter the URL and Key you copied from Deploying a Model and Retrieving an API Key

  6. Click Deploy to save the changes. (Note: The Inject node’s repeat function will automatically inject.)

Simple Interaction with Azure OpenAI

  1. Press Ctrl+i to import the following JSON into your Dialogue Studio:

    Copy
    JSON
    [{"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"]]}]
  2. Click Deploy to save the changes.

  3. Press the inject node to trigger the flow.

  4. In the debug window, you should see the response from OpenAI.