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:

Step 1: Create an Azure OpenAI Resource

Once your access is approved, you can create an Azure OpenAI resource in the Azure portal.

  1. Sign in to the Azure portal.
  2. Search for "Azure OpenAI" and select it.
  3. Click "Create".
  4. Fill in the required details: Subscription, Resource group, Region, Name, and Pricing tier.
  5. 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.

  1. Navigate to your newly created Azure OpenAI resource in the Azure portal.
  2. Go to "Model deployments" under "Resource Management".
  3. Click "Create new deployment".
  4. Select a model (e.g., gpt-35-turbo) and a deployment name.
  5. Click "Create".

Step 3: Get Your API Key and Endpoint

You'll need your API key and endpoint to make requests to the service.

  1. In your Azure OpenAI resource, go to "Keys and Endpoint" under "Resource Management".
  2. 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.