Provision Azure OpenAI, deploy GPT-4, call it from Python using the Azure SDK, and build a document summarization app.
Azure OpenAI is the enterprise version of OpenAI — same models, hosted in Azure, with compliance certifications (FedRAMP, SOC2, HIPAA). Access requires approval but is generally available now.
# 1. Search 'Azure OpenAI' in portal
# 2. Create resource in a supported region (East US, West Europe)
# 3. Go to Azure OpenAI Studio
# 4. Deployments → Create new deployment → Select gpt-4o
# 5. Note your: endpoint URL, API key, deployment namepip install openaifrom openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint='https://YOUR_RESOURCE.openai.azure.com/',
api_key='YOUR_API_KEY',
api_version='2024-02-01'
)
response = client.chat.completions.create(
model='gpt-4o', # your deployment name
messages=[
{'role': 'system', 'content': 'You are a helpful assistant that summarizes documents.'},
{'role': 'user', 'content': 'Summarize this in 3 bullet points: ' + document_text}
],
max_tokens=500
)import os
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint=os.environ['AZURE_OPENAI_ENDPOINT'],
api_key=os.environ['AZURE_OPENAI_KEY'],
api_version='2024-02-01'
)
def summarize(text: str) -> str:
response = client.chat.completions.create(
model=os.environ['AZURE_DEPLOYMENT_NAME'],
messages=[{
'role': 'user',
'content': f'Summarize this document in 5 bullet points:\n\n{text}'
}],
temperature=0.3
)
return response.choices[0].message.content
# Test it
with open('document.txt') as f:
print(summarize(f.read()))