POST /v1/decisions
问题类型 | 填写方式 | 说明 |
分类选择 | type=choice | 从给定候选项中选择一个类别,并返回候选项概率等信息。 |
有序评分 | type=score | 按给定的有序等级评估状态,返回分数等信息。 |
命题判断 | type=noul | 评估一个命题的成立程度,通常返回 0 - 1 的数值。 |
场景 | 推荐问题类型 | 接入方式 |
客服工单分流 | choice | 将工单作为 state,以团队标识为候选项,按 choice 分配处理团队。 |
用户意图分类 | choice | 给出清晰的意图候选项;需要承接未覆盖意图时,在 criteria 中显式定义其他类别。 |
工单紧急程度判断 | noul | 定义“需要优先处理”的含义,根据业务评测设定 noul 阈值。 |
情绪、满意度或优先级评估 | score | 使用有序 criteria 等级,结合 score、legend 和概率分布处理结果。 |
Agent 工作流条件判断 | choice / noul | 评估任务状态,决定后续处理分支或是否需要人工介入。 |
同一业务状态的多维评估 | 混合类型 | 一次提交多个带独立标识的问题,例如同时识别团队、不满程度和紧急程度。 |
cmr-decisions 作为示例逻辑模型名称,调用前请替换为控制台实际配置的名称。上游访问凭证由服务端配置,客户端使用 CMR API Key 调用。POST {CMR_BASE_URL}/v1/decisions
/v1/decisions,本文示例均使用该路径。Header | 必填 | 说明 |
Authorization | 是 | Bearer <CMR_API_KEY> |
Content-Type | 是 | 固定为 application/json |
curl --request POST "${CMR_BASE_URL}/v1/decisions" \\--header "Authorization: Bearer ${CMR_API_KEY}" \\--header "Content-Type: application/json" \\--data '{"model": "cmr-decisions","state": "我的提现已经连续失败三天,今天必须支付供应商货款,请尽快处理。","questions": {"is_urgent": {"type": "noul","instructions": "这条工单是否需要优先处理?"}}}'
import osimport requestsresponse = requests.post(f"{os.environ['CMR_BASE_URL'].rstrip('/')}/v1/decisions",headers={"Authorization": f"Bearer {os.environ['CMR_API_KEY']}","Content-Type": "application/json",},json={"model": "cmr-decisions","state": "我的提现已经连续失败三天,今天必须支付供应商货款,请尽快处理。","questions": {"is_urgent": {"type": "noul","instructions": "这条工单是否需要优先处理?",}},},timeout=30,)response.raise_for_status()result = response.json()print(result["answers"]["is_urgent"]["noul"])
参数 | 类型 | 必填 | 说明 |
model | string | 是 | CMR 逻辑模型名称或模型别名,可用值以当前实例配置为准。 |
state | string | object | array | 是 | 需要评估的文本、结构化业务数据或上下文列表;不接受 null、数字或布尔值作为顶层 state。 |
questions | object | 是 | 问题集合;键为业务自定义的问题标识,值为问题对象。 |
questions 的内部结构、问题类型、候选项数量以及 state 长度等限制由上游模型校验;网关接受顶层类型不代表上游一定接受整个请求。网关顶层校验本身不拒绝空字符串 state、空数组/对象 state 或空 questions;这些输入是否可用由上游决定。正常调用建议提交具有实际业务含义的状态与问题。参数 | 类型 | 必填 | 说明 |
questions.<question_id> | object | 是 | 一个问题;question_id 为自定义标识,如 department 或 is_urgent。 |
questions.<question_id>.type | string | 是 | 问题类型,常用值为 choice、score 或 noul。 |
questions.<question_id>.instructions | string;也可使用上游支持的 object / array | 是 | 问题说明、判断目标与规则;简单文本最便于接入。 |
questions.<question_id>.criteria | 依问题类型而定 | 按类型填写 | choice 通常为候选标识到说明的对象;score 通常为按顺序排列的等级数组;noul 可省略。 |
{"model": "cmr-decisions","state": "我的提现已经连续失败三天,请帮我检查支付账户。","questions": {"department": {"type": "choice","instructions": "这条工单应该交给哪个团队处理?","criteria": {"billing": "支付、账单、退款与提现问题","technical": "程序缺陷、服务故障与系统集成问题","sales": "产品咨询、采购与合同问题"}}}}
{"model": "cmr-decisions","state": "我已经反馈三次,问题仍然没有解决,这让我非常失望。","questions": {"frustration": {"type": "score","instructions": "评估客户的不满程度,按 criteria 从低到高评分。","criteria": ["情绪平静", "有些不满", "非常不满"]}}}
{"model": "cmr-decisions","state": "请立刻处理,今天必须完成付款。","questions": {"is_urgent": {"type": "noul","instructions": "文本是否表达了需要立即处理的紧急诉求?"}}}
{"model": "cmr-decisions","state": {"ticket": {"subject": "提现失败","message": "已经失败三天,今天必须付款,我非常不满。"},"history": [{"role": "customer", "text": "昨天也反馈过,仍未解决。"}]},"questions": {"department": {"type": "choice","instructions": "选择负责处理该工单的团队。","criteria": {"billing": "支付、账单与提现问题","technical": "程序缺陷与系统故障","sales": "采购与合同咨询"}},"frustration": {"type": "score","instructions": "按从低到高的等级评估客户不满程度。","criteria": ["情绪平静", "有些不满", "非常不满"]},"is_urgent": {"type": "noul","instructions": "是否需要优先处理?"}}}
{"model": "cmr-decisions","state": [{"role": "customer", "text": "提现失败了。"},{"role": "customer", "text": "已经三天了,今天必须付款。"}],"questions": {"is_urgent": {"type": "noul", "instructions": "结合上下文,是否需要优先处理?"}}}
参数 | 类型 | 是否一定返回 | 说明 |
id | string | 是 | 网关生成的请求追踪标识,格式为 dec- 加随机标识;不复用上游同名字段。 |
model | string | 是 | 协议翻译后保留的上游模型名称,可能为版本化名称;未返回有效名称时回退为逻辑模型名称,可能与请求中的 model 不同。 |
answers | object | 是 | 按问题标识组织的答案对象;通过 answers.<question_id> 对应请求中的问题。 |
usage | object | 否 | 归一化后的 Token 用量;上游未提供或翻译结果中没有 usage 时不返回。 |
参数 | 类型 | 是否一定返回 | 说明 |
answers.<question_id>.type | string | 依上游返回 | 通常为 choice。 |
answers.<question_id>.choice | string | 依上游返回 | 所选候选项标识,通常对应请求中 criteria 的一个键。 |
answers.<question_id>.probabilities | object | 依上游返回 | 候选项标识到概率的映射,概率通常在 0 - 1 之间。 |
answers.<question_id>.confidence | number | 依上游返回 | 模型返回的置信度,具体含义以模型协议为准。 |
参数 | 类型 | 是否一定返回 | 说明 |
answers.<question_id>.type | string | 依上游返回 | 通常为 score。 |
answers.<question_id>.score | number | 依上游返回 | 评分结果,可能为小数;取值范围和计算口径以所选模型为准。 |
answers.<question_id>.legend | object | 否 | 等级编号到等级说明的映射,常用字符串形式的 0、1、2 等作为键。 |
answers.<question_id>.probabilities | object | 否 | 等级编号到概率的映射。 |
answers.<question_id>.confidence | number | 否 | 模型返回的置信度。 |
参数 | 类型 | 是否一定返回 | 说明 |
answers.<question_id>.type | string | 依上游返回 | 通常为 noul。 |
answers.<question_id>.noul | number | 依上游返回 | 通常为 0 - 1 的命题成立程度;越大表示模型越倾向于认为命题成立。 |
参数 | 类型 | 是否一定返回 | 说明 |
usage.prompt_tokens | integer | usage 存在时返回 | 输入 Token 数;TypeSafe 内置规则将 input_tokens 映射至此字段。 |
usage.completion_tokens | integer | usage 存在时返回 | 输出 Token 数;TypeSafe 内置规则将 output_tokens 映射至此字段。 |
usage.total_tokens | integer | usage 存在时返回 | 总 Token 数;翻译结果未提供时按输入与输出 Token 数相加。 |
{"id": "dec-7f3a2c1059814a62acb350be36a4d119","model": "typesafe/jev-1.13","answers": {"is_urgent": {"type": "noul", "noul": 0.96}},"usage": {"prompt_tokens": 120,"completion_tokens": 18,"total_tokens": 138}}
{"id": "dec-a1b2c3d456784abca9c81234567890de","model": "typesafe/jev-1.13","answers": {"department": {"type": "choice","choice": "billing","probabilities": {"billing": 0.89, "technical": 0.10, "sales": 0.01},"confidence": 0.83},"frustration": {"type": "score","score": 1.8,"legend": {"0": "情绪平静", "1": "有些不满", "2": "非常不满"},"probabilities": {"0": 0.05, "1": 0.10, "2": 0.85},"confidence": 0.86},"is_urgent": {"type": "noul", "noul": 0.96}},"usage": {"prompt_tokens": 427,"completion_tokens": 73,"total_tokens": 500}}
{"id": "dec-9e8d7c6b54324d01aabbccddeeff0011","model": "typesafe/jev-1.13","answers": {"is_urgent": {"type": "noul", "noul": 0.78}}}
{"detail": {"code": "invalid_decisions_request","message": "Request does not match the CMR Decisions Standard","issues": [{"path": "/state", "reason": "missing"}]}}
参数 | 说明 |
detail.code | 校验错误标识;标准请求形状错误为 invalid_decisions_request |
detail.message | 错误概要 |
detail.issues[].path | 问题字段的 JSON Pointer 路径;请求根对象使用 / |
detail.issues[].reason | 原因,如 missing、object_required 或类型校验原因 |
{"error": {"message": "InternalServerError: {\\"error\\":\\"Upstream service is overloaded\\"}","type": null,"param": null,"code": "529"}}
参数 | 说明 |
error.message | 错误说明,可能包含经过处理的上游诊断信息。 |
error.type | 错误类型,可能为字符串或 null,随错误来源变化;不要假设始终为固定字符串。 |
error.param | 相关参数,无明确参数时可能为 null 或其他占位值。 |
error.code | 错误码,当前常见为字符串形式的 HTTP 状态码。 |
HTTP 状态码 | 常见场景 | 建议 |
400 | JSON 格式错误、请求体不是对象、必填字段缺失、标准字段类型错误、逻辑模型名称无效,或上游拒绝当前参数。 | 修正请求,不要盲目重试。 |
401 | 网关或上游鉴权失败,访问凭证无效或失效。 | 检查 CMR API Key 和上游凭证。 |
403 | 缺少必需的鉴权信息、鉴权头格式错误,或无权访问目标模型或接口;具体状态以鉴权配置为准。 | 检查 Authorization 和模型访问权限。 |
404 | 上游模型、资源或请求路径不存在。 | 检查上游模型及接口路径配置。 |
408 | 请求或上游调用超时。 | 结合业务时限决定是否重试。 |
422 | 上游拒绝 questions 内部结构、输入长度或其他模型约束。 | 按上游诊断修正参数;当前实现保留 422 状态码。 |
429 | 网关限流、上游配额超限或暂无可用部署。 | 结合 Retry-After(如存在)使用退避策略。 |
500 | 网关或上游内部错误,或连接上游失败。 | 记录请求标识并排查;按业务策略退避重试。 |
502 | 上游响应不是有效的预期协议结果,或协议翻译结果不满足响应契约。 | 检查上游与翻译配置,持续出现时联系支持人员。 |
503 | 协议翻译运行环境/配置不可用,或上游服务不可用。 | 检查服务与配置状态,恢复后重试。 |
504 | 上游网关超时。 | 结合业务时限决定是否重试。 |
529 | TypeSafe 上游过载。 | 当前实现保留 529,不统一改写为 500;可按临时故障退避重试。 |
文档反馈