跳转到正文
文档导航: 决策模型 / 决策

决策

RightNow AI决策模型决策 更新于

本页内容

一次决策把你的状态与命名的问题配对,并以每个结果的名称返回该结果。

通过普通 HTTP,本页的问题类型和结果属于决策路径,适用于以 rnsk_ 开头的密钥。API 密钥页面上的密钥改为调用 POST /v1/decisions,它接受 noul、带 options 的 choice 和带 levels 的 score,并返回 noul,或带 confidence 和 probabilities 的 choice。见用你的密钥调用。

问题类型
Text
问题类型示意图。

根据你需要的答案选择 boolean、choice 或 score。

decide.ts
import { RightNowClient } from '@rightnowai/rightnow';

const client = new RightNowClient({
  apiKey: process.env.RIGHTNOW_API_KEY,
  baseURL: "https://api.rightnowai.co/v1",
});
const reply = await client.decide({
  "model": "rightnow-decision",
  "state": "The blender I ordered arrived with a cracked jar.",
  "questions": {
    "damaged": {
      "type": "boolean",
      "instructions": "Did the item arrive damaged?"
    }
  }
});
console.log(JSON.stringify(reply, null, 2));

// Set RIGHTNOW_API_KEY to your API key before running this example.
// Run this example on your server.
// SDK defaults: The default is 5 retries, also the maximum, with 150 seconds
// per attempt and a 60-second total retry budget. A single wait longer than 60
// seconds raises the last error.
// Use Retry-After-Ms, or Retry-After when milliseconds are absent. The wait is
// never shorter than a random backoff floor: a random fraction of 0.5 seconds
// doubled for each attempt, capped at 8 seconds.

状态

状态接受 JSON 对象、数组或字符串。嵌套的数字、布尔值和 null 仍保持为 JSON。请自行提供单位、坐标系和数据时效信息。

使用简短的键。需要精度时,把大整数和精确小数作为数字字符串发送。把应用数据放在状态中,把任务放在每个问题的 instructions 中。

普通 HTTP 的 decide 没有 state_version 或 sequence 字段。请在状态中保存你自己的序号或时间戳,并把每个响应与你发送的请求对应起来。

标准文本状态最多支持 38,000 个 token。完整的 JSON 请求,包括问题和附件,必须在 3,665,920 字节以内。 64k 和 128k 区间通过危险区域提供,需要发送 RightNow-Danger-Zone: long_context_64k 或 long_context_128k。 访问步骤和限制见危险区域。 token 限制并不保证序列化后的正文能放得下。问题和请求格式也计入渲染后的输入限制。

对于不断变化的状态,请使用流式传输。每次被接受的变更都会让 state_version 前进。使用答案前请检查每个决策的版本;更新的状态可能已经到达。

问题类型

类型用途结果
boolean是或否的决策。一个布尔决策以及为 true 的概率。
choice选择一个命名的选项。所选的选项以及每个选项的概率。
score给出一个有序的评级。一个期望等级、它的图例以及各等级的概率。

每个问题都有名称、type 和 instructions。instructions 必须是非空字符串,或非空的 JSON 对象或数组。

choice 使用 criteria 对象,score 使用有序的 criteria 数组。 在文本调用中,choice 接受 2 到 10 个选项,score 接受 2 到 4 个等级;带图像或音频时,为 2 到 26 个选项和 2 到 10 个等级。 把它们的数量保持在模型列表中的 limits.choice_options 和 limits.score_levels 之内;其他数量会返回 422 invalid_criteria。

criteria.json
JSON
{
  "model": "rightnow-decision",
  "state": "The blender arrived with a cracked jar and is needed before Saturday.",
  "questions": {
    "team": {
      "type": "choice",
      "instructions": "Which team should handle this ticket?",
      "criteria": {
        "replacements": "Ship a new item or part",
        "refunds": "Return money to the customer",
        "support": null
      }
    },
    "urgency": {
      "type": "score",
      "instructions": "How urgent is this ticket?",
      "criteria": [
        "Routine",
        "Priority",
        "Immediate"
      ]
    }
  }
}

结果

在 answers 中按问题名称读取每个结果。

读取响应中的 answers.damaged。对于 boolean,probability 是为 true 的可能性。当 true 至少与 false 一样可能时,decision 为 true;confidence 是所选结果的概率。

对于 choice,decision 等于 choice,confidence 是 probabilities[choice],即选项概率中的最大值。最大值并列时保留 choice。

对于 score,decision 是最可能等级的键字符串;并列时选择最低的等级。confidence 是该等级的概率;score 仍是期望等级的索引。

alternatives 以 { decision, confidence } 对象列出其他每个结果。条目按置信度从高到低排列;并列的选项按键的 UTF-8 字节顺序排列,并列的 score 等级按等级顺序排列。

calibration_version:一个不透明的公开标识符;未分配时为 unpublished。非空的标识符并不证明已校准。

在这个版本中 calibrated 为 false;有 calibration_version 值也不会让它变为 true。

旧的幂等重放保留其存储的答案结构。不要把旧的 confidence 当作决策概率。

使用请求策略时,低于你阈值的答案带有 abstained: true,并且没有 decision。

问题拒绝

被标记的问题可能返回错误,而其他问题照常得到回答。即使 HTTP 状态是 200,也要检查 answers 中的每一项。

refused-answer.json
JSON
{
  "error": {
    "code": "injection_suspected",
    "retryable": false
  }
}

如果每个问题都被标记,整个请求都会被拒绝。