Getting Started with Azure OpenAI Service
Welcome to the Azure OpenAI Service! This guide will help you get started with deploying and using powerful OpenAI models like GPT-3.5 Turbo, GPT-4, and DALL-E in your Azure environment.
Prerequisites
Before you begin, ensure you have the following:
- An Azure subscription. If you don't have one, you can sign up for a free account.
- Access to Azure OpenAI Service. Due to high demand, access is currently limited and requires an application and approval. Apply for access.
Step 1: Create an Azure OpenAI Resource
Once your access is approved, you can create an Azure OpenAI resource in the Azure portal.
- Sign in to the Azure portal.
- Search for "Azure OpenAI" and select it.
- Click "Create".
- Fill in the required details: Subscription, Resource group, Region, Name, and Pricing tier.
- Click "Review + create", then "Create".
Step 2: Deploy a Model
After creating your resource, you need to deploy a specific OpenAI model to use it.
- Navigate to your newly created Azure OpenAI resource in the Azure portal.
- Go to "Model deployments" under "Resource Management".
- Click "Create new deployment".
- Select a model (e.g.,
gpt-35-turbo) and a deployment name. - Click "Create".
Step 3: Get Your API Key and Endpoint
You'll need your API key and endpoint to make requests to the service.
- In your Azure OpenAI resource, go to "Keys and Endpoint" under "Resource Management".
- Copy your "Endpoint" and one of the "Keys". Keep these secure.
Step 4: Making Your First API Call
You can interact with the deployed model using various SDKs or directly via REST API. Here's an example using Python:
import os
import openai
# Configure OpenAI
openai.api_type = "azure"
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
openai.api_version = "2023-05-15" # Or your preferred API version
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
deployment_name = 'your-deployment-name' # Replace with your deployment name
try:
response = openai.ChatCompletion.create(
engine=deployment_name,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain Azure OpenAI Service in one sentence."}
]
)
print(response.choices[0].message.content)
except Exception as e:
print(f"An error occurred: {e}")
Make sure to set the AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY environment variables with your respective values.
Key API Endpoints
| Operation | Endpoint |
|---|---|
| Chat Completions | /openai/deployments/{deployment}/chat/completions?api-version={api-version} |
| Completions | /openai/deployments/{deployment}/completions?api-version={api-version} |
| Embeddings | /openai/deployments/{deployment}/embeddings?api-version={api-version} |
Next Steps
Explore the different models available, learn about fine-tuning, and discover how to integrate Azure OpenAI Service into your applications.