一字一诗 / 第 24 课 / 图 14
当前入口源码 + 本次帮助输出

最后,让 ./poet 成为可用的命令

启动脚本先找到自己所在的项目,再使用该项目的 Python 执行 poetry_gpt。

poet · 第 1—8 行(当前源码节选)

  1  #!/bin/sh
  2  # 与当前目录无关;始终使用这个项目的隔离环境。
  3  POET_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
  4  if [ ! -x "$POET_ROOT/.venv/bin/python" ]; then
  5    echo "还没有学习环境。请先运行:sh \"$POET_ROOT/scripts/setup.sh\"" >&2
  6    exit 1
  7  fi
  8  PYTHONPATH="$POET_ROOT${PYTHONPATH:+:$PYTHONPATH}" exec "$POET_ROOT/.venv/bin/python" -m poetry_gpt "$@"

pyproject.toml · 第 12—13 行(当前源码节选)

 12  [project.scripts]
 13  poet = "poetry_gpt.cli:main"

实际执行的命令

./poet --help

标准输出

usage: poet [-h] {doctor,prepare,train,write,chat,evaluate,lesson,course} ...

从一字到一首诗:本地古诗 GPT 学习工具

positional arguments:
  {doctor,prepare,train,write,chat,evaluate,lesson,course}
    doctor              检查环境、材料和模型
    prepare             整理诗词,生成训练材料
    train               从零训练,或继续已有进度
    write               按首字或关键词写诗
    chat                按中文提示连续写诗
    evaluate            在保留材料上检查预测误差
    lesson              运行某节课的小实验
    course              显示离线课程入口或启动本地阅读服务

options:
  -h, --help            show this help message and exit

执行结果

退出码 0 · 2026-09-19T00:56:02.778596+00:00