インストールして最初のセッションを実行する
Dropstone SDKをインストールし、APIキーでヘッドレスAPI呼び出しを行い、アカウントのメモリを保持するローカルエージェントセッションを実行します。ストリーミング、構造化出力、OpenAI SDKをDropstoneに対して使用する方法も含みます。
2つのクライアント、2つの最初の呼び出し。コードが実行される場所に合う方を選んでください。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は既存の統合用に残ります。 - パイプラインの学習内容を自分のメモリに混ぜない。 ヘッドレス呼び出しにはメモリが関連付けられておらず、ローカルセッションはサインインしたアカウントを使用します。統合に独自のメモリを持たせたい場合は、専用のアカウントを与えてください。すべてのサーフェスで1つのメモリを参照してください。
制限事項
- ローカルクライアントは同じマシンに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