本指南說明如何使用 Gemini 模型中的思考功能,提升模型的推論能力。本頁面涵蓋下列主題:
- 支援的機型:瞭解哪些機型支援思考功能。
- 使用思考模型:啟用並使用具備思考能力的模型。
- 查看想法摘要:查看模型思考過程的簡短輸出內容。
- 控管思考預算:管理模型思考過程的權杖限制。
- 提示技巧:瞭解提示思維模型的最佳做法,取得更優質的回覆。
思考模型經過訓練後,會生成模型在回覆中經歷的「思考過程」。與同等基礎模型相比,這個程序可讓思考模型具備更強大的推理能力。
思考過程預設為啟用,使用 Vertex AI Studio 時,您可以查看完整的思考過程,以及模型產生的回覆。
支援的模型
以下機型支援思考功能:
使用思考模型
如要使用支援模型搭配思考功能,請按照下列步驟操作:
控制台
- 前往「Vertex AI Studio」>「建立提示」。
- 在「模型」面板中,按一下「切換模型」,然後從選單中選取支援的模型。
- 選用:在「系統指令」欄位中,詳細說明模型應如何設定回覆格式。
- 在「輸入提示」欄位中輸入提示。
- 按一下「執行」圖示 。
選取 Gemini 2.5 Flash 模型時,「思考預算」預設會設為「自動」。如要關閉這個模型的思考功能,請將「思考預算」設為「關閉」。
生成完成後,Gemini 就會傳回回覆。視提示的複雜程度而定,這可能需要幾秒鐘。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考說明文件。
設定環境變數,透過 Vertex AI 使用 Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
查看想法摘要
想法摘要是模型思考過程的簡短版本。Gemini 2.5 Flash 和 Gemini 2.5 Pro 都會顯示思考摘要。
控制台
Vertex AI Studio 預設會啟用想法摘要。 如要查看模型想法摘要,請展開「想法」面板。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考說明文件。
設定環境變數,透過 Vertex AI 使用 Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
控管思考預算
您可以控制模型思考回覆的程度。這個上限稱為「思考預算」,適用於模型的完整思考過程。根據預設,模型會自動控制思考過程,最多可使用 8,192 個符記。
您可以手動設定這個權杖限制。舉例來說,您可以為較簡單的工作設定較低的限制,為較複雜的工作設定較高的限制。
下表列出各支援模型的最低和最高權杖預算金額:
模型 | 最低代幣金額 | 代幣金額上限 |
---|---|---|
Gemini 2.5 Flash | 1 | 24,576 |
Gemini 2.5 Pro | 128 | 32,768 |
Gemini 2.5 Flash-Lite | 512 | 24,576 |
如果將 Gemini 2.5 Flash 或 Gemini 2.5 Flash-Lite 的思考預算設為 0
,系統會關閉思考功能。Gemini 2.5 Pro 無法關閉思考功能。
如要讓模型在使用 API 時控管思考預算,請將思考預算設為 -1
。
控制台
- 前往「Vertex AI Studio」>「建立提示」。
- 在「模型」面板中,按一下「切換模型」,然後從選單中選取支援的模型。
- 在「思考預算」下拉式選單中選取「手動」,然後使用滑桿調整權杖限制。
Python
安裝
pip install --upgrade google-genai
詳情請參閱 SDK 參考說明文件。
設定環境變數,透過 Vertex AI 使用 Gen AI SDK:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
提示詞編寫技巧
只要提供有效的提示,就能充分發揮 Gemini 思考模型的效用。本節將說明幾項最佳做法。
做法 | 說明 | 最適合用於... |
---|---|---|
提供逐步操作說明 | 引導模型逐步解決問題。 | 複雜的工作,模型可能遺漏步驟或需要更專注的方法。 |
多樣本提示 | 提供多個輸入/輸出範例,示範所需行為和格式。 | 提高準確度,並確保模型瞭解預期輸出格式。 |
系統操作說明 | 為模型設定持續性角色、角色或格式設定規則,讓模型在多個提示中遵循這些設定。 | 建構應用程式,需要模型行為和輸出風格一致。 |
驗證與反思 | 要求模型檢查來源、複查推論過程,並驗證最終答案。 | 事實查詢或任務,這類任務非常重視準確度,且您希望減少生成錯誤資訊。 |
偵錯和引導 | 分析模型的思考過程,找出誤解之處並提供修正意見。 | 如果初始結果不如預期,請反覆修正提示並提升模型成效。 |
先從簡單的提示開始,描述您期望的結果,然後觀察模型的初步想法。
Describe the most unusual or striking architectural feature you've ever seen in a building or structure. <...> The most unusual architectural feature that has truly stayed with me is the "floating roof" of the Heydar Aliyev Center in Baku, Azerbaijan, designed by Zaha Hadid Architects. Visually, it's breathtaking. Imagine a vast, undulating landscape of pure white, seemingly draped over the building. It's not just a roof in the traditional sense; it's an extension of the ground, flowing seamlessly upwards and over the building's various spaces before curving back down to meet the earth again. There are no sharp angles, no rigid lines. Instead, everything is fluid, organic, and continuous. It resembles a giant, pristine white wave frozen in motion, or perhaps a sand dune sculpted by an unseen wind. <...> |
提供逐步說明
如果初始回應不符合需求,請提供明確的逐步指示,修正提示。這有助於引導模型解決問題,並採取更專注的做法。這項技術可讓您透過明確建議,引導模型瞭解工作。
Now imagine that architectural feature is not just for looks, but has a specific function or purpose related to the building's environment or the people who use it. Explain what that function could be and how it enhances the building's overall design and usability. <...> Let's imagine that the "floating roof" of the Heydar Aliyev Center is not purely aesthetic but serves a crucial environmental and user-centric function: it's designed as a sophisticated climate moderator and natural ventilation system for the Baku environment. Here's how this function would work and enhance the building: Function: Passive Climate Control and Natural Ventilation System Shading and Solar Heat Mitigation: The undulating curves of the white GFRC roof are strategically shaped and oriented to provide optimal shading throughout the day, year-round. Baku experiences intense sun, especially during the summer. The overhanging curves, acting like giant brise-soleils, would block direct sunlight from hitting the building's glass facade, significantly reducing solar heat gain. The varying heights and depths of the curves would create dynamic shade patterns, ensuring that different parts of the building are shaded at different times of the day, optimizing comfort and reducing the need for excessive air conditioning. The white color of the GFRC further enhances this by reflecting a large portion of the solar radiation. <...> |
採用思維鏈的多樣本提示
搭配思考功能使用多樣本提示,有助於 Gemini 提升理解能力,並提供更準確的回覆。在提示中提供幾個輸入/輸出範例,示範所需行為和格式。
Example 1: User: What is the tallest mountain in the world? Assistant: Mount Everest Example 2: User: What is the largest ocean? Assistant: Pacific Ocean User: What is the longest river in the world? Assistant: Amazon River |
使用系統指示
如果您要建構的應用程式會讓使用者直接與模型互動,可以使用系統指令引導 Gemini 回覆的格式和語氣。系統指令是模型在處理提示詞前會先處理的一組指令。每次收到提示時,模型都會回想這些指令,並據此決定行為和回應方式。例如角色或人物、背景資訊和格式設定指示。
System Instruction: You are a helpful and concise coding tutor. Always provide code examples and explain them briefly. User Prompt: Explain what is a closure in Javascript and give an example. function outerFunction(outerVar) { function innerFunction(innerVar) { console.log(outerVar); // Accessing outerVar from outerFunction's scope console.log(innerVar); } return innerFunction; } const closureExample = outerFunction('I am from outer'); closureExample('I am from inner'); Explanation: A closure is created when a function (innerFunction in this example) is defined inside another function (outerFunction) and the inner function remembers and has access to the variables from the outer function's scope, even after the outer function has finished executing. In the example: outerFunction is called with 'I am from outer' and returns innerFunction. closureExample now holds a reference to innerFunction. When closureExample('I am from inner') is called, innerFunction executes. Even though outerFunction has already finished, innerFunction can still access and use outerVar (which is 'I am from outer') because of the closure. In essence, the innerFunction "closes over" the variables of its outer function's scope, creating a closure. |
使用驗證和反射
您可以在系統指令或提示中直接加入特定驗證步驟。例如,你可以要求 Gemini 驗證來源、檢查推理過程、找出潛在錯誤,以及檢查最終答案。
Verify the following statement and provide your sources: The capital of Brazil is Rio de Janeiro. The statement "The capital of Brazil is Rio de Janeiro" is incorrect. The current capital of Brazil is Brasília. Rio de Janeiro was the capital of Brazil for a significant period, from 1763 to 1960. However, the capital was moved to Brasília in 1960 as part of a plan to develop the country's interior and create a more centrally located capital. Verification and Sources: You can easily verify this information from numerous reliable sources: Encyclopedias: Britannica: Searching for "Brazil" on Britannica will clearly state Brasília as the capital. https://www.britannica.com/place/Brazil (Look for the "Capital" information in the introductory summary or "Geography" section) Wikipedia: The Wikipedia article for "Brazil" also states Brasília as the capital. https://en.wikipedia.org/wiki/Brazil (Look in the infobox or introductory section) Government and Official Sources: CIA World Factbook: This is a highly reliable source for country information. Searching for "Brazil" will list Brasília as the capital. https://www.cia.gov/the-world-factbook/countries/brazil/ (Look under "Government" > "Capital") Official Website of the Brazilian Government (if accessible and in English): While navigating official government websites can sometimes be complex, they would definitively list Brasília as the capital. Geographic Resources: National Geographic: Their website and publications will confirm Brasília as the capital of Brazil. Atlases and Geography Textbooks: Any modern atlas or geography textbook will list Brasília as the capital. Why the confusion? The confusion might arise because: Rio de Janeiro is a very famous Brazilian city: It's a major tourist destination, known for its beaches, Carnival, and iconic landmarks like Christ the Redeemer. Its past status as capital adds to its historical significance and public recognition. Historical context: Rio de Janeiro was the capital for a long time. People who learned about Brazil in the past might remember it as the capital. In conclusion, the statement is false. The capital of Brazil is Brasília, not Rio de Janeiro. Rio de Janeiro was the former capital but is no longer the current capital. You can confidently use the sources listed above to verify this information. |
偵錯及引導模型
Vertex AI Studio 可讓您在使用者介面中查看模型的想法,有助於偵錯提示。
分析思考過程
查看模型的思考過程,找出模型可能誤解您指令的地方。這項分析有助於修正提示,更穩定地獲得預期回覆。
情境範例:如果模型在思考過程中誤解複雜指令中的某個步驟,您可以修正提示,釐清該步驟。
Step 1: Summarize the following article about quantum physics. Step 2: Translate the summary into Spanish. Step 3: Extract the key entities from the Spanish summary. Article: ... [Article Text] ... The user wants me to process an article about Google's new quantum chip called Willow in three steps: Step 1: Summarize the article. Step 2: Translate the summary into Spanish. Step 3: Extract the key entities from the Spanish summary. Let's break down each step. Step 1: Summarize the article. I need to read the article and identify the main points. The article is about Google's new quantum chip, Willow, and its achievements. The key achievements are: Exponential error reduction as qubits scale up. Outperforming supercomputers in a benchmark computation (RCS). Willow is a step towards commercially relevant quantum computing. It's the first system below threshold for quantum error correction. It achieved a benchmark computation in under 5 minutes that would take a supercomputer 10 septillion years. It was fabricated in a new facility. It has state-of-the-art performance and high quality qubits. Google is looking towards real-world applications with Willow. Quantum computing will benefit AI. I will synthesize these points into a concise summary. Step 2: Translate the summary into Spanish. Once I have the summary in English, I will translate it into Spanish. I need to ensure the translation is accurate and natural-sounding in Spanish. Step 3: Extract the key entities from the Spanish summary. After translating the summary, I will identify and extract the key entities. Key entities are typically nouns or noun phrases that represent important objects, concepts, or actors. In this context, they will likely include: Names of chips (Willow, Sycamore) Companies/Organizations (Google Quantum AI, Google Research) Technologies (quantum chip, quantum computer, qubits, quantum error correction, superconducting quantum system, classical computers, supercomputers, AI) Benchmarks (random circuit sampling, RCS) People (Julian Kelly, Peter Shor, David Deutsch, Sergio Boixo, Hartmut Neven, John Preskill) Concepts (exponential error reduction, below threshold, beyond breakeven, state-of-the-art performance, commercially relevant applications, quantum mechanics, multiverse, T1 times, system benchmarks, algorithmic benchmarks) I will need to carefully review the Spanish summary to identify these entities and list them out. |
Provide corrective feedback
If you find errors or inconsistencies in the model's reasoning, provide corrective feedback in your prompt or system instructions. This helps you guide the model toward your desired outcome.
You are an expert in botany. When asked to identify a plant, focus on leaf shape, flower structure, and stem characteristics. Identify this plant based on these characteristics: ... [Plant Characteristics Description] ... Previous incorrect response focused on habitat only. Please disregard habitat and focus on morphology. Previous incorrect response focused on habitat only. Please disregard habitat and focus on morphology. Tabebuia vellosoi |
處理長篇輸出內容和長篇思考
思考功能會在權杖輸出內容中產生「想法」,顯示模型的詳細推理過程。如要充分運用這些輸出內容,請注意以下幾點:
查看原因
在 Vertex AI Studio 使用者介面中,查看模型的推理過程,瞭解模型如何分解工作及所做的選擇。這有助於瞭解 AI 如何得出結論。
引導推理過程
如果輸出內容很長,建議在提示中提供更多指引。這樣一來,完成工作所需的思考量就會受到限制,並為回覆保留更多詞元輸出。
範例:如要取得詳細報表,您可以在提示中指定章節和子章節,引導模型思考並有效率地建構輸出內容。
Generate a detailed report on the impact of climate change on coastal ecosystems. Report Structure: Introduction Rising Sea Levels 2.1. Impact on Mangroves 2.2. Impact on Coral Reefs Ocean Acidification 3.1. Impact on Shellfish 3.2. Impact on Plankton Extreme Weather Events 4.1. Increased Storm Intensity 4.2. Coastal Erosion Conclusion Provide detailed analysis within each section. <...> Climate Change Impact on Coastal Ecosystems: A Detailed Report 1. Introduction Coastal ecosystems, the dynamic interface between land and sea, are among the most productive and biodiverse environments on Earth. They provide crucial ecosystem services, including coastal protection, fisheries, carbon sequestration, and support for a vast array of species. However, these vital ecosystems are increasingly threatened by the multifaceted impacts of climate change. Driven by anthropogenic greenhouse gas emissions, climate change is manifesting in several interconnected ways that are profoundly altering the physical and chemical conditions of coastal environments. This report will delve into the key impacts of climate change on coastal ecosystems, focusing on rising sea levels, ocean acidification, and extreme weather events, and their specific consequences for critical habitats like mangroves and coral reefs, and key organisms like shellfish and plankton. Understanding these impacts is crucial for developing effective conservation and management strategies to mitigate the damage and enhance the resilience of these invaluable ecosystems. 2. Rising Sea Levels Rising sea levels are a direct and significant consequence of global warming, driven by thermal expansion of seawater and the melting of land ice (glaciers and ice sheets). This phenomenon poses a direct threat to low-lying coastal ecosystems by inundating habitats, altering salinity regimes, and increasing erosion rates. The rate of sea level rise is accelerating, and projections for the 21st century indicate a continued upward trend, with potentially devastating consequences for coastal environments. 2.1. Impact on Mangroves Mangrove forests are unique coastal ecosystems found in tropical and subtropical intertidal zones. They provide numerous benefits, including coastal protection against storms, nursery grounds for fish and invertebrates, and significant carbon sequestration... <...> |
後續步驟
請嘗試在 Colab 筆記本中使用思考模型,或開啟 Vertex AI 控制台,自行提示模型。