Lab 013: Free LLM Backends β Foundry Local and OllamaΒΆ
Why this lab changed
GitHub Models inference was retired on July 30, 2026. This lab now provides the shared free backend used by the hub: Foundry Local on supported Windows devices or Ollama on Windows, macOS, and Linux.
What You'll LearnΒΆ
- Choose between Foundry Local and Ollama
- Start an OpenAI-compatible local endpoint
- Call a local chat model from Python
- Configure the environment variables used by other labs
- Verify that no prompts or data leave your machine
Choose a RuntimeΒΆ
Best for supported Windows devices and DirectML acceleration.
Cross-platform and easy to use on Windows, macOS, and Linux.
- Install Ollama.
- Start a small model:
Configure the shared endpoint:
Supporting FilesΒΆ
| File | Description | Download |
|---|---|---|
requirements.txt |
Python dependency | Download |
starter.py |
Local-backend exercises | Download |
Exercise 1 β Verify the EndpointΒΆ
Install the client and run the starter:
The OpenAI SDK accepts both runtimes because they expose an OpenAI-compatible API:
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["LOCAL_LLM_BASE_URL"],
api_key="local",
)
response = client.chat.completions.create(
model=os.environ["LOCAL_LLM_MODEL"],
messages=[{"role": "user", "content": "Explain MCP in two sentences."}],
)
print(response.choices[0].message.content)
Exercise 2 β Confirm Local ProcessingΒΆ
- Disconnect from the internet after the model download completes.
- Run
python starter.pyagain. - Confirm the response still succeeds.
- Stop the runtime and confirm the script reports a connection error rather than silently switching to a cloud service.
Shared Configuration for Other LabsΒΆ
The migrated labs use these variables:
| Variable | Example | Purpose |
|---|---|---|
LOCAL_LLM_BASE_URL |
http://localhost:11434/v1 |
OpenAI-compatible endpoint |
LOCAL_LLM_MODEL |
phi4-mini |
Installed chat model |
LOCAL_EMBEDDING_MODEL |
Runtime-specific | Optional embedding model |
Model capabilities vary
Tool calling, structured output, embeddings, and context limits depend on the selected model and runtime. Each lab lists the capabilities it requires.
Knowledge CheckΒΆ
Why do the labs use environment variables instead of hardcoding the endpoint?
They let the same code work with Foundry Local, Ollama, or a documented paid backend without rewriting the exercise.
Does the OpenAI SDK mean the request is sent to OpenAI?
No. The SDK is only the client library. base_url determines where the request is sent.
Next StepsΒΆ
Supporting kitΒΆ
The site build generates stable PDF and ZIP downloads. The ZIP contains the lab guide and every supporting file declared for this lab.