Dropstone SDK 快速入门
安装 Dropstone SDK,使用 API 密钥进行无头 API 调用,并运行携带您账户记忆的本地代理会话。包括流式输出、结构化输出,以及使用 OpenAI SDK 对接 Dropstone。
两个客户端,两次首次调用。选择与您代码运行环境匹配的那个;SDK 概览解释了二者的区别。
无头模式:从任何地方发起调用
- 在您的 仪表盘 中,进入 设置,在 API 密钥 下创建一个 API 密钥。它看起来像
dsk_live_...,并且只显示一次。 - 安装 SDK:
npm install @blankline/dropstone-sdk。 - 将密钥放入环境变量中,命名为
DROPSTONE_API_KEY。像对待密码一样对待它:切勿提交到版本库,也切勿将其打包进浏览器 bundle。 - 发起调用。客户端会自动读取环境变量。
import { createDropstoneApi } from "@blankline/dropstone-sdk"
const dropstone = createDropstoneApi()
const resp = await dropstone.chat.completions.create({
model: "dropstone-fast",
messages: [{ role: "user", content: "Summarise this changelog entry." }],
})
console.log(resp.choices[0].message.content)
添加 stream: true,同样的调用将返回一个异步的块迭代器,这正是您在 UI 或长回答中需要的:
const stream = await dropstone.chat.completions.create({
model: "dropstone-fast",
stream: true,
messages: [{ role: "user", content: "Count to five." }],
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "")
}
该端点与 OpenAI 兼容,因此现有的客户端只需指向 Dropstone 即可使用:
import OpenAI from "openai"
const openai = new OpenAI({
baseURL: "https://api.dropstone.io/api/v1",
apiKey: process.env.DROPSTONE_API_KEY,
})
API 密钥请求按使用量从您的信用余额中计费,而非从套餐配额中扣除;余额为空的密钥会被拒绝,并附带充值链接。请参阅 将 API 与您的套餐一起使用。
本地模式:代理运行在您的进程中
本地客户端会启动一个 dropstone serve 进程,向您提供一个指向它的类型化客户端,并在您完成后将其关闭。由于它以您的账户身份运行,会话会携带您的记忆。
- 安装 Dropstone CLI 并使用
dropstone login登录。SDK 会读取相同的登录状态。 - 创建一个会话,然后向它发送提示。
import { createDropstone } from "@blankline/dropstone-sdk"
const { client, server } = await createDropstone()
const session = await client.session.create({
body: { agent: "build", model: { providerID: "dropstone", modelID: "dropstone-pro" } },
})
const reply = await client.session.prompt({
path: { id: session.data.id },
body: { parts: [{ type: "text", text: "Hello, who are you?" }] },
})
console.log(reply.data)
await server.close()
如果服务器已经在运行,可以跳过启动步骤:
import { createDropstoneClient } from "@blankline/dropstone-sdk"
const client = createDropstoneClient({ baseUrl: "http://127.0.0.1:4096" })
提示
- 固定版本范围。 SDK 发布节奏很快,因此请依赖您已测试过的版本范围,而不是最新的标签。
- 新代码使用 v2。
@blankline/dropstone-sdk/v2是新端点落地的表面;v1 保留给现有集成。 - 将流水线的学习内容排除在您自己的记忆之外。 无头调用不附带任何记忆,而本地会话使用您登录的账户。如果某个集成需要自己的记忆,请为它单独创建一个账户。请参阅 每个表面共享一份记忆。
限制
- 本地客户端需要 CLI 位于同一台机器上;没有 CLI 的主机应使用无头客户端。
- 无头端点是聊天补全。代理循环、文件操作和工作区工具位于本地客户端上。
Related articles
- Dropstone SDKA typed TypeScript and JavaScript client for the Dropstone agent, with two entry points: one for headless API calls from CI or a serverless function, one that runs the agent locally with the same account memory as the CLI and Chat.
- Using the API with your planCall Dropstone over HTTP with an API key. The endpoint is OpenAI-compatible, billed pay-per-use from your credit balance, and works from any language. Keys, errors, rate limits, and what the API does not carry.
- One memory across every surfaceThe account memory that follows you across Dropstone Chat, the CLI, and the SDK, what shares it and what does not, and how to keep an integration's learning out of your own memory.
- Install the CLIInstall the Dropstone CLI on macOS, Linux, or Windows with one command, sign in, and check it works. Upgrading and uninstalling.
- How to get supportHow to reach Dropstone support, what to include so we can help quickly, and the right address for billing, privacy, security, and enterprise questions.
Ctrl+I