JavaScript SDKJavaScript 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 能做什么。 有关 API 选项和默认值,请参阅 SDK 的 client 和 types。