Contents

Azure AI Foundry Demo

Azure AI Foundry Demo

azure-foundry is a small demo project exploring Azure AI Foundry — Microsoft’s platform for building, evaluating, and deploying AI applications. The project demonstrates how to connect to Azure-hosted models and build simple AI workflows using the Azure SDK.

What is Azure AI Foundry?

Azure AI Foundry brings together model deployment, prompt management, evaluation pipelines, and monitoring into a single platform. It supports Azure OpenAI models as well as models from the Azure model catalog (Meta Llama, Mistral, Phi, etc.).

Project Setup

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

endpoint = os.environ["AZURE_AI_ENDPOINT"]
api_key = os.environ["AZURE_AI_API_KEY"]
model_name = os.environ.get("AZURE_AI_MODEL", "gpt-4o")

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

Basic Chat Completion

def chat(user_message: str, system_prompt: str = "You are a helpful assistant.") -> str:
    response = client.complete(
        messages=[
            SystemMessage(content=system_prompt),
            UserMessage(content=user_message),
        ],
        model=model_name,
        temperature=0.7,
        max_tokens=1024,
    )
    return response.choices[0].message.content

Streaming Responses

def chat_stream(user_message: str):
    stream = client.complete(
        messages=[UserMessage(content=user_message)],
        model=model_name,
        stream=True,
    )
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="", flush=True)
    print()

Configuration via Environment

# .env
AZURE_AI_ENDPOINT=https://<your-hub>.services.ai.azure.com/models
AZURE_AI_API_KEY=<your-key>
AZURE_AI_MODEL=gpt-4o

Key Takeaways

  • Azure AI Foundry abstracts model access through a unified endpoint, making it easy to swap models
  • The azure-ai-inference SDK provides a clean Python interface consistent across model providers
  • Streaming works out of the box with the same client
  • Azure’s managed infrastructure handles scaling and compliance requirements

Source: GitHub