TS TypeSafe 文档中文版 原文 ↗

进阶:结构

Instructions、Choice 选项、Score 等级以及 Noul 的 criteria 都接受 JSON 结构。

System One 模型经过训练,能够理解结构。

哪些地方允许使用结构

下面每一个字段都是一个 EntryType。

字段 适用于 接受的形式
instructions Choice, Score, Noul string, object, array, or null
criteria 的值(选项描述) Choice string, object, array, or null
criteria 的条目(等级描述) Score string, object, array, or null
criteria.true 与 criteria.false Noul string, object, array, or null

何时该把问题结构化

  • 当它有助于清晰时。 当一个问題有多个部分时,把它们以 JSON 形式呈现有助于清晰,因为各个键都有标签。
  • 当问题需要支撑数据时。 一份 schema、一套分类法或一行数据库记录本身就已经是 JSON。直接整体使用这份 JSON,或传入相关的子字段,而不是把它们序列化进一个字符串模板。

结构化的 instructions

一个 field 对象描述被检查的字段,每个问题都通过键来引用它。同样的形态可以驱动一个校验某个值的 Noul、一个从候选中挑选其一的 Choice,以及两个把某个值放到刻度上的 Score。

request
{
  "state": {
    "source_text": "Invoice #4471 issued March 3, 2026 to Beaver Dam Logistics for $12,840.00, net 30."
  },
  "selectedModels": [
    "jev-latest"
  ],
  "questions": {
    "invoice_number_is_correct": {
      "type": "noul",
      "instructions": {
        "field": {
          "name": "invoice_number",
          "type": "string",
          "description": "The identifier printed on the invoice."
        },
        "extracted_value": "4471",
        "question": "Does `extracted_value` match the `field` as it appears in `source_text`?"
      }
    },
    "customer_name": {
      "type": "choice",
      "instructions": {
        "field": {
          "name": "customer_name",
          "type": "string",
          "description": "The organization the invoice was issued to."
        },
        "question": "Which option is the value of `field` in `source_text`?"
      },
      "criteria": {
        "Beaver Logistics": null,
        "Dam Logistics": null,
        "Beaver Dam Logistics": null,
        "Beaver": null,
        "Dam": null
      }
    },
    "amount_due": {
      "type": "score",
      "instructions": {
        "field": {
          "name": "amount_due",
          "type": "number",
          "unit": "USD",
          "description": "The total the invoice asks to be paid."
        },
        "question": "How large is the `field` value in `source_text`?"
      },
      "criteria": [
        "Under $1,000",
        "$1,000 to $10,000",
        "$10,000 to $100,000",
        "$100,000 to $1,000,000",
        "Over $1,000,000"
      ]
    },
    "payment_terms": {
      "type": "score",
      "instructions": {
        "field": {
          "name": "payment_terms",
          "type": "integer",
          "unit": "days",
          "description": "Days allowed for payment, from terms such as \"net 30\"."
        },
        "question": "How many days does the `field` in `source_text` allow for payment?"
      },
      "criteria": [
        "Due on receipt",
        "Net 10",
        "Net 30",
        "Net 60",
        "Net 90"
      ]
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。

在代码中,你可以遍历这些候选记录,为每个字段构造这样一个问题,并在一次调用中全部发送。SDE 级联实践手册 做了与此类似的事情。

数组同样可行。当 instruction 是一串需要检查或比较的事项时,就用数组:

json
"instructions": {
  "question": "Does the claimed sender identity conflict with the sending domain?",
  "compare": ["ticket.sender.display_name", "ticket.sender.email"],
  "focus": "Compare the named organization with the email domain."
}
 

结构化的 Choice 选项

Choice 的选项描述也可以是一个结构化对象。

用于澄清边界的 JSON 评分标准

request
{
  "state": "I ordered the standing desk two weeks ago and tracking still says label created. Was I even charged?",
  "selectedModels": [
    "jev-latest"
  ],
  "questions": {
    "department": {
      "type": "choice",
      "instructions": {
        "question": "Which team should handle this message?",
        "focus": "Classify the customer's primary request, not every topic mentioned."
      },
      "criteria": {
        "billing": {
          "what": "Charges, invoices, refunds, or subscriptions",
          "not_for": "Order tracking or account access",
          "examples": [
            "I was charged twice",
            "Where is my refund?"
          ]
        },
        "orders": {
          "what": "Order status, delivery, cancellation, or returns",
          "not_for": "Charges or account access",
          "examples": [
            "Where is my package?",
            "Cancel my order"
          ]
        },
        "account": {
          "what": "Login, password, profile, or security",
          "not_for": "Charges or delivery",
          "examples": [
            "I can't log in",
            "Change my email"
          ]
        }
      }
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。

这个例子告诉模型每个选项覆盖什么、不覆盖什么。它使选项之间的边界更清晰。

遍历分类法

要分类到很深的分类法中,就为每一层问一个 Choice,并在代码中遍历这棵树。每一步的选项是当前节点的子节点,每个选项的值是子节点的子树。这样模型在选定某个分支之前就能看到该分支下有什么,当条目所属的叶子名称无法仅从分支名看出来时,这一点很重要。

这里的 state 是一条商品信息,第一个问题挑选一个顶层部门。

request
{
  "state": "32oz plastic bottle with a flip straw lid. Fits most bike cages.",
  "selectedModels": [
    "jev-latest"
  ],
  "questions": {
    "department": {
      "type": "choice",
      "instructions": "Which top-level department does this product belong to?",
      "criteria": {
        "Sporting Goods": {
          "Cycling": [
            "Bike Bottles & Cages",
            "Bike Lights",
            "Helmets"
          ],
          "Fitness": [
            "Yoga Mats",
            "Resistance Bands"
          ],
          "Outdoor": [
            "Tents",
            "Sleeping Bags",
            "Hydration Packs"
          ]
        },
        "Home & Kitchen": {
          "Drinkware": [
            "Water Bottles",
            "Travel Mugs",
            "Tumblers"
          ],
          "Cookware": [
            "Pots & Pans",
            "Bakeware"
          ]
        },
        "Baby & Toddler": [
          "Sippy Cups",
          "Bottle Warmers",
          "Bibs"
        ]
      }
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。

这个瓶子可能同时适合两个部门。展示子树让模型看到 Sporting Goods > Cycling > Bike Bottles & Cages 和 Home & Kitchen > Drinkware > Water Bottles 都存在,并权衡这条信息中对自行车水壶架的侧重与日常饮水器皿之间的取舍。这个答案上的 probabilities 会告诉你,两者的差距是否小到需要同时探索两条分支。

一旦选定了某个部门,就用该部门的子节点作为选项、用它们的子树作为取值,提出下一个 Choice,如此重复直到抵达叶子。在代码中,这可以是对一个嵌套 dict 的循环,其中每个问题的 criteria 就是当前节点。层次分类实践手册 给出了类似遍历树的一个示例,其中包含在概率接近时保留多条候选路径的束搜索。

注意

子树可能变得很大。如果某个分支过大,就把取值裁剪为它的直接子节点以及一部分叶子样本。

结构化的 Score 等级

Score 的 criteria 数组中的每个条目都可以是一个对象。

request
{
  "state": "Fixed the null check in the payment handler. Also refactored the retry loop while I was in there, and bumped the SDK version since the old one had that timeout bug.",
  "selectedModels": [
    "jev-latest"
  ],
  "questions": {
    "pr_scope": {
      "type": "score",
      "instructions": {
        "question": "How focused is this pull request description on a single change?",
        "note": "Judge the number of independent changes, not the size of any one change."
      },
      "criteria": [
        {
          "summary": "One change, clearly stated",
          "signals": [
            "A single fix or feature",
            "Nothing described as \"also\" or \"while I was in there\""
          ]
        },
        {
          "summary": "One main change plus a small related tweak",
          "signals": [
            "A primary change and one minor adjacent edit",
            "The tweak supports the main change"
          ]
        },
        {
          "summary": "Several independent changes bundled together",
          "signals": [
            "Two or more unrelated fixes or features",
            "Changes that could each be their own PR"
          ]
        }
      ]
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。

结构化的 Noul criteria

Noul 的 criteria 是可选的;当是/否的边界很微妙时,结构化的 true 与 false 描述让你可以在两侧各用一个定义和若干示例把它确定下来。

request
{
  "state": {
    "sender": {
      "display_name": "Beaver Dam Builders Ltd.",
      "email": "donotreply@payroll.example"
    },
    "message": "Your Q3 bonus is ready. Reply with your login password so we can verify your identity and release the funds."
  },
  "selectedModels": [
    "jev-latest"
  ],
  "questions": {
    "requests_credentials": {
      "type": "noul",
      "instructions": {
        "question": "Does the `message` ask the recipient to disclose a sensitive credential?",
        "inspect": "message",
        "focus": "Look for a request to send the credential itself, not a request to change or reset it."
      },
      "criteria": {
        "true": {
          "what": "Asks the recipient to reply with, type, or send a password, PIN, one-time code, or other security sensitive answer",
          "examples": [
            "Reply with your password",
            "Send us the 6-digit code you just received"
          ]
        },
        "false": {
          "what": "No sensitive credential is requested",
          "examples": [
            "Reset your password from the settings page",
            "Your statement is ready"
          ]
        }
      }
    }
  }
}

这个示例是可交互的;到官网原页面可以直接在 Playground 里运行。