Gemini 2.5 モデルは、推論と多段階の計画能力を大幅に向上させる内部の「思考プロセス」を使用できます。これにより、コーディング、高度な数学、データ分析などの複雑なタスクに非常に効果的です。
思考モデルには、次の構成とオプションがあります。
思考予算: 思考予算を使用して、モデルが実行できる「思考」の量を構成できます。この構成は、レイテンシや費用の削減が優先される場合に特に重要です。また、タスクの難易度の比較を確認して、モデルがどの程度の思考能力を必要とするかを判断します。
思考の要約: 思考の要約を有効にして、生成されたレスポンスに含めることができます。これらの要約は、モデルの生の思考を合成したもので、モデルの内部推論プロセスに関する分析情報を提供します。
思考シグネチャ: Firebase AI Logic SDK は、思考シグネチャを自動的に処理します。これにより、関数呼び出しを使用する場合に、モデルが前のターンの思考コンテキストにアクセスできるようになります。
思考モデルを使用する際のベスト プラクティスとプロンプトのガイダンスを必ずご確認ください。
思考モデルを使用する
他の Gemini モデルと同様に思考モデルを使用します(選択した Gemini API プロバイダを初期化し、GenerativeModel
インスタンスを作成するなど)。これらのモデルは、構造化された出力を生成する、画像、動画、音声、PDF などのマルチモーダル入力を分析するなど、テキストやコードの生成タスクに使用できます。出力をストリーミングしているときに思考モデルを使用することもできます。
この機能をサポートするモデル
この機能は Gemini 2.5 モデルでのみサポートされています。
gemini-2.5-pro
gemini-2.5-flash
gemini-2.5-flash-lite
思考モデルを使用するためのベスト プラクティスとプロンプトのガイダンス
Google AI Studio または Vertex AI Studio でプロンプトをテストすることをおすすめします。これらのツールでは、思考プロセス全体を確認できます。モデルが逸脱した可能性のある領域を特定し、プロンプトを調整して、より一貫性のある正確なレスポンスを得ることができます。
望ましい結果を説明する一般的なプロンプトから始め、モデルが回答を決定する方法についての最初の考え方を観察します。レスポンスが期待どおりでない場合は、次のプロンプト手法のいずれかを使用して、モデルがより適切なレスポンスを生成できるようにします。
- 詳しい手順を説明する
- 入出力ペアの例をいくつか提供する
- 出力と回答の言い回しと形式に関するガイダンスを提供する
- 具体的な確認手順を提供する
プロンプトに加えて、次の推奨事項の使用も検討してください。
システム指示を設定します。これは、プロンプトまたはエンドユーザーからの詳細な指示がモデルに伝達される前に追加する「前文」のようなものです。システム指示を使用すると、特定のニーズやユースケースに基づいてモデルの動作を制御できます。
思考予算を設定して、モデルが実行できる思考の量を構成します。予算を低く設定すると、モデルは回答を「考えすぎ」ません。予算を高く設定すると、必要に応じてモデルがより多くのことを考えられるようになります。思考予算を設定すると、実際のレスポンス用にトークン出力上限のより多くの部分が予約されます。
Firebase コンソールの AI モニタリングを有効にして、思考トークンの数と、思考が有効になっているリクエストのレイテンシをモニタリングします。思考の要約が有効になっている場合は、コンソールに表示されます。コンソールでモデルの詳細な推論を調べて、プロンプトのデバッグと調整を行うことができます。
思考予算を制御する
モデルが回答を生成するために実行できる思考の量を制御するには、使用できる思考予算トークンの数を指定します。
デフォルトの思考予算よりも多くのトークンが必要になる可能性がある場合は、思考予算を手動で設定できます。タスクの複雑さと推奨予算については、このセクションの後半で詳しく説明します。概要は次のとおりです。
- レイテンシが重要な場合や、複雑でないタスクの場合は、思考予算を低く設定する
- 複雑なタスクには高い思考予算を設定する
思考予算を設定する
Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考予算を設定します。構成はインスタンスの存続期間中維持されます。リクエストごとに異なる思考予算を使用する場合は、各予算で構成された GenerativeModel
インスタンスを作成します。
サポートされている思考予算の値については、このセクションで後ほど説明します。
Swift
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考予算を設定します。
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
let generationConfig = GenerationConfig(
thinkingConfig: ThinkingConfig(thinkingBudget: 1024)
)
// Specify the config as part of creating the `GenerativeModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
)
// ...
Kotlin
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
でパラメータの値を設定します。
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
val generationConfig = generationConfig {
thinkingConfig = thinkingConfig {
thinkingBudget = 1024
}
}
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig,
)
// ...
Java
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
でパラメータの値を設定します。
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
.setThinkingBudget(1024)
.build();
GenerationConfig generationConfig = GenerationConfig.builder()
.setThinkingConfig(thinkingConfig)
.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig */ generationConfig
);
);
// ...
Web
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
でパラメータの値を設定します。
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
const generationConfig = {
thinkingConfig: {
thinkingBudget: 1024
}
};
// Specify the config as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
// ...
Dart
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
でパラメータの値を設定します。
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
final thinkingConfig = ThinkingConfig(thinkingBudget: 1024);
final generationConfig = GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
config: generationConfig,
);
// ...
Unity
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
でパラメータの値を設定します。
// ...
// Set the thinking configuration
// Use a thinking budget value appropriate for your model (example value shown here)
var thinkingConfig = new ThinkingConfig(thinkingBudget: 1024);
var generationConfig = new GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
// ...
サポートされている思考予算の値
次の表に、モデルの thinkingBudget
を構成することで、各モデルに設定できる思考予算の値を示します。
モデル | デフォルト値 | 思考予算の利用可能な範囲 |
思考を無効にする値 |
動的な思考を可能にする |
|
---|---|---|---|---|---|
最小値 | 最大値 | ||||
Gemini 2.5 Pro | 8,192 |
128 |
32,768 |
オフにすることはできません | -1 |
Gemini 2.5 Flash | 8,192 |
1 |
24,576 |
0 |
-1 |
Gemini 2.5 Flash‑Lite | 0 (デフォルトでは思考は無効) |
512 |
24,576 |
0 (または思考予算をまったく構成しない) |
-1 |
思考プロセスを無効にする
一部の簡単なタスクでは、思考能力は必要なく、従来の推論で十分です。レイテンシの短縮が優先される場合は、モデルがレスポンスの生成に必要以上の時間をかけないようにする必要があります。
このような状況では、思考を無効(オフ)にすることができます。
- Gemini 2.5 Pro: thinking は無効にできません
- Gemini 2.5 Flash:
thinkingBudget
を0
トークンに設定します - Gemini 2.5 Flash‑Lite: デフォルトでは思考が無効
動的な思考を可能にする
thinkingBudget
を -1
に設定すると、モデルがいつ、どれだけ思考するか(動的思考)を決定できます。モデルは、上記の最大トークン値まで、適切な数のトークンを使用できます。
タスクの複雑さ
簡単なタスク - 思考をオフにできる
事実の取得や分類など、複雑な推論を必要としない簡単なリクエスト。例:- 「DeepMind はどこで設立されましたか?」
- 「このメールは会議を依頼しているのか、それとも情報を提供しているだけなのか?」
中程度のタスク - デフォルトの予算または追加の思考予算が必要
段階的な処理やより深い理解が役立つ一般的なリクエスト。例:- 「光合成と成長の類似点を説明して。」
- 「電気自動車とハイブリッド車を比較対照してください。」
難しいタスク - 最大の思考予算が必要になる可能性がある
複雑な数学の問題の解決やコーディング タスクなど、非常に複雑な課題。このようなタスクでは、モデルが完全な推論と計画の能力を発揮する必要があります。多くの場合、回答を提供する前に多くの内部ステップが必要になります。例:- 「AIME 2025 の問題 1 を解いてください。17b が 97b の約数となるすべての整数基数 b > 9 の合計を求めてください。」
- 「ユーザー認証を含む、株価のリアルタイム データを可視化するウェブ アプリケーションの Python コードを記述してください。できるだけ効率的にしてください。」
回答に思考の概要を含める
思考の要約は、モデルの生の思考を合成したもので、モデルの内部推論プロセスに関する分析情報を提供します。
回答に思考の要約を含める理由を以下に示します。
思考の要約をアプリの UI に表示したり、ユーザーがアクセスできるようにしたりできます。思考の要約はレスポンスの別の部分として返されるため、アプリでの使用方法をより細かく制御できます。
Firebase コンソールの AI モニタリングも有効にすると、コンソールに思考の概要が表示されます。ここで、モデルの詳細な推論を調べて、プロンプトのデバッグと調整を行うことができます。
思考の要約に関する重要な注意点は次のとおりです。
思考の要約は思考予算によって制御されません(予算はモデルの生の思考にのみ適用されます)。ただし、思考が無効になっている場合、モデルは思考の要約を返しません。
思考の要約は、モデルの通常の生成テキスト レスポンスの一部とみなされ、出力トークンとしてカウントされます。
思考の要約を有効にする
Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。 |
モデル構成で includeThoughts
を true に設定すると、思考の要約を有効にできます。レスポンスの thoughtSummary
フィールドを確認することで、サマリーにアクセスできます。
以下に、レスポンスで思考の要約を有効にして取得する方法を示す例を示します。
Swift
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
let generationConfig = GenerationConfig(
thinkingConfig: ThinkingConfig(includeThoughts: true)
)
// Specify the config as part of creating the `GenerativeModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
)
let response = try await model.generateContent("solve x^2 + 4x + 4 = 0")
// Handle the response that includes thought summaries
if let thoughtSummary = response.thoughtSummary {
print("Thought Summary: \(thoughtSummary)")
}
guard let text = response.text else {
fatalError("No text in response.")
}
print("Answer: \(text)")
Kotlin
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
val generationConfig = generationConfig {
thinkingConfig = thinkingConfig {
includeThoughts = true
}
}
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig,
)
val response = model.generateContent("solve x^2 + 4x + 4 = 0")
// Handle the response that includes thought summaries
response.thoughtSummary?.let {
println("Thought Summary: $it")
}
response.text?.let {
println("Answer: $it")
}
Java
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
.setIncludeThoughts(true)
.build();
GenerationConfig generationConfig = GenerationConfig.builder()
.setThinkingConfig(thinkingConfig)
.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig */ generationConfig
);
);
// Handle the response that includes thought summaries
ListenableFuture responseFuture = model.generateContent("solve x^2 + 4x + 4 = 0");
Futures.addCallback(responseFuture, new FutureCallback() {
@Override
public void onSuccess(GenerateContentResponse response) {
if (response.getThoughtSummary() != null) {
System.out.println("Thought Summary: " + response.getThoughtSummary());
}
if (response.getText() != null) {
System.out.println("Answer: " + response.getText());
}
}
@Override
public void onFailure(Throwable t) {
// Handle error
}
}, MoreExecutors.directExecutor());
Web
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
const generationConfig = {
thinkingConfig: {
includeThoughts: true
}
};
// Specify the config as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
const result = await model.generateContent("solve x^2 + 4x + 4 = 0");
const response = result.response;
// Handle the response that includes thought summaries
if (response.thoughtSummary()) {
console.log(`Thought Summary: ${response.thoughtSummary()}`);
}
const text = response.text();
console.log(`Answer: ${text}`);
Dart
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
final thinkingConfig = ThinkingConfig(includeThoughts: true);
final generationConfig = GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
generationConfig: generationConfig,
);
final response = await model.generateContent('solve x^2 + 4x + 4 = 0');
// Handle the response that includes thought summaries
if (response.thoughtSummary != null) {
print('Thought Summary: ${response.thoughtSummary}');
}
if (response.text != null) {
print('Answer: ${response.text}');
}
Unity
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
var thinkingConfig = new ThinkingConfig(includeThoughts: true);
var generationConfig = new GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
var response = await model.GenerateContentAsync("solve x^2 + 4x + 4 = 0");
// Handle the response that includes thought summaries
if (response.ThoughtSummary != null) {
Debug.Log($"Thought Summary: {response.ThoughtSummary}");
}
if (response.Text != null) {
Debug.Log($"Answer: {response.Text}");
}
ストリームの思考の要約
generateContentStream
を使用してレスポンスをストリーミングする場合は、思考の要約を表示することもできます。これにより、レスポンスの生成中にローリング増分要約が返されます。
Swift
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
let generationConfig = GenerationConfig(
thinkingConfig: ThinkingConfig(includeThoughts: true)
)
// Specify the config as part of creating the `GenerativeModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
)
let stream = try model.generateContentStream("solve x^2 + 4x + 4 = 0")
// Handle the streamed response that includes thought summaries
var thoughts = ""
var answer = ""
for try await response in stream {
if let thought = response.thoughtSummary {
if thoughts.isEmpty {
print("--- Thoughts Summary ---")
}
print(thought)
thoughts += thought
}
if let text = response.text {
if answer.isEmpty {
print("--- Answer ---")
}
print(text)
answer += text
}
}
Kotlin
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
val generationConfig = generationConfig {
thinkingConfig = thinkingConfig {
includeThoughts = true
}
}
// Specify the config as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
generationConfig,
)
// Handle the streamed response that includes thought summaries
var thoughts = ""
var answer = ""
model.generateContentStream("solve x^2 + 4x + 4 = 0").collect { response ->
response.thoughtSummary?.let {
if (thoughts.isEmpty()) {
println("--- Thoughts Summary ---")
}
print(it)
thoughts += it
}
response.text?.let {
if (answer.isEmpty()) {
println("--- Answer ---")
}
print(it)
answer += it
}
}
Java
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
ThinkingConfig thinkingConfig = new ThinkingConfig.Builder()
.setIncludeThoughts(true)
.build();
GenerationConfig generationConfig = GenerationConfig.builder()
.setThinkingConfig(thinkingConfig)
.build();
// Specify the config as part of creating the `GenerativeModel` instance
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig */ generationConfig
);
);
// Streaming with Java is complex and depends on the async library used.
// This is a conceptual example using a reactive stream.
Flowable responseStream = model.generateContentStream("solve x^2 + 4x + 4 = 0");
// Handle the streamed response that includes thought summaries
StringBuilder thoughts = new StringBuilder();
StringBuilder answer = new StringBuilder();
responseStream.subscribe(response -> {
if (response.getThoughtSummary() != null) {
if (thoughts.length() == 0) {
System.out.println("--- Thoughts Summary ---");
}
System.out.print(response.getThoughtSummary());
thoughts.append(response.getThoughtSummary());
}
if (response.getText() != null) {
if (answer.length() == 0) {
System.out.println("--- Answer ---");
}
System.out.print(response.getText());
answer.append(response.getText());
}
}, throwable -> {
// Handle error
});
Web
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
const generationConfig = {
thinkingConfig: {
includeThoughts: true
}
};
// Specify the config as part of creating the `GenerativeModel` instance
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", generationConfig });
const result = await model.generateContentStream("solve x^2 + 4x + 4 = 0");
// Handle the streamed response that includes thought summaries
let thoughts = "";
let answer = "";
for await (const chunk of result.stream) {
if (chunk.thoughtSummary()) {
if (thoughts === "") {
console.log("--- Thoughts Summary ---");
}
// In Node.js, process.stdout.write(chunk.thoughtSummary()) could be used
// to avoid extra newlines.
console.log(chunk.thoughtSummary());
thoughts += chunk.thoughtSummary();
}
const text = chunk.text();
if (text) {
if (answer === "") {
console.log("--- Answer ---");
}
// In Node.js, process.stdout.write(text) could be used.
console.log(text);
answer += text;
}
}
Dart
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
final thinkingConfig = ThinkingConfig(includeThoughts: true);
final generationConfig = GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
generationConfig: generationConfig,
);
final responses = model.generateContentStream('solve x^2 + 4x + 4 = 0');
// Handle the streamed response that includes thought summaries
var thoughts = '';
var answer = '';
await for (final response in responses) {
if (response.thoughtSummary != null) {
if (thoughts.isEmpty) {
print('--- Thoughts Summary ---');
}
thoughts += response.thoughtSummary!;
}
if (response.text != null) {
if (answer.isEmpty) {
print('--- Answer ---');
}
answer += response.text!;
}
}
Unity
GenerativeModel
インスタンスの作成の一環として、GenerationConfig
で思考の要約を有効にします。
// ...
// Set the thinking configuration
// Optionally enable thought summaries in the generated response (default is false)
var thinkingConfig = new ThinkingConfig(includeThoughts: true);
var generationConfig = new GenerationConfig(
thinkingConfig: thinkingConfig
);
// Specify the config as part of creating the `GenerativeModel` instance
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
generationConfig: generationConfig
);
var stream = model.GenerateContentStreamAsync("solve x^2 + 4x + 4 = 0");
// Handle the streamed response that includes thought summaries
var thoughts = "";
var answer = "";
await foreach (var response in stream)
{
if (response.ThoughtSummary != null)
{
if (string.IsNullOrEmpty(thoughts))
{
Debug.Log("--- Thoughts Summary ---");
}
Debug.Log(response.ThoughtSummary);
thoughts += response.ThoughtSummary;
}
if (response.Text != null)
{
if (string.IsNullOrEmpty(answer))
{
Debug.Log("--- Answer ---");
}
Debug.Log(response.Text);
answer += response.Text;
}
}
思考シグネチャについて
マルチターンのインタラクションで思考を使用する場合、モデルは前のターンの思考コンテキストにアクセスできません。ただし、関数呼び出しを使用している場合は、思考シグネチャを利用して、ターン間で思考コンテキストを維持できます。思考シグネチャは、モデルの内部思考プロセスの暗号化された表現です。思考と関数呼び出しを使用する場合に使用できます。具体的には、次の場合に思考シグネチャが生成されます。
- 思考が有効になり、思考が生成されます。
- リクエストに関数宣言が含まれています。
思考シグネチャを活用するには、通常どおり関数呼び出しを使用します。Firebase AI Logic SDK は、状態を管理し、思考シグネチャを自動的に処理することで、このプロセスを簡素化します。SDK は、生成された思考シグネチャを Chat
セッション内の後続の sendMessage
呼び出しまたは sendMessageStream
呼び出し間で自動的に渡します。
料金とトークンのカウント
思考トークンは、テキスト出力トークンと同じ料金を使用します。思考の要約を有効にすると、思考の要約は思考トークンとみなされ、それに応じて料金が設定されます。
Firebase コンソールの AI モニタリングを有効にすると、思考が有効になっているリクエストの思考トークンの数をモニタリングできます。
思考トークンの合計数は、レスポンスの usageMetadata
属性の thoughtsTokenCount
フィールドから取得できます。
Swift
// ...
let response = try await model.generateContent("Why is the sky blue?")
if let usageMetadata = response.usageMetadata {
print("Thoughts Token Count: \(usageMetadata.thoughtsTokenCount)")
}
Kotlin
// ...
val response = model.generateContent("Why is the sky blue?")
response.usageMetadata?.let { usageMetadata ->
println("Thoughts Token Count: ${usageMetadata.thoughtsTokenCount}")
}
Java
// ...
ListenableFuture<GenerateContentResponse> response =
model.generateContent("Why is the sky blue?");
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
String usageMetadata = result.getUsageMetadata();
if (usageMetadata != null) {
System.out.println("Thoughts Token Count: " +
usageMetadata.getThoughtsTokenCount());
}
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
Web
// ...
const response = await model.generateContent("Why is the sky blue?");
if (response?.usageMetadata?.thoughtsTokenCount != null) {
console.log(`Thoughts Token Count: ${response.usageMetadata.thoughtsTokenCount}`);
}
Dart
// ...
final response = await model.generateContent(
Content.text("Why is the sky blue?"),
]);
if (response?.usageMetadata case final usageMetadata?) {
print("Thoughts Token Count: ${usageMetadata.thoughtsTokenCount}");
}
Unity
// ...
var response = await model.GenerateContentAsync("Why is the sky blue?");
if (response.UsageMetadata != null)
{
UnityEngine.Debug.Log($"Thoughts Token Count: {response.UsageMetadata?.ThoughtsTokenCount}");
}
トークンの詳細については、トークン数のガイドをご覧ください。