Skip to Content
模型用法Gemini思考

Gemini 思考設定

本頁說明 Gemini 模型的思考預設值與調整方式。模型 ID 與介面位址請見 Gemini 系列概覽。

重點除 Flash-Lite 外,Gemini 模型預設開啟思考,複雜問題可能耗時 1 分鐘以上。對速度敏感的情境請降低思考量。

Gemini 模型在回答前會先進行思考。思考消耗的 token 計入輸出並依輸出單價計費,數量請見 usageMetadata.thoughtsTokenCount(OpenAI 相容介面為 usage.completion_tokens_details.reasoning_tokens)。

模型預設調整方式
Gemini 3.x(Flash-Lite 除外)開啟思考thinkingLevel,如 "low";也接受 thinkingBudget(思考 token 上限)
Flash-Lite 系列(3.5、3.1)不思考傳入 thinkingLevel 或 thinkingBudget 後開啟

實測同一道數學題,thinkingLevel: "low" 可將 Gemini 3.5 Flash 的思考 token 從約 6000 降至約 4600,耗時也相應縮短。thinkingBudget: 0 可關閉 3.5 Flash、3 Flash Preview 的思考;3.1 Pro Preview、3.8 Flash 傳入後仍會思考,無法完全關閉。

gemini_thinking.py
import os from google import genai from google.genai import types client = genai.Client( api_key=os.environ["OFOX_API_KEY"], http_options={"api_version": "v1beta", "base_url": "https://api.ofox.io/gemini"}, ) resp = client.models.generate_content( model="google/gemini-3.8-flash", contents="找出所有小於 50 的正整數 n,使 n² + n + 41 不是質數。", config=types.GenerateContentConfig( thinking_config=types.ThinkingConfig(thinking_level="low"), ), ) print(resp.text) print("思考 token:", resp.usage_metadata.thoughts_token_count or 0)
  • thinkingLevel: "low" 時,模型對簡單問題可能不進行思考,此時不會出現 thoughtsTokenCount。
  • 需要查看思考過程時,在 thinkingConfig 中加入 "includeThoughts": true,parts 中帶有 "thought": true 的項目為思考摘要,其餘為回答。
  • 思考 token 計入 maxOutputTokens。上限設定過小時,回答會在中途截斷,請見常見錯誤。
  • thinkingConfig 位於 generationConfig 內。
最後更新於