Day 5 of 5
⏱ ~60 minutes
Azure in 5 Days — Day 5

Azure OpenAI

Provision Azure OpenAI, deploy GPT-4, call it from Python using the Azure SDK, and build a document summarization app.

Provisioning Azure OpenAI

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.

Azure Portal Steps
# 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 name
Python SDK
pip install openai
Call Azure OpenAI
from 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
)
Document Summarizer App
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()))
ℹ️
Azure OpenAI uses the same SDK as OpenAI — just replace the client instantiation. This means you can switch between the two with minimal code changes. Azure adds compliance, private networking (VNet integration), and enterprise SLAs.
📝 Day 5 Exercise
Build a Document Summarizer
  1. P
  2. r
  3. o
  4. v
  5. i
  6. s
  7. i
  8. o
  9. n
  10. A
  11. z
  12. u
  13. r
  14. e
  15. O
  16. p
  17. e
  18. n
  19. A
  20. I
  21. (
  22. o
  23. r
  24. u
  25. s
  26. e
  27. t
  28. h
  29. e
  30. O
  31. p
  32. e
  33. n
  34. A
  35. I
  36. A
  37. P
  38. I
  39. i
  40. f
  41. a
  42. c
  43. c
  44. e
  45. s
  46. s
  47. i
  48. s
  49. p
  50. e
  51. n
  52. d
  53. i
  54. n
  55. g
  56. )
  57. .
  58. W
  59. r
  60. i
  61. t
  62. e
  63. a
  64. P
  65. y
  66. t
  67. h
  68. o
  69. n
  70. s
  71. c
  72. r
  73. i
  74. p
  75. t
  76. t
  77. h
  78. a
  79. t
  80. r
  81. e
  82. a
  83. d
  84. s
  85. a
  86. t
  87. e
  88. x
  89. t
  90. f
  91. i
  92. l
  93. e
  94. a
  95. n
  96. d
  97. r
  98. e
  99. t
  100. u
  101. r
  102. n
  103. s
  104. a
  105. 5
  106. -
  107. b
  108. u
  109. l
  110. l
  111. e
  112. t
  113. s
  114. u
  115. m
  116. m
  117. a
  118. r
  119. y
  120. .
  121. S
  122. t
  123. o
  124. r
  125. e
  126. t
  127. h
  128. e
  129. A
  130. P
  131. I
  132. k
  133. e
  134. y
  135. a
  136. s
  137. a
  138. n
  139. e
  140. n
  141. v
  142. i
  143. r
  144. o
  145. n
  146. m
  147. e
  148. n
  149. t
  150. v
  151. a
  152. r
  153. i
  154. a
  155. b
  156. l
  157. e
  158. ,
  159. n
  160. o
  161. t
  162. i
  163. n
  164. c
  165. o
  166. d
  167. e
  168. .

Day 5 Summary

  • Azure OpenAI = same GPT-4 models, hosted in Azure, enterprise compliance included.
  • The Python SDK is identical to the OpenAI SDK. Just change the client instantiation.
  • Store credentials in environment variables. Never hardcode API keys in source code.
  • Azure OpenAI is the right choice for government and healthcare apps requiring FedRAMP/HIPAA.
Finished this lesson?