HOWTO: ChatGPT Demonstration From Your Azure Enclave Workspace

 

Introduction

Researchers who have been provisioned access to an Azure Enclave ChatGPT project workspace have the ability to run the following basic ChatGPT example for demonstrative purposes after configuring your OpenAI Key in Azure Key Vault.

Requirements

  • You have been provisioned access to an Azure Enclave ChatGPT Project Workspace and have your Azure Enclave Project Workspace Resource Group name provided in your welcome email.
  • You have basic knowledge of how to execute a ChatGPT conversation and tokens.

1. Create Azure Key Vault Secret

The below instructions show you have to create a secret to store your OpenAI key needed to run this demo and OpenAI from your Azure Enclave project workspace. INFOSEC best practices recommends storing this value in key vault. In addition, the instructions show how to obtain the values (#a, #c, #d) used as inputs to run the demo.

1. Login to your Azure Enclave project workspace.

2. Open another tab in your web browser and copy/paste this URL to access your list of project Resources. NOTE: Update the URL string with your Azure Enclave Project Workspace Resource Group value received in your welcome email.

https://portal.azure.com/#@partnershealthcare.onmicrosoft.com/resource/subscriptions/e3980824-3206-4fef-a3b7-4b89756bac30/resourceGroups/{Azure Enclave Project Workspace Resource Group}/overview

3. Click on Type Azure OpenAI.

4. Click Keys and Endpoints under Resource Management on left column.

5. Copy KEY 1 (your secret) and Endpoint (your Endpoint URL #a.) to notepad.

6. Go back to your list of project Resources and click on Type Key vault. Copy the Key Vault Name (#c) to notepad.

7. Click Secrets under Objects on the left column.

8. Click Generate/Import create your secret.

a. Create a unique Name. Copy the Name (#d) you created to notepad.

b. Copy from notepad your saved KEY 1 secret and paste into Secret value

c. Enter mmyy into Content type. Example: May2024

d. Click Create.

You have finished creating your Azure Key Vault Secret and have the three input variables needed to run the below demo.

2. Run Demonstration

1. From your Azure Enclave project workspace, create a Python demonstration.py file with the following code in Visual Studio Code.

import os import openai import time from azure.keyvault.secrets import SecretClient from azure.identity import DefaultAzureCredential from azure.identity import ManagedIdentityCredential ############################################################################### #  CONFIGURATION ############################################################################### openai.api_base = "YourEndpointURLHere" #a. openai.api_version = "2023-06-01-preview"  #b. keyVaultName = "YourKeyVaultNameHere" #c. secretName = "YourSecretNameHere" #d. # END CONFIGURATION ############################################################################### #  MAIN WORK ############################################################################### openai.api_type = "azure" KVUri = 'https://'+keyVaultName+'.vault.azure.net' credential = ManagedIdentityCredential() client = SecretClient(vault_url=KVUri, credential=credential) secret = client.get_secret(secretName) openai.api_key = secret.value question = "What year was Abe Lincoln born?" response = openai.ChatCompletion.create(   engine='FirstDeployment',   messages=[{"role": "user", "content": question}] ) print(response) time.sleep(10) question = "What is a good mountain bike trail in Vermont?" response = openai.ChatCompletion.create(   engine='FirstDeployment',   messages=[{"role": "user", "content": question}] ) print(response) # END MAIN WORK 

a. api_base Replace YourEndpointURLHere with the Endpoint URL copied from the Azure OpenAI resource.

b. api_version Use or replace with the appropriate API version. Further details can be found on the Microsoft Azure OpenAI Service REST API reference page.

c. keyVaultName Replace YourKeyVaultNameHere with the Key Vault Name resource you copied.

d. secretName Replace YourSecretNameHere with the Secret Name you entered when creating your secret.

3. Run demonstration.py. Can be run with following CMD line command:  python demonstration.py

4. Responses to the two questions and token usage are displayed in the Terminal tab:

What year is Abe Lincoln born?

What is a good mountain bike trail in Vermont?

The Azure Enclave Support team can assist with environment issues when executing ChatGPT conversations. We do not provide technical support with specific tools. Researchers utilizing tools are expected to have knowledge and research solutions when using said tools.

For assistance with troubleshooting or platform support with your Azure Enclave Project Workspace environment, please open a Research Issue/Inquiry Request request. Please always include your unique Project Workspace IP Address on all communications.

Additional Resources

MS Azure OpenAI Service REST API reference

OpenAI What are tokens and how to count them?

MS OpenAI tokens and limits

Go to KB0040805 in the IS Service Desk

Related articles