In this post, we deploy Azure OpenAI base models and test them in the Completions and Chat playgrounds. We’ll get a chance to explore the effects of prompts and parameters on text and code completions.
This post is based on Microsoft Learn documentation:https://learn.microsoft.com/en-us/training/modules/get-started-openai/
Provision an Azure OpenAI resource
Azure OpenAI resources are constrained by regional quotas. Randomly choosing a region reduces the risk of a single region reaching its quota limit in scenarios where we are sharing a subscription with other users. In the event of a quota limit being reached later in the post, there’s a possibility we may need to create another resource in a different region.
Different region offers different quotas, for example, in my subscription in Poland Central region I can choose only from 2 standard quotas:
In West Europe region, I can choose from 36 standard quotas:
If you don’t already have one, provision an Azure OpenAI resource in your Azure subscription.
- Sign into the Azure portal at https://portal.azure.com.
- Create an Azure OpenAI resource with the following settings on the Basics tab, then click Next:
- Subscription: Select an Azure subscription that has been approved for access to the Azure OpenAI service
- Resource group: Choose or create a resource group
- Region: Make a random choice from any of the available regions
- Name: A unique name of your choice. I
Note: If you see an error like this one: “The subdomain name {name} is not available, already used by resource.”, it meansthat if the resource using the name was deleted in the last 48 hours, you may need to purge the deleted resource. You can learn more about this and how to resolve it by visiting the following link: https://go.microsoft.com/fwlink/?linkid=2215493
- Pricing tier: Standard S0
- On the Network tab, choose the best option for you and then click Nexttwice:
- On the Review + submit tab click Createbutton.
5. Wait for deployment to complete. Then click Go to resource button to go to the deployed Azure OpenAI resource in the Azure portal.
Deploy a model
Azure OpenAI provides a web-based portal named Azure OpenAI Studio, that you can use to deploy, manage, and explore models. You’ll start your exploration of Azure OpenAI by using Azure OpenAI Studio to deploy a model.
- On the Overview page for your Azure OpenAI resource, use the Go to Azure OpenAI Studio button to open Azure OpenAI Studio in a new browser tab.
- In Azure OpenAI Studio, on the Deployments tab, view your existing model deployments. If you don’t already have one, create a new deployment of the gpt-35-turbo-16k or gpt-35-turbomodel. Click Create new deployment button:
- Use the following settings and the click Create button:
- Model: gpt-35-turbo-16k (if the 16k model isn’t available, choose gpt-35-turbo)
- Model version: Auto-update to default
- Deployment name: A unique name of your choice
- Advanced options
- Content filter: Default
- Tokens per minute rate limit: 5K*
- Enable dynamic quota: Enabled
* A rate limit of 5,000 tokens per minute is more than adequate to complete this demo while leaving capacity for other people using the same subscription.
- Wait for deployment to complete:
Use the Chat playground
The Chat playground provides a chatbot interface for GPT 3.5 and higher models.
Note: The Chat playground uses the ChatCompletions API rather than the older Completions API that is used by the Completions playground. The Completions playground is provided for compatibility with older models.
- In the Playground section, select the Chat page. The Chat playground page consists of three main sections:
- Assistant setup – used to set the context for the model’s responses.
- Chat session – used to submit chat messages and view responses.
- Configuration – used to configure settings for the model deployment.
- In the Configuration section, ensure that your model deployment is selected.
- In the Assistant setup section, in the System message box, replace the current text with the following statement: The system is an AI teacher that helps people learn about AI.
- Below the System message box, select Add button, and type the following message and response in the designated boxes:
- User: What are different types of artificial intelligence?
- Assistant: There are three main types of artificial intelligence: Narrow or Weak AI (such as virtual assistants like Siri or Alexa, image recognition software, and spam filters), General or Strong AI (AI designed to be as intelligent as a human being. This type of AI does not currently exist and is purely theoretical), and Artificial Superintelligence (AI that is more intelligent than any human being and can perform tasks that are beyond human comprehension. This type of AI is also purely theoretical and has not yet been developed).
Note: Few-shot examples are used to provide the model with examples of the types of responses that are expected. The model will attempt to reflect the tone and style of the examples in its own responses.
- Save the changes by clicking Apply changes, then Continueto start a new session and set the behavioral context of the chat system.
- In the Chat session section, enter the user query What is artificial intelligence?
Note: You may receive a response that the API deployment is not yet ready. If so, wait for a few minutes and try again.
- Review the response and then submit the following message to continue the conversation: How is it related to machine learning?
- Review the response, noting that context from the previous interaction is retained (so the model understands that “it” refers to artificial intelligence).
9. Review the response and then submit the following message to continue the conversation: How is it related to machine learning?
10. Use the View Code button to view the code for the interaction. The prompt consists of the system message, the few-shot examples of user and assistant messages, and the sequence of user and assistant messages in the chat session so far. Available languages:
- Python
- JSON
- C#
- curl
Explore prompts and parameters
You can use the prompt and parameters to maximize the likelihood of generating the response you need.
- In the Parameters pane, set the following parameter values:
- Temperature: 0
- Max response: 500
- Submit the following message:
Write three multiple choice questions based on the following text, indicating the correct answers.
Most computer vision solutions are based on machine learning models that can be applied to visual input from cameras, videos,or images.*
-Image classification involves training a machine learning model to classify images based on their contents.For example,in a traffic monitoring solution you might use an image classification model to classify images based on the type of vehicle they contain, such as taxis, buses, cyclists,and so on.*
-Object detection machine learning models are trained to classify individual objects within an image,and identify their location with a bounding box.For example, a traffic monitoring solution might useobject detection to identify the location of different classes of vehicle.*
-Semantic segmentation is an advanced machine learning technique in which individual pixels in the image are classified according to the object to which they belong.For example, a traffic monitoring solution might overlay traffic images with”mask” layers to highlight different vehicles using specific colors.
- Review the results, which should consist of multiple-choice questions that a teacher could use to test students on the computer vision topics in the prompt. The total response should be smaller than the maximum length you specified as a parameter.
Observe the following about the prompt and parameters you used:
- The prompt specifically states that the desired output should be three multiple choice questions.
- The parameters include Temperature, which controls the degree to which response generation includes an element of randomness. The value of 0 used in your submission minimizes randomness, resulting in stable, predictable responses.
Explore code-generation
In addition to generating natural language responses, you can use GPT models to generate code.
- In the Assistant setup pane, select the Empty Example template to reset the system message.
- Enter the system message: You are a Python developer. and save the changes by clicking Apply changes.
- In the Chat session pane, select Clear chat, then select Clear to clear the chat history and start a new session.
- Submit the following user message:
Write a Pythonfunction named Multiply that multiplies two numeric parameters.
- Review the response, which should include sample Python code that meets the requirement in the prompt.
- The result without saving system message is completely different:
In this demo you learned how to:
- Create an Azure OpenAI Service resource and understand types of Azure OpenAI base models.
- Use the Azure OpenAI Studio, Azure CLI, and REST API to deploy a base model.
- Generate completions to prompts.
- Test models in the Studio’s playgrounds and begin to manage model parameters.