OER·harvester

← Back to the library
GitHub CODE resource component · inferred

githubmodels-app.py

ComponentCode a lab works on: part of the labs, not a lesson of its own. Read it beside them, below.

Licence
OPEN MIT
Authors
Microsoft (microsoft)
Updated
2026-07-14 · GitHub
Language
—
Length
39 words

Material for these 3 labs

inferred
Open original ↗

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

import os
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage, UserMessage
from azure.core.credentials import AzureKeyCredential

# Get these from your Microsoft Foundry project's "Overview" page
# (GitHub Models is retiring end of July 2026 - see https://ai.azure.com/catalog/models)
token = os.environ["AZURE_INFERENCE_CREDENTIAL"]
endpoint = os.environ["AZURE_INFERENCE_ENDPOINT"]

model_name = "gpt-5-mini"

client = ChatCompletionsClient(
    endpoint=endpoint,
    credential=AzureKeyCredential(token),
)

prompt = "Show me 5 recipes for a dish with the following ingredients: chicken, potatoes, and carrots. Per recipe, list all the ingredients used"

response = client.complete(
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant.",
        },
        {
            "role": "user",
            "content": prompt,
        },
    ],
    model=model_name,
    # Note: gpt-5 reasoning models don't accept temperature/top_p; leave them at their defaults.
)

if response.choices and response.choices[0].message is not None:
    print(response.choices[0].message.content)