本文来自《AI 应用开发课程》月份 1 课程文档,已整理为网站文章版本。
1. Python 与 uv
python3 --version
uv --version
uv init my_project
uv add httpx pydantic python-dotenv
uv add --dev pytest ruff
uv sync
uv run python main.py
uv run pytest
uv run ruff check .
2. Git
git status
git add .
git commit -m "feat: initialize month1 project"
git log --oneline -n 5
3. FastAPI
uv add fastapi uvicorn
uv run uvicorn app.main:app --reload
默认启动后访问:
http://127.0.0.1:8000/healthhttp://127.0.0.1:8000/docs
4. 测试与质量
uv run pytest -q
uv run ruff check .
uv run ruff format .
注意:
- 如果课程某处只要求检查格式,不要盲目运行格式化。
- 先看差异,再决定是否格式化。
5. 环境变量
cp .env.example .env
使用 Python 读取时,通常会在代码中调用:
from dotenv import load_dotenv
load_dotenv()
6. 常见调试动作
pwd
ls
tree
cat .env.example
uv run python -c "import os; print(os.getenv('DEEPSEEK_API_KEY'))"
7. API 调试建议
- 先在终端脚本中调通模型调用。
- 再把调用封装进 service。
- 最后再接入 CLI 或 FastAPI。
不要一开始就在框架里排所有问题。那会把错误来源混在一起。