typescript · 2026-09-23
TypeScript Jev 人工复核门控模板
使用 Jev 路由客服工单,并为低置信度结果保留人工复核分支。
适用场景
- 客服路由
- 线索筛选
- 内容分流
依赖与版本
- @typesafe-ai/sdk: verify current release before install
- Node.js 20+
预期行为
通过校验且置信度达到 0.8 的结果返回所选队列,低于阈值时返回 human_review。
失败处理
缺少凭证、请求重试耗尽或响应结构异常时会抛出错误,避免继续自动执行。
代码模板
import { choice, TypeSafeClient } from '@typesafe-ai/sdk';
const apiKey = process.env.TYPESAFE_API_KEY;
if (!apiKey) throw new Error('TYPESAFE_API_KEY is required');
const client = new TypeSafeClient({
apiKey,
timeout: 10_000,
retry: { maxRetries: 2 },
});
const result = await client.systemOne({
model: 'jev-latest',
state: {
ticket: 'I was charged twice. Please fix this ASAP.',
},
questions: {
route: choice('Choose the support queue.', {
billing: 'Payments, invoices, refunds, or duplicate charges',
technical: 'Product behavior, errors, or integrations',
other: 'Everything else',
}),
},
});
const decision = result.answers.route;
if (
typeof decision.choice !== 'string' ||
!Number.isFinite(decision.confidence) ||
decision.confidence < 0 ||
decision.confidence > 1
) {
throw new Error('Unexpected decision response');
}
const action = decision.confidence < 0.8 ? 'human_review' : decision.choice;
console.log({ action, confidence: decision.confidence, model: result.model });来源
示例会调用第三方服务。复制前请核对当前 API、依赖版本、费用、隐私要求和服务条款。