Skip to content

JEV 决策 (TypeSafe)

JEV 是 TypeSafe 的决策模型。你给它一段上下文(state)和一组带类型的问题(questions),它一次调用返回结构化答案:每个答案都带概率分布,而不是一段还要你自己解析的自由文本。适合工单路由、意图识别、内容审核、情绪打分这类判断与分类任务。

创建决策

POST https://ciyuanx.io/inference/jev/api/alpha/decisions

注意

这个端点不在 /v1 兼容层下,请求体也和 Chat Completions 不同,不能用 OpenAI SDK 直接调用,按下面的示例发普通 HTTP 请求即可。路径中的 alpha 表示接口仍处于早期阶段,字段可能调整。

bash
curl https://ciyuanx.io/inference/jev/api/alpha/decisions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "jev",
    "state": "Help! My payouts have been failing for 3 days.",
    "questions": {
      "is_urgent": {
        "type": "noul",
        "instructions": "Does this message convey urgency?",
        "criteria": {
          "true": "Explicitly time-sensitive",
          "false": "No urgency expressed"
        }
      },
      "department": {
        "type": "choice",
        "instructions": "Which team should handle this?",
        "criteria": {
          "billing": "Payments, invoicing, refunds",
          "technical": "Bugs, outages, integrations",
          "sales": "Pricing, upgrades, new accounts"
        }
      },
      "frustration": {
        "type": "score",
        "instructions": "How frustrated is the customer?",
        "criteria": ["Calm", "Frustrated", "Very angry"]
      }
    }
  }'
python
import requests

response = requests.post(
    "https://ciyuanx.io/inference/jev/api/alpha/decisions",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY",
    },
    json={
        "model": "jev",
        "state": "Help! My payouts have been failing for 3 days.",
        "questions": {
            "is_urgent": {
                "type": "noul",
                "instructions": "Does this message convey urgency?",
                "criteria": {
                    "true": "Explicitly time-sensitive",
                    "false": "No urgency expressed",
                },
            },
            "department": {
                "type": "choice",
                "instructions": "Which team should handle this?",
                "criteria": {
                    "billing": "Payments, invoicing, refunds",
                    "technical": "Bugs, outages, integrations",
                    "sales": "Pricing, upgrades, new accounts",
                },
            },
            "frustration": {
                "type": "score",
                "instructions": "How frustrated is the customer?",
                "criteria": ["Calm", "Frustrated", "Very angry"],
            },
        },
    },
)

answers = response.json()["answers"]
print(answers["department"]["choice"])  # billing
print(answers["frustration"]["score"])  # 1.04
print(answers["is_urgent"]["noul"])     # 0.95
typescript
const response = await fetch(
  "https://ciyuanx.io/inference/jev/api/alpha/decisions",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer YOUR_API_KEY",
    },
    body: JSON.stringify({
      model: "jev",
      state: "Help! My payouts have been failing for 3 days.",
      questions: {
        is_urgent: {
          type: "noul",
          instructions: "Does this message convey urgency?",
          criteria: {
            true: "Explicitly time-sensitive",
            false: "No urgency expressed",
          },
        },
        department: {
          type: "choice",
          instructions: "Which team should handle this?",
          criteria: {
            billing: "Payments, invoicing, refunds",
            technical: "Bugs, outages, integrations",
            sales: "Pricing, upgrades, new accounts",
          },
        },
        frustration: {
          type: "score",
          instructions: "How frustrated is the customer?",
          criteria: ["Calm", "Frustrated", "Very angry"],
        },
      },
    }),
  },
);

const { answers } = await response.json();
console.log(answers.department.choice); // billing
console.log(answers.frustration.score); // 1.04
console.log(answers.is_urgent.noul); // 0.95

请求参数

参数类型必需描述
modelstring模型 ID,填 jev;响应会返回实际使用的版本
statestring待判断的上下文文本,例如一条用户消息、一封邮件或一段会话记录
questionsobject问题集合。键由你自己定义,答案会用同样的键返回

questions 中每个问题的结构:

字段类型必需描述
typestring问题类型:noulchoicescore
instructionsstring用自然语言说明这道题要判断什么
criteriaobject 或 array判断标准,写法取决于 type

问题类型

noul — 是否判断

