OER·harvester

← Back to the library
GitHub NOTEBOOK resource

Aoai Assigment Simple

Repository 21 Lessons, Get Started Building with Generative AI

Licence
OPEN MIT
Authors
Microsoft (microsoft)
Updated
2026-07-16 · GitHub
Language
en
Length
125 words
Open original ↗
{ }
Jupyter notebook Converted to a read-only view · code is not executed

Source: Aoai Assigment Simple · GitHub · microsoft/generative-ai-for-beginners Authors: Microsoft (microsoft) Licence: MIT — https://spdx.org/licenses/MIT.html

In [1]
import os
from openai import OpenAI

API_KEY = os.getenv("AZURE_OPENAI_API_KEY","").strip()
assert API_KEY, "ERROR: Azure OpenAI Key is missing"

RESOURCE_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT","").strip()
assert RESOURCE_ENDPOINT, "ERROR: Azure OpenAI Endpoint is missing"
assert "openai.azure.com" in RESOURCE_ENDPOINT.lower(), "ERROR: Azure OpenAI Endpoint should be in the form: \n\n\t<your unique endpoint identifier>.openai.azure.com"

deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT", "").strip()
assert deployment, "ERROR: Azure OpenAI Deployment name is missing"

# The OpenAI client points at the Azure OpenAI (Microsoft Foundry) /openai/v1/ endpoint
# for the Responses API - no api_version needed.
client = OpenAI(
    api_key=API_KEY,
    base_url=f"{RESOURCE_ENDPOINT.rstrip('/')}/openai/v1/",
)
In [2]
# Create your first prompt
text_prompt = " My foot hurts, what can be wrong?"

response = client.responses.create(
  model=deployment,
  input = [
      {"role":"system", "content":"I'm a doctor, specialist on surgery"},
      {"role":"user","content":text_prompt},],
  store=False,)


response.output_text

Disclaimer: This document has been translated using AI translation service Co-op Translator. While we strive for accuracy, please be aware that automated translations may contain errors or inaccuracies. The original document in its native language should be considered the authoritative source. For critical information, professional human translation is recommended. We are not liable for any misunderstandings or misinterpretations arising from the use of this translation.