结构化决策
POST /model/v1/systemone 调用决策模型(例如 jev-1.13)。你给出一份 state 和一组带类型的问题,它为每个问题返回概率:是/否的概率、每个选项的概率、或每一档的概率。它不生成文字,答案一定落在你给的选项里。请求与响应格式兼容 TypeSafe System One API;已用 TypeSafe SDK 的应用,把 base URL 换成 https://api.deepraxis.com/typesafe 即可,那个入口逐字照抄原格式。
适合同一个判断反复出现的地方:工单分诊、路由、打标签、审核放行、按条件筛选、打分排序。需要计算、计数、日期推算、多步推理或生成文字的任务,用对话模型。
1. 准备终端
将 Praxis API Key 放入环境变量 PRAXIS_API_KEY;获取方式见 Key 与鉴权。准备 Python 和 uv。
test -n "$PRAXIS_API_KEY"期望:退出码为 0。示例默认使用 https://api.deepraxis.com;切换环境时,将 PRAXIS_API_BASE 设为相应 API 域名,不带末尾斜杠或 API 路径。
2. 一次调用问三个问题
保存为 decide.py,运行 uv run -q --no-project --with requests python decide.py。
import osimport requests
base = os.environ.get('PRAXIS_API_BASE', 'https://api.deepraxis.com')resp = requests.post(f'{base}/model/v1/systemone', headers={'Authorization': f"Bearer {os.environ['PRAXIS_API_KEY']}"}, json={ 'model': 'jev-1.13', 'state': {'subject': 'Charged twice', 'message': 'My card was charged twice for the annual plan. Please refund the extra charge today.'}, 'questions': { 'team': {'type': 'choice', 'instructions': 'Which team should handle this ticket', 'criteria': {'billing': 'Charges, invoices, refunds', 'technical': 'Errors, outages, broken features', 'other': 'None of these'}}, 'urgency': {'type': 'score', 'instructions': 'How urgent the request is', 'criteria': ['No time pressure', 'Wants action soon', 'Wants action today']}, 'refund': {'type': 'noul', 'instructions': 'The customer is asking for money back'}, }, })resp.raise_for_status()answers = resp.json()['answers']team = answers['team']assert team['choice'] in ('billing', 'technical', 'other')assert abs(sum(team['probabilities'].values()) - 1) < 0.01refund = answers['refund']['noul']route = 'refund-desk' if refund >= 0.7 else 'person' if refund > 0.3 else 'queue'print(team['choice'], round(team['probabilities'][team['choice']], 2), answers['urgency']['score'], refund, route)期望:输出 billing 1 2 0.99 refund-desk(概率可能有小幅差异),退出码为 0。三个问题共用一份 state,并行作答,按一次读取计费。
3. 三种题型
| 题型 | 用于 | 请求字段 | 答案 |
|---|---|---|---|
noul | 一个是/否陈述 | instructions;可选 criteria: { true, false } 说明「是」与「否」各指什么 | noul:陈述为真的概率 |
choice | 在固定选项里选一个(最多 255 个) | criteria:选项名 → 描述 | choice、每个选项的 probabilities、confidence |
score | 在有序刻度上定位(最多 10 档) | criteria:从低到高的数组 | score、每一档的 probabilities、legend、confidence |
instructions 和每个描述都可以是字符串、对象或数组;两个选项容易混淆时,把描述写成对象,列出包含什么、不包含什么。图片定位(box)和图片输入(assets)暂不支持,传入返回 400。
4. 读答案、设阈值
- 最高选项的概率就是它答对的可能性,按它决定动作;
noul直接看noul。 confidence衡量概率分布有多集中,不代表答案正确,只作为第二个信号。noul起步阈值:≥ 0.7 为是,≤ 0.3 为否,中间交给人或其他流程。按出错的代价调整。- 判断交给模型,动作留在代码里:把「要不要升级」拆成几个可核对的事实问题,再在代码里组合。
5. 计费与限制
按输入 token 计费,输出免费;价格见 模型目录 中 jev-1.13 的 pricing.input。自有面在 usage.cost 里返回本次实付金额(美元),兼容面只在响应头 X-Praxis-Cost-Usd 返回。上下文 32K token。模型未声明该协议时返回 404。
在工作流里,用内置动作 decide 做同样的判断,后续步骤按答案分支。