Choosing & Configuring an LLM Provider 🔑
Assignments may also be setup to work against one or more Large Language Model (LLM) deployments through a supported service provider like OpenAI, Azure or Hugging Face. These provide a hosted endpoint (API) that we can access programmatically with the right credentials (API key or token). In this course, we discuss these providers:
作业也可以配置成通过受支持的服务商(如 OpenAI、Azure 或 Hugging Face)调用一个或多个大语言模型(LLM)部署。这些服务商提供托管端点(API),凭正确的凭据(API key 或 token)即可用程序访问。本课程涉及以下服务商:
- OpenAI with diverse models including the core GPT series.
- Azure OpenAI for OpenAI models with enterprise readiness in focus
- Microsoft Foundry Models for a single endpoint and API key to access hundreds of models from OpenAI, Meta, Mistral, Cohere, Microsoft and more (replaces GitHub Models, which is retiring at the end of July 2026)
- Hugging Face for open-source models and inference server
- Foundry Local or Ollama if you'd rather run models fully offline on your own device, with no cloud subscription required
OpenAI:模型种类丰富,包括核心的 GPT 系列;Azure OpenAI:以企业级可用性为重点的 OpenAI 模型;Microsoft Foundry Models:一个端点、一个 API key 即可访问来自 OpenAI、Meta、Mistral、Cohere、微软等数百个模型(取代将于 2026 年 7 月底退役的 GitHub Models);Hugging Face:开源模型与推理服务器;Foundry Local 或 Ollama:适合希望完全离线、在自己设备上运行模型且不需要云订阅的场景。
You will need to use your own accounts for these exercises. Assignments are optional so you can choose to setup one, all - or none - of the providers based on your interests. Some guidance for signup:
这些练习需要使用你自己的账号。作业是可选的,你可以按兴趣配置其中一个、全部,或者一个都不配置。注册方面的说明如下:
| Signup | Cost | API Key | Playground | Comments |
|---|---|---|---|---|
| OpenAI | Pricing | Project-based | No-Code, Web | Multiple Models Available |
| Azure | Pricing | SDK Quickstart | Studio Quickstart | Must Apply Ahead For Access |
| Microsoft Foundry | Pricing | Project Overview page | Foundry Playground | Free tier available; one endpoint + key for many model providers |
| Hugging Face | Pricing | Access Tokens | Hugging Chat | Hugging Chat has limited models |
| Foundry Local | Free (runs on your device) | Not required | Local CLI/SDK | Fully offline, OpenAI-compatible endpoint |
Follow the directions below to configure this repository for use with different providers. Assignments that require a specific provider will contain one of these tags in their filename:
按下面的说明把本仓库配置成使用不同的服务商。需要特定服务商的作业,文件名里会带有以下标签之一:
aoai- requires Azure OpenAI endpoint, keyoai- requires OpenAI endpoint, keyhf- requires Hugging Face tokengithubmodels- requires Microsoft Foundry Models endpoint, key (GitHub Models is retiring at the end of July 2026)
aoai:需要 Azure OpenAI 的 endpoint 和 key;oai:需要 OpenAI 的 endpoint 和 key;hf:需要 Hugging Face token;githubmodels:需要 Microsoft Foundry Models 的 endpoint 和 key(GitHub Models 将于 2026 年 7 月底退役)。
You can configure one, none, or all providers. Related assignments will simply error out on missing credentials.
可以只配置一个、都不配置,或者全部配置。缺少凭据时,相关作业会直接报错。
Create .env file
We assume that you have already read the guidance above and signed up with the relevant provider, and obtained the required authentication credentials (API_KEY or token). In the case of Azure OpenAI, we assume you also have a valid deployment of an Azure OpenAI Service (endpoint) with at least one GPT model deployed for chat completion.
以下假定你已经读过上面的说明、注册了相应服务商,并取得所需的认证凭据(API_KEY 或 token)。若使用 Azure OpenAI,还假定你已经有一个可用的 Azure OpenAI Service 部署(endpoint),并至少部署了一个用于对话补全的 GPT 模型。
The next step is to configure your local environment variables as follows:
下一步是按如下方式配置本地环境变量:
- Look in the root folder for a
.env.copyfile that should have contents like this:
1. 在根目录里找到 .env.copy 文件,内容大致如下:
# OpenAI Provider
OPENAI_API_KEY='<add your OpenAI API key here>'
## Azure OpenAI in Microsoft Foundry
## (Azure OpenAI Service is now part of Microsoft Foundry: https://ai.azure.com)
AZURE_OPENAI_API_VERSION='2024-10-21' # Default is set! (current stable GA API version)
AZURE_OPENAI_API_KEY='<add your Foundry resource key here>'