Rho AI / LLM Guide

给做 AI 应用的开发者:让 LLM 可靠地生成 Rho format .md。 Rho 设计上就是 AI-friendly——但有些 prompt / schema / 修复模式能把准确率从 80% 拉到 99%+。


谁用这份 guide

  • ✅ AI 应用开发者:让 ChatGPT / Claude / Gemini / 自己 host 的 LLM 输出 Rho format 内容
  • ✅ prompt engineer:调 prompt 让 LLM 一发就对
  • ✅ 教育 AI / 学习平台:让 AI 直接生成可交互的解释
  • ✅ 数据科学 / 分析助手:让 AI 直接产出 chart + slider 的探索文档
  • ✅ 自动化文档系统:从结构化数据 → AI → Rho doc

为什么 Rho 适合 AI 生成

1. 语法紧凑 + 无歧义

\```interact
slider weight 40 120 70 1
template stl: [BMI] -> [{weight / (height * height):.1f}]
\```

跟"写个 React 组件含 useState、useEffect、Chart.js" 比,Rho 表达 token 数少 10-20 倍——LLM 出错率低 10-20 倍。

2. 结构在 markdown 内

LLM 训练时已学会海量 markdown。Rho 是 markdown 超集——LLM 默认的"写 markdown" 能力 + 几条 DSL 规则 = 直接能用。

3. 错误降级温和

LLM 生成的 Rho 即使错了,最坏显示为代码块字面量——读者依然能看到 LLM 的意图。不会像 React 那样错一个引号整个 page 白屏。

4. 安全设计 = 可放心 hosting

Rho 没有 eval、没有任意 JS、SVG 自动 sanitize——LLM 输出的内容直接 render 给读者也安全。不需要重型 sandbox。


这里有什么

Page 内容
Prompt templates 5+ 个 ready-to-use prompts 给常见生成场景
Schema-aware generation 喂 spec / function calling / JSON mode / 提升准确率
Common LLM mistakes & repair LLM 专属常见错误 + auto-fix patterns

已存在的文档(在 docs/ 根目录,本 guide 链接它们):

文档 作用
AINP 协议 — §21 单页速查表 全部围栏与 spec 行的单页汇总——适合直接贴进 prompt(英文)
AINP 协议 — §16 给 LLM 作者 生成纪律、失败恢复、何时不该用协议(英文)

这两份 LLM Protocol 是给 LLM 读 的(嵌进 prompt / system message / fine-tuning data),不是给人读的——它们紧凑到让 LLM 一次 absorb 所有约束。


三种 LLM 集成模式

模式 A:直接 prompt(最简)

把 LLM Protocol 的核心规则嵌进 system prompt:

You are a Rho format generator. Rho is markdown extended with:
- Callout: > [!INFO/WARN/ZEN]
- Layout: ```layout grid cols=N + :::card accent=color
- Interact: ```interact + slider/input/template
- ... (从 LLM Protocol 抽 ~50 行核心)

When the user requests interactive content, output Rho format.

适合:单模型 / 单一应用 / 试用阶段

详见 Prompt templates.

模式 B:Function / tool calling(精确)

定义一个 generate_rho_doc(...) function schema 让 LLM 调:

{
  "name": "generate_rho_doc",
  "description": "Generate a Rho format markdown document",
  "parameters": {
    "type": "object",
    "properties": {
      "title": {"type": "string"},
      "blocks": {
        "type": "array",
        "items": {
          "oneOf": [
            {"type": "object", "properties": {"type": {"const": "callout"}, "callout_type": {"enum": ["INFO", "WARN", "ZEN"]}, "body": {"type": "string"}}},
            {"type": "object", "properties": {"type": {"const": "interact"}, "controls": {...}, "template": {"type": "string"}}},
            ...
          ]
        }
      }
    }
  }
}

LLM 输出 JSON → 你 server 端转 Rho markdown。

适合:production 服务 / 严格质量控制 / 多模型抽象

详见 Schema-aware generation.

模式 C:fine-tune / few-shot(最高质量)

收集真实 Rho doc 样本 + 期望任务对,做:

  • few-shot examples 嵌进每次 prompt(最简)
  • 或对 base model 做 fine-tuning(最强但最贵)

适合:大规模 production / 特定垂直领域 / 商业产品


推荐起步路径

Step 1: 读 LLM Protocol (CN 或 EN)
   - 5 分钟,理解 Rho 语法约束
   - 决定哪些 capability 你的应用真要

Step 2: 试 mode A(直接 prompt)
   - 嵌 LLM Protocol 关键 50 行进 system message
   - 让 LLM 试生成 5 个测试场景
   - 看准确率

Step 3: 准确率不够?
   - 加 few-shot examples(mode C 入门)
   - 或换 mode B(function calling)

Step 4: 生产上线
   - 加 LLM 输出 → @rho/md 解析 校验环节
   - 不通过的 fallback 重新 prompt

最小可行 prompt(30 秒上手)

你是 Rho format 生成器。Rho 是 markdown 超集,含:

# Callout (强调段)
> [!INFO] | [!WARN] | [!ZEN]
> body...

# Interact (可交互)
\```interact
slider name min max initial step    (滑块)
input name "default"                 (文本输入)
select name "opt1" "opt2"           (下拉)
toggle name true                     (开关)
computed varName = expression        (派生值)
template stl:
  [label] -> [{var}]
  [label2] -> [{(expr):.2f}]
\```

# Layout (多列)
\```layout grid cols=N
:::card accent=blue
content
:::
\```

mini DSL: + - * / pow sqrt sin cos pi (不是 JS!)

任务:根据用户描述生成 Rho format markdown。

把这段塞进你的 LLM 的 system prompt → 立刻能生成基础 Rho 文档。


See also