システム指示は、モデルが公開される前にエンドユーザーからの詳細な手順を示すために追加する「プリアンブル」のようなものです。システム指示を使用すると、特定のニーズやユースケースに基づいてモデルの動作を制御できます。
システム指示を設定すると、タスクを理解するための追加のコンテキストがモデルに提供され、よりカスタマイズされた回答が得られます。また、モデルとユーザーのインタラクション全体を特定のガイドラインに準拠させることができます。エンドユーザーが提供するプロンプトとは別に、システム指示でプロダクト レベルの動作を指定できます。たとえば、ロールやペルソナ、コンテキスト情報、フォーマット手順などを指定できます。
システム指示は、次のような用途で使用できます。
- ペルソナまたはロールの定義(chatbot など)
- 出力形式の定義(マークダウン、YAML など)
- 出力のスタイルとトーンの定義(詳細度、形式、対象読者レベルなど)
- タスクの目標またはルールの定義する(たとえば、説明なしでコード スニペットを返す、など)
- プロンプトの追加のコンテキストの提供(ナレッジ カットオフなど)
システム指示はリクエスト全体に適用されます。プロンプトに含まれている場合、システム指示は複数のユーザーとモデルのターンで機能します。システム指示はプロンプトのコンテンツとは別ですが、全体的なプロンプトの一部であるため、標準のデータ使用ポリシーの対象となります。
システム指示は、すべての Gemini モデルでサポートされています。Imagen 3 モデルではサポートされていません。
システム指示を設定する
一般的なユースケースのシステム指示を設定する
Swift
GenerativeModel
インスタンスを作成するときに systemInstruction
を指定します。
import FirebaseVertexAI
// Initialize the Vertex AI service
let vertex = VertexAI.vertexAI()
// Create a `GenerativeModel` instance
let model = vertex.generativeModel(
modelName: "gemini-2.0-flash",
systemInstruction: ModelContent(role: "system", parts: "You are a cat. Your name is Neko.")
)
Kotlin
GenerativeModel
インスタンスを作成するときに systemInstruction
を指定します。
// Initialize the Vertex AI service and create a `GenerativeModel` instance
val generativeModel = Firebase.vertexAI.generativeModel(
modelName = "gemini-2.0-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
Java
GenerativeModel
インスタンスを作成するときに systemInstruction
を指定します。
// Initialize the Vertex AI service and create a `GenerativeModel` instance
GenerativeModel gm = FirebaseVertexAI.getInstance().generativeModel(
/* modelName */ "gemini-2.0-flash",
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
/* requestOptions (optional) */ new RequestOptions(),
/* tools (optional) */ null,
/* toolsConfig (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
Web
GenerativeModel
インスタンスを作成するときに systemInstruction
を指定します。
import { initializeApp } from "firebase/app";
import { getVertexAI, getGenerativeModel } from "firebase/vertexai";
// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Vertex AI service
const vertexAI = getVertexAI(firebaseApp);
// Create a `GenerativeModel` instance
const model = getGenerativeModel(vertexAI, {
model: "gemini-2.0-flash",
systemInstruction: "You are a cat. Your name is Neko."
});
Dart
GenerativeModel
インスタンスを作成するときに systemInstruction
を指定します。
import 'package:firebase_vertexai/firebase_vertexai.dart';
import 'package:firebase_core/firebase_core.dart';
await Firebase.initializeApp();
// Initialize the Vertex AI service and create a `GenerativeModel` instance
final model =
FirebaseVertexAI.instance.generativeModel(
model: 'gemini-2.0-flash',
systemInstruction: Content.system('You are a cat. Your name is Neko.'),
);
Gemini Live API のシステム指示を設定する
Swift
Live API は Apple プラットフォーム アプリではまだサポートされていませんが、近日中にサポートされる予定です。
Kotlin
LiveModel
インスタンスを作成するときに systemInstruction
を指定します。
// Initialize the Vertex AI service and create a `LiveModel` instance
val model = Firebase.vertexAI.LiveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
Java
LiveModel
インスタンスを作成するときに systemInstruction
を指定します。
// Initialize the Vertex AI service and create a `LiveeModel` instance
GenerativeModel gm = FirebaseVertexAI.getInstance().LiveModel(
/* modelName */ "gemini-2.0-flash",
/* generationConfig (optional) */ null,
/* requestOptions (optional) */ new RequestOptions(),
/* tools (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
);
LiveModelFutures model = LiveModelFutures.from(gm);
Web
Live API はウェブアプリではまだサポートされていませんが、近日中にサポートされる予定です。
Dart
LiveModel
インスタンスを作成するときに systemInstruction
を指定します。
import 'package:firebase_vertexai/firebase_vertexai.dart';
import 'package:firebase_core/firebase_core.dart';
await Firebase.initializeApp();
// Initialize the Vertex AI service and create a `LiveModel` instance
final model =
FirebaseVertexAI.instance.liveModel(
model: 'gemini-2.0-flash-live-preview-04-09',
systemInstruction: Content.system('You are a cat. Your name is Neko.'),
);
プロンプトの例
以下に、モデルの想定動作を定義するシステム指示の例を示します。
コード生成
- システム: あなたは、フロントエンド インターフェースのコードのレンダリングを専門とするコーディングの専門家です。作成するウェブサイトのコンポーネントを説明する際は、作成に必要な HTML と CSS を返してください。このコードの説明は行わないでください。UI デザインも提案してください。
- ユーザー: ページの中央で、選択した画像を回転させ、キャプションを表示するボックスを作成してください。ページの中央にある画像は、目立つように影付きにしてください。また、サイトの別のページにリンクする必要があります。URL は空欄のままにしてください。
フォーマットされたデータの生成
システム: あなたは、家庭で料理を作る際のアシスタントです。材料のリストを受け取って、それらの材料を使用するレシピのリストを返します。追加の材料が不要なレシピは、必ず、追加の材料が必要なレシピの前にリストする必要があります。
レスポンスは、3 つのレシピを含む JSON オブジェクトにする必要があります。レシピ オブジェクトには次のスキーマがあります。
- name: レシピの名前
- usedIngredients: リストで指定されたレシピの材料
- otherIngredients: リストで指定されていないレシピの材料(他の材料がない場合は省略)
- description: レシピの簡単な説明。販売する際の説明のようにポジティブに書く
ユーザー:
- 1 ポンドの袋入り冷凍ブロッコリー
- 1 パイントのヘビークリーム
- 1 ポンドのパックのチーズの端切れとかけら
音楽 chatbot
- システム: あなたは、音楽の歴史家として、さまざまな音楽ジャンルに関する包括的な知識を披露し、関連する例を提示します。音楽の楽しさを広めるため、トーンは明るく、熱狂的な雰囲気みにします。質問が音楽に関連していない場合は、「その件については把握しておりません」と回答してください。
- ユーザー: 60 年代に生まれた人が聴いていた音楽のジャンルで最も人気があったのは?5 曲を箇条書きでリストしてください。
コンテンツ生成を制御するためのその他のオプション
- プロンプトの設計について学び、ニーズに固有の出力を生成するようにモデルに影響を与えましょう。
- モデル パラメータを構成して、モデルがどのようにレスポンスを生成するかを制御します。Gemini モデルの場合、これらのパラメータには、最大出力トークン、温度、topK、topP が含まれます。Imagen モデルの場合、アスペクト比、人物の生成、ウォーターマークなどがあります。
- 安全性設定を使用して、ヘイトスピーチや性的描写が露骨なコンテンツなど、有害と見なされる回答が生成される可能性を調整します。
- プロンプトとともにレスポンス スキーマを渡して、特定の出力スキーマを指定します。この機能は、JSON 出力の生成に最もよく使用されますが、分類タスクにも使用できます(モデルで特定のラベルやタグを使用する場合など)。