API リファレンス
詳細なメソッドの説明、パラメータ、実用的な例を含む完全なGemini CLI APIドキュメント。
API セクション
異なるAPIカテゴリをナビゲート
コア API
Geminiモデルとの相互作用と会話管理のためのメインAPI
プラグイン API
カスタムプラグインと拡張機能を開発するためのAPI
設定 API
CLI設定と設定を管理するためのAPI
ツール API
組み込みツールを管理・実行するためのAPI
コア API
Geminiモデルとの相互作用と会話管理のためのメインAPI
chat()
Geminiとのインタラクティブチャットセッションを開始
シグネチャ:
chat(options?: ChatOptions): Promise<ChatSession>例:
import { GeminiCLI } from '@google/generative-ai-cli';
const cli = new GeminiCLI();
const session = await cli.chat({
model: 'gemini-pro',
temperature: 0.7
});ask()
プロンプトを送信して応答を受信
シグネチャ:
ask(prompt: string, options?: AskOptions): Promise<string>例:
const response = await cli.ask("機械学習とは何ですか?", {
maxTokens: 1000,
temperature: 0.5
});analyze()
AIアシスタンスでファイルやコードを分析
シグネチャ:
analyze(files: string[], options?: AnalyzeOptions): Promise<AnalysisResult>例:
const analysis = await cli.analyze(['src/main.js'], {
type: 'code-review',
includeMetrics: true
});プラグイン API
カスタムプラグインと拡張機能を開発するためのAPI
registerPlugin()
CLIに新しいプラグインを登録
シグネチャ:
registerPlugin(plugin: Plugin): void例:
const myPlugin = {
name: 'my-custom-plugin',
version: '1.0.0',
commands: {
'custom-command': async (args) => {
// プラグインロジックここ
return 'プラグインが正常に実行されました';
}
}
};
cli.registerPlugin(myPlugin);createTool()
AI用のカスタムツールを作成
シグネチャ:
createTool(definition: ToolDefinition): Tool例:
const weatherTool = cli.createTool({
name: 'get_weather',
description: '指定された場所の現在の天気を取得',
parameters: {
location: { type: 'string', required: true }
},
execute: async ({ location }) => {
// 天気データを取得
return `${location}の天気:晴れ、25°C`;
}
});設定 API
CLI設定と設定を管理するためのAPI
getConfig()
現在の設定値を取得
シグネチャ:
getConfig(key?: string): any例:
// すべての設定を取得
const config = cli.getConfig();
// 特定の設定値を取得
const model = cli.getConfig('model');setConfig()
設定値を設定
シグネチャ:
setConfig(key: string, value: any): void例:
// モデルを設定
cli.setConfig('model', 'gemini-pro');
// 複数の値を設定
cli.setConfig('temperature', 0.8);
cli.setConfig('maxTokens', 2000);resetConfig()
設定をデフォルトにリセット
シグネチャ:
resetConfig(key?: string): void例:
// すべての設定をリセット
cli.resetConfig();
// 特定のキーをリセット
cli.resetConfig('temperature');ツール API
組み込みツールを管理・実行するためのAPI
listTools()
利用可能なツールのリストを取得
シグネチャ:
listTools(): Tool[]例:
const tools = cli.listTools(); console.log(tools.map(t => t.name)); // ['read_file', 'write_file', 'run_shell_command', ...]
executeTool()
特定のツールを実行
シグネチャ:
executeTool(name: string, args: any): Promise<any>例:
// ファイルを読み取り
const content = await cli.executeTool('read_file', {
path: './package.json'
});
// シェルコマンドを実行
const result = await cli.executeTool('run_shell_command', {
command: 'ls -la'
});共通タイプ
APIで使用されるTypeScriptインターフェースとタイプ
ChatOptions
チャットセッションを開始するためのオプション
model
string
使用するモデル(例:"gemini-pro")
temperature
number
創造性レベル(0-1)
maxTokens
number
最大応答長
systemPrompt
string
システム指示
ToolDefinition
カスタムツールを作成するための定義
name
string
一意のツール名
description
string
AIのためのツール説明
parameters
object
パラメータスキーマ
execute
function
ツール実行関数