ドキュメント
エージェントフロー
インテグレーション
プロンプトプリプロセッサ
ジェネレーター
カスタム設定
プラグインの発行
テキスト埋め込み
トークン化
モデル情報
エージェントフロー
インテグレーション
プロンプトプリプロセッサ
ジェネレーター
カスタム設定
プラグインの発行
テキスト埋め込み
トークン化
モデル情報
インテグレーション
複数ツール
プラグインサポートは現在プライベートベータ版です。こちらからベータ版に参加してください。
ツールプロバイダーは、モデルが使用する複数のツールを定義できます。追加のツールインスタンスを作成し、tools配列に追加するだけです。
以下の例では、ファイルを読み込むための2番目のツールを追加しています。
import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { existsSync } from "fs";
import { readFile, writeFile } from "fs/promises";
import { join } from "path";
export async function toolsProvider(ctl: ToolsProviderController) {
const tools: Tool[] = [];
const createFileTool = tool({
name: `create_file`,
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); // First tool
const readFileTool = tool({
name: `read_file`,
description: "Read the content of a file with the given name.",
parameters: { file_name: z.string() },
implementation: async ({ file_name }) => {
const filePath = join(ctl.getWorkingDirectory(), file_name);
if (!existsSync(filePath)) {
return "Error: File does not exist.";
}
const content = await readFile(filePath, "utf-8");
return content;
},
});
tools.push(readFileTool); // Second tool
return tools; // Return the tools array
}
このページのソースはGitHubで入手できます。