Jev 粉皮书
实战篇6

第 6 课 · 第一段可以落地的代码与 Agent 技能接入

模块实战篇预计学习12 分钟难度

🎯 学完这一课,你将能够

  • 使用标准的 HTTP API 写出第一段可落地的 Jev 生产调用代码
  • 熟练解析返回对象中的 answers 结构体及各子字段
  • 将 Jev 的判定结果无缝串联进企业现有的业务 if 分支中
  • 掌握在 Codex / Claude Code 等 Agent 中通过 TypeSafe Skill 进行工具调度的四步法

第一段可以落地的代码

在 Playground 验证完题目后,我们就可以通过代码正式发起 API 调取了。

连接状态、允许的动作和本人处理的步骤分别检查。

接口地址:POST https://api.typesafe.ai/v1/systemone 认证方式:Authorization: Bearer YOUR_API_KEY

环境变量优先

切记千万不要将 API Key 硬编码在代码文件里提交进 Git 仓库!先设置环境变量:

bash
export TYPESAFE_API_KEY="ts_live_your_actual_key_here"

完整 Node.js / TypeScript 调用范例

javascript
// jev-service.mjs
import fetch from 'node-fetch';

async function classifyCustomerTicket(rawMessage) {
  const apiKey = process.env.TYPESAFE_API_KEY;
  if (!apiKey) {
    throw new Error('未检测到 TYPESAFE_API_KEY 环境变量');
  }

  const payload = {
    model: 'jev-latest',
    state: rawMessage,
    questions: {
      is_urgent: {
        type: 'noul',
        instructions: '这条消息是否明确催促必须马上处理?'
      },
      department: {
        type: 'choice',
        instructions: '根据内容陈述,该问题属于哪个团队的职责?',
        criteria: {
          billing: '付款、扣费、重复扣款、发票、退费',
          technical: '系统故障、连不上、Bug 报错、崩溃',
          sales: '价格咨询、企业套餐购买、商务合作'
        }
      },
      frustration: {
        type: 'score',
        instructions: '评估客户的不满与沮丧程度:',
        criteria: [
          '冷静陈述事实',
          '稍有不满但礼貌',
          '极度愤怒,用词激烈'
        ]
      }
    }
  };

  const response = await fetch('https://api.typesafe.ai/v1/systemone', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(payload)
  });

  if (!response.ok) {
    const errorText = await response.text();
    throw new Error(`Jev API 错误 [${response.status}]: ${errorText}`);
  }

  const result = await response.json();
  return result.answers;
}

读懂 Answers 结构并串联业务

模型返回的 JSON 对象中,最核心的字段就是 answers:

javascript
// 假设 result.answers 的结构如下:
// {
//   is_urgent: { noul: 0.88 },
//   department: { choice: 'billing', confidence: 0.94, probabilities: { billing: 0.94, technical: 0.04, sales: 0.02 } },
//   frustration: { score: 2.3 }
// }

// 业务路由分发伪代码:
const { is_urgent, department, frustration } = answers;

if (is_urgent.noul > 0.8 && department.choice === 'billing') {
  // 紧急账单纠纷:直接分配给值班财务主管
  await assignToPriorityQueue(ticketId, 'financial_supervisor');
} else if (department.confidence > 0.9) {
  // 把握极高:直接自动派发给对应组
  await routeTicket(ticketId, department.choice);
} else {
  // 把握不够明确:分流至大模型复核或人工前台
  await sendToReviewQueue(ticketId, {
    suggested: department.choice,
    confidence: department.confidence
  });
}

让 Agent 调度 Jev:四步技能接入

除了由后端代码直接发起 HTTP 请求,社区还流行在 Codex 或 Claude Code 这类高级智能体中,把 Jev 当作专用的快速判断工具(Skill)调用:

  1. 第一步:官网申请通过,获得 API 访问权限;
  2. 第二步:安装 TypeSafe 官方技能包:

``bash npx skills add typesafe-ai/skills --skill typesafe-ai ``

  1. 第三步:配置 Key:在本地环境或 .env 中写入 TYPESAFE_API_KEY;
  2. 第四步:编写 Prompt:在向 Agent 发出指令时加入提示词:

> *“遇到复杂的分类判断或选项分流时,请优先使用 TypeSafe skill 调用 Jev 模型完成类型判定,避免大模型幻觉。”*


✍️ 动手练习

1. 将上面的 Node.js 代码保存为 test-jev.mjs; 2. 配置自己的 API Key 并运行一次,观察控制台打印的 answers 结构; 3. 在代码末尾尝试增加一个打印语句,输出当前请求消耗的时间(毫秒数),感受 Jev 的快判定速度。


📌 一句话带走

Jev 只负责公正判决,后续的业务动作由你的 if 语句来裁决。

学完后记得保存进度

完成标记保存在当前浏览器;登录后,会记住上次阅读的章节与位置。