microsoft/generative-ai-for-beginners · 上手攻略
- 仓库:microsoft/generative-ai-for-beginners
- 链接:https://github.com/microsoft/generative-ai-for-beginners
- 分类:ai
- 作者:Tom
- 更新:2026-07-10
这是什么
微软官方出品的 21 节生成式 AI 入门课程,覆盖从 LLM 基础理论到 AI Agent 开发完整路径。每节包含讲解视频(YouTube)+ 文字课程 + Python/TypeScript 双语言代码示例,并配套 50+ 语言的社区翻译。Stars 约 112k,是微软 GitHub 最受欢迎的教育类仓库之一。
课程默认使用 Azure OpenAI Service 或 OpenAI API,但所有代码示例也兼容纯 OpenAI SDK,无需 Azure 账号也可完成大部分课程。
解决什么问题
生成式 AI 应用开发的学习资源要么太浅(只会调 API),要么太散(需要自己拼凑 prompt 工程、RAG、Agent 等知识点)。这门课的价值在于: - 体系完整:21 节从理论到生产,涵盖整个 GenAI 应用开发生命周期。 - 代码可跑:每个 Build 课都有完整可运行的 Python/TypeScript 示例。 - 微软官方背书:Azure OpenAI、Foundry Models 等企业级工具的正确打开方式。
快速安装
方式一:GitHub Codespaces(推荐,5 分钟上手)
无需本地配置,直接在浏览器里跑:
- Fork 本仓库到自己账户
- 在你的 fork 中:Code → Codespaces → Create new on main
- 在 Codespace 终端添加 API 密钥 Secrets:
- ⚙️ → Command Palette → Codespaces: Manage user secret
- 添加
OPENAI_API_KEY(或AZURE_INFERENCE_ENDPOINT+AZURE_INFERENCE_CREDENTIAL) - 开始 lesson 01
⚠️ GitHub Models(
GITHUB_TOKEN)将于 2026 年 7 月底停用,课程已改用 Microsoft Foundry Models 作为默认推理端点。
方式二:本地 Miniconda 环境
# 1. 安装 Miniconda(https://conda.io/en/latest/miniconda.html)
# 2. 克隆仓库(不含翻译文件以节省空间)
git clone --filter=blob:none --sparse https://github.com/microsoft/generative-ai-for-beginners.git
cd generative-ai-for-beginners
git sparse-checkout set --no-cone '/*' '!translations' '!translated_images'
# 3. 创建 conda 环境
conda env create --name ai4beg --file .devcontainer/environment.yml
conda activate ai4beg
# 4. 配置 API 密钥
# 方式 A:用 Azure Foundry(推荐)
echo "AZURE_INFERENCE_ENDPOINT=https://your-endpoint.azure.com" >> .env
echo "AZURE_INFERENCE_CREDENTIAL=your-api-key" >> .env
# 方式 B:用 OpenAI
echo "OPENAI_API_KEY=sk-..." >> .env
# 5. 安装 python-dotenv(课程代码依赖)
pip install python-dotenv
# 6. 启动 Jupyter 开始学习
jupyter notebook
方式三:VS Code + Dev Container
在 VS Code 中打开仓库后,会提示"Reopen in Container",接受即可自动配置完整开发环境(需 Docker)。
核心课程结构
课程分两类节次:Learn(概念讲解)+ Build(代码实战)。
| 编号 | 主题 | 类型 | 关键内容 |
|---|---|---|---|
| 00 | Course Setup | Setup | 环境配置、API 密钥、Codespaces |
| 01 | Introduction to Generative AI and LLMs | Learn | GenAI 基础、LLM 工作原理 |
| 02 | Exploring and Comparing Different LLMs | Learn | 模型选型、GPT-4/Gemini/Claude/LLaMA 对比 |
| 03 | Using Generative AI Responsibly | Learn | AI 安全、偏见识别、负责任 AI 原则 |
| 04 | Prompt Engineering Fundamentals | Learn | Few-shot、CoT、zero-shot 最佳实践 |
| 05 | Creating Advanced Prompts | Build | 复杂 prompt 技巧、输出控制 |
| 06 | Building Text Generation Applications | Build | Azure OpenAI / OpenAI API 调用示例 |
| 07 | Building Chat Applications | Build | Chat Completion API、多轮对话 |
| 08 | Building Search Apps with Embeddings | Build | 向量 Embedding、相似度搜索 |
| 09 | Building Image Generation Applications | Build | DALL-E API、图像生成 pipeline |
| 10 | Building Low Code AI Applications | Build | Azure AI Studio、Prompt Flow 等低代码工具 |
| 11 | Integrating External Applications with Function Calling | Build | Tool calling / Function calling 实战 |
| 12 | Designing UX for AI Applications | Learn | AI 产品 UX 设计原则 |
| 13 | Securing Your Generative AI Applications | Learn | API 安全、Prompt 注入防护、数据保护 |
| 14 | The Generative AI Application Lifecycle | Learn | LLMOps、模型评估、监控 |
| 15 | RAG and Vector Databases | Build | RAG 架构、ChromaDB/ Pinecone 集成 |
| 16 | Open Source Models and Hugging Face | Build | Hugging Face 部署开源模型 |
| 17 | AI Agents | Build | Agent 框架(LangChain/LlamaIndex 等) |
| 18 | Fine-Tuning LLMs | Learn | LoRA/QLoRA 微调概念与流程 |
| 19 | Building with SLMs | Learn | 小语言模型(Phi-3、Gemma 等)优势与场景 |
| 20 | Building with Mistral Models | Learn | Mistral 系列模型特性 |
| 21 | Building with Meta Models | Learn | Llama 3 系列特性与使用 |
典型适用场景
| 场景 | 推荐课时 |
|---|---|
| 刚入门 AI,不知从哪下手 | 01 → 04 → 06 |
| 想用 LLM 做产品,需要 RAG | 08 → 15 → 14 |
| 需要 AI Agent 能力 | 11 → 17 |
| 企业级 AI 应用安全负责人 | 03 → 13 → 14 |
| 想部署开源模型降成本 | 16 → 18 → 19 |
| 需要快速出原型 / POC | 10(低代码)→ 06 → 07 |
坑与注意
⚠️ API 密钥配置是必过的第一关
课程所有 Build 课都需要 API 调用。GitHub Models 2026 年 7 月底停用后,新用户必须注册 Microsoft Foundry Models(ai.azure.com/catalog/models)或 OpenAI 账号。如果只有 OpenAI key,用 OPENAI_API_KEY 环境变量即可,代码里两种方式都有示例。
⚠️ Codespaces 容器构建卡住
如果 Codespaces 容器首次构建超过 10 分钟没动静:Codespaces → Rebuid Container。常见原因:GitHub 账户缺额(免费账户有每月额度上限)。
⚠️ 翻译文件使仓库臃肿
直接 git clone 会拉取 50+ 语言翻译,占用数 GB。建议用 sparse checkout 排除 translations/ 目录(见上方命令)。
⚠️ 环境变量加载依赖 python-dotenv
课程代码使用 from dotenv import load_dotenv,需要 pip install python-dotenv,否则运行时代码会报 ModuleNotFoundError。
⚠️ 国内访问 Azure 区域限制
如果使用 Azure OpenAI 国内世纪互联区域(azure.cn),部分端点格式与全球版不同,课程代码需做 endpoint URL 适配。
⚠️ .NET 开发者另有专属课程
本课程是 Python/TypeScript 版,.NET 开发者应使用 microsoft/Generative-AI-for-beginners-dotnet。
与同类对比
| 课程 | 定位 | 优势 | 劣势 |
|---|---|---|---|
| 微软 GenAI for Beginners | 官方入门课 | 体系完整、代码可跑、Azure 原生 | 默认 Azure,OpenAI 用户需自行适配 |
| DeepLearning.AI Short Courses | OpenAI 官方课 | 短小精悍、Andrew Ng 背书 | 深度有限,主题分散不成体系 |
| Google ML Crash Course | 通用机器学习 | 免费、覆盖面广 | 不是专门针对 GenAI 应用开发 |
| LlamaIndex / LangChain 官方文档 | 框架文档 | 最新、权威 | 不是课程形式,需要自学能力 |
一句话推荐结论
零基础想体系化学 GenAI 应用开发,首选这门微软官方课——21 节从理论到代码全覆盖,Codespaces 免配置可直接开跑,Python/TypeScript 双语言示例,总有一款适合你。