criteriatruefalse 两个键,分别描述「成立」和「不成立」的情形。

json
"is_urgent": {
  "type": "noul",
  "instructions": "Does this message convey urgency?",
  "criteria": {
    "true": "Explicitly time-sensitive",
    "false": "No urgency expressed"
  }
}

答案返回一个 noul 字段,是 0–1 的概率,表示条件成立的可能性(0.95 即「大概率紧急」)。这个类型不返回 confidence,概率本身就是强度。

choice — 单项选择

criteria 是「选项 → 该选项含义」的对象,模型从中挑一个。

json
"department": {
  "type": "choice",
  "instructions": "Which team should handle this?",
  "criteria": {
    "billing": "Payments, invoicing, refunds",
    "technical": "Bugs, outages, integrations",
    "sales": "Pricing, upgrades, new accounts"
  }
}

答案返回选中的 choice、所有选项的 probabilities,以及 confidence

score — 分档打分

criteria 是一个有序数组,下标就是分值:第 0 项对应 0 分,第 1 项对应 1 分,依此类推。

json
"frustration": {
  "type": "score",
  "instructions": "How frustrated is the customer?",
  "criteria": ["Calm", "Frustrated", "Very angry"]
}

答案返回连续的 score、把下标映射回档位文字的 legend、每一档的 probabilities,以及 confidencescore 是按概率加权的期望值,所以通常落在两档之间:示例中 0 × 0 + 1 × 0.96 + 2 × 0.04 = 1.04

响应

json
{
  "model": "typesafe/jev-1.13-20260917",
  "answers": {
    "department": {
      "type": "choice",
      "choice": "billing",
      "probabilities": {
        "technical": 0.11,
        "sales": 0,
        "billing": 0.89
      },
      "confidence": 0.83
    },
    "frustration": {
      "type": "score",
      "score": 1.04,
      "legend": {
        "0": "Calm",
        "1": "Frustrated",
        "2": "Very angry"
      },
      "probabilities": {
        "0": 0,
        "1": 0.96,
        "2": 0.04
      },
      "confidence": 0.95
    },
    "is_urgent": {
      "type": "noul",
      "noul": 0.95
    }
  },
  "usage": {
    "input_tokens": 427,
    "output_tokens": 73,
    "cost": 0.000017934
  },
  "id": "gen-dec-1789948229-FmHnDQNsDfVnwWsYaUP1",
  "provider": "TypeSafe"
}

响应字段

顶层字段:

字段类型描述
modelstring实际使用的模型版本,例如 typesafe/jev-1.13-20260917
answersobject答案集合,键与请求中的 questions 一一对应
usageobject本次调用的 token 用量与费用
idstring本次请求的唯一 ID,排查问题时提供给支持人员
providerstring实际服务商,此处为 TypeSafe

答案对象字段(按 type 区分):

字段出现在类型描述
type全部string与提问时的 type 一致
noulnoulnumber条件成立的概率,0–1
choicechoicestring选中的选项键
scorescorenumber概率加权后的分值,连续值
legendscoreobject下标 → 档位文字的映射
probabilitieschoicescoreobject各选项 / 各档位的概率,合计约为 1
confidencechoicescorenumber模型对该答案的置信度,0–1;与 probabilities 分开给出,不等于最大概率值

usage 字段:

字段类型描述
input_tokensinteger输入 token 数(state 与全部问题定义)
output_tokensinteger输出 token 数
costnumber本次调用的费用(美元)

最佳实践

把判断标准写进 criteria

  • instructions 说清楚要判断什么,criteria 说清楚每个结果的边界——把边界写细,比把 instructions 写长更有效
  • 问题的键名就是答案的键名,用 is_urgentdepartment 这类语义化命名,拿到响应可以直接取值入库

用概率做路由

  • 不要只看 choice,同时检查 confidenceprobabilities:低于阈值的转人工处理
  • score 是连续值,需要离散档位时按 probabilities 取最大项,或自行取整

合并请求

  • 同一段 state 上的多个问题放进一次请求,state 只发送和计费一次,比拆成多次调用更省 token

提示

答案按键返回,顺序不保证与提问顺序一致(上面的示例响应就重新排过序)。取值请用键名,不要依赖顺序。