Skip to content

pamelafox/python-stack-foundry-models

Repository files navigation

Python Stack for Foundry Models

Open in GitHub Codespaces Open in Dev Containers

This repository contains samples showing different Python stacks for building on top of multiple Microsoft Foundry models (OpenAI, Claude, etc). Each example demonstrates the same task — calling a Foundry-hosted model — using a different Python SDK or framework.

Getting started

You have a few options for getting started with this repository. The quickest way to get started is GitHub Codespaces, since it will setup everything for you, but you can also set it up locally.

GitHub Codespaces

You can run this repository virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:

  1. Open the repository (this may take several minutes):

    Open in GitHub Codespaces

  2. Open a terminal window

  3. Continue with the steps to run the examples

VS Code Dev Containers

A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:

  1. Start Docker Desktop (install it if not already installed)

  2. Open the project:

    Open in Dev Containers

  3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.

  4. Continue with the steps to run the examples

Local environment

  1. Make sure the following tools are installed:

  2. Clone the repository:

    git clone https://github.com/pamelafox/python-stack-foundry-models
    cd python-stack-foundry-models
  3. Install the dependencies:

    uv sync

Deploying Foundry models

All examples use models hosted on Microsoft Foundry. The project includes infrastructure as code (IaC) to provision OpenAI and Claude deployments. The IaC is defined in the infra directory and uses the Azure Developer CLI to provision the resources.

  1. Make sure the Azure Developer CLI (azd) is installed.

  2. Login to Azure:

    azd auth login

    For GitHub Codespaces users, if the previous command fails, try:

     azd auth login --use-device-code

    If you are using a tenant besides the default tenant, you may need to also login with Azure CLI to that tenant:

    az login --tenant your-tenant-id
  3. Provision the Foundry resources:

    azd provision

    It will prompt you to provide an azd environment name (like "stack-demos"), select a subscription from your Azure account, and select a location. Then it will provision the resources in your account.

  4. Once the resources are provisioned, you should now see a local .env file with all the environment variables needed to run the scripts.

  5. To delete the resources, run:

    azd down

Running the Python examples

You can run the examples in this repository by executing the scripts in the examples directory. Each example demonstrates calling Foundry models using a different Python stack.

Example Description
openai_responses.py Calling a Foundry-hosted OpenAI model using the OpenAI Python SDK (Responses API).
anthropic_messages.py Calling a Foundry-hosted Claude model using the Anthropic Python SDK (Messages API).
litellm_swap.py Calling either OpenAI or Claude models via LiteLLM, a unified interface that abstracts provider differences.
pydanticai_agent.py Building an agent with tools using PydanticAI, configured for either OpenAI or Claude on Foundry.
langchain_agent.py Building an agent with tools using LangChain, configured for either OpenAI or Claude on Foundry.
agentframework_agent.py Building an agent with tools using Microsoft Agent Framework, configured for either OpenAI or Claude on Foundry.

Run any example with:

uv run examples/<example_name>.py

Resources

About

For AIE talk

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors