跳转到内容

Day 1 · 认识你的 AI

本章目标:理解 LLM 的工作原理、使用方式和局限性。 产出:my-agent/llm.py — 你的 LLMClient 类。

你将学到

  • LLM 为什么具备智能(next-token prediction + 涌现)
  • Token 与向量:文本如何变成模型能处理的数字
  • 如何与 LLM 对话(messages 协议、三种角色)
  • Token 与上下文窗口:成本和约束
  • 大模型幻觉:成因、识别与缓解
  • 为什么需要给 LLM 配工具与上下文(Agent 的雏形)

内容结构

内容讲义Demo
1LLM 为什么具备智能01-why-llm-is-smartdemo_01_next_token.py
2提示词与角色02-prompts-and-rolesdemo_02_roles.py
3Token 与上下文窗口03-tokens-and-contextdemo_03_tokens.py
4大模型幻觉04-hallucinationdemo_04_hallucinate.py
5LLM + 外部支持05-llm-needs-augmentationdemo_05_with_tool.py

运行 Demo

bash
cd 01-meet-your-ai/lab
python demo_00_chat.py           # 最简交互式对话
python demo_01_next_token.py     # 看模型怎么"猜下一个词"
python demo_02_roles.py          # system prompt 改变模型人格
python demo_03_tokens.py         # tokenization + 成本估算
python demo_04_hallucinate.py    # 主动诱发幻觉
python demo_05_with_tool.py      # 加工具前后对比 + Function Calling 预告

今日产出

补全 my-agent/llm.py 中的 LLMClient 类,让测试通过:

bash
cd my-agent
python tests/test_llm.py

配套练习

exercises/01-meet-your-ai/ — 4 道代码填空题

Released under the MIT License.