TS TypeSafe 文档中文版 原文 ↗

JavaScript SDK

TypeSafe AI 的 JavaScript 和 TypeScript SDK。

快速开始

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

bash
npm install @typesafe-ai/sdk
 

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

typescript
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 能做什么。 API 选项和默认值见该 SDK 的 client 与 types。