🛡️TypeSafe 中文文档
原文档 ↗

JavaScript SDK

用于 TypeSafe AI 的 JavaScript 和 TypeScript SDK。

快速开始

安装 SDK(需要 Node.js 20 或更新版本):

sh
npm install @typesafe-ai/sdk

在环境中设置 TYPESAFE_API_KEY,然后创建并使用客户端:

ts
import { choice, TypeSafeClient } from "@typesafe-ai/sdk";

const client = new TypeSafeClient();
const response = await client.systemOne({
  state: { document: "I was charged twice. Please fix this ASAP." },
  questions: {
    category: choice("What is this ticket about?", {
      billing: null,
      technical: null,
      other: null,
    }),
  },
});

console.log(response.answers.category.choice);

答案类型会根据你定义的问题自动推断。该软件包包含 ESM、CommonJS 和 TypeScript 声明文件。

文档

在 TypeSafe 文档中了解 TypeSafe 能做什么。 查看 SDK 的 client 和 types 了解 API 选项与默认值。

本站为 docs.typesafe.ai 的中文翻译,仅供学习参考;内容版权归原作者所有。