Dropstone SDK 快速入門
安裝 Dropstone SDK、使用 API 金鑰進行無頭 API 呼叫,以及執行攜帶您帳戶記憶的本地代理程式工作階段。包含串流、結構化輸出,以及使用 OpenAI SDK 搭配 Dropstone。
兩個用戶端,兩個首次呼叫。選擇符合您程式碼執行環境的那一個;SDK 總覽說明了兩者的差異。
無頭:從任何地方呼叫
- 在您的儀表板中,於設定底下的API 金鑰建立一個 API 金鑰。它看起來像
dsk_live_...,而且只會顯示一次。 - 安裝 SDK:
npm install @blankline/dropstone-sdk。 - 將金鑰放入環境變數中,命名為
DROPSTONE_API_KEY。請像對待密碼一樣對待它:絕不提交,也絕不將它放入瀏覽器套件中。 - 呼叫它。用戶端會自行讀取環境變數。
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