ドキュメント
エージェントフロー
インテグレーション
プロンプトプリプロセッサ
ジェネレーター
カスタム設定
プラグインの発行
テキスト埋め込み
トークン化
モデル情報
エージェントフロー
インテグレーション
プロンプトプリプロセッサ
ジェネレーター
カスタム設定
プラグインの発行
テキスト埋め込み
トークン化
モデル情報
インテグレーション
単一ツール
プラグインサポートは現在プライベートベータ版です。こちらからベータ版に参加してください。
ツールプロバイダーをセットアップするには、まずプラグインの src ディレクトリに toolsProvider.ts という名前のファイルを作成します。
import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { existsSync } from "fs";
import { writeFile } from "fs/promises";
import { join } from "path";
export async function toolsProvider(ctl: ToolsProviderController) {
const tools: Tool[] = [];
const createFileTool = tool({
// Name of the tool, this will be passed to the model. Aim for concise, descriptive names
name: `create_file`,
// Your description here, more details will help the model to understand when to use the tool
description: "Create a file with the given name and content.",
parameters: { file_name: z.string(), content: z.string() },
implementation: async ({ file_name, content }) => {
const filePath = join(ctl.getWorkingDirectory(), file_name);
if (existsSync(filePath)) {
return "Error: File already exists.";
}
await writeFile(filePath, content, "utf-8");
return "File created.";
},
});
tools.push(createFileTool);
return tools;
}
上記のツールプロバイダーは、モデルが作業ディレクトリ内に指定された名前とコンテンツを持つファイルを作成できる create_file という単一のツールを定義しています。ツールの定義については、「ツール定義」でさらに詳しく学ぶことができます。
次に、プラグインの index.ts でツールプロバイダーを登録します。
// ... other imports ...
import { toolsProvider } from "./toolsProvider";
export async function main(context: PluginContext) {
// ... other plugin setup code ...
// Register the tools provider.
context.withToolsProvider(toolsProvider); // <-- Register the tools provider
// ... other plugin setup code ...
}
これで、LLMにファイルを作成するように依頼すると、作成したツールを使用してファイルを作成できるようになります。
このページのソースは、GitHub で利用可能です。