使用零樣本最佳化工具,自動修正及改善提示。如果提示的語言含糊不清、缺少背景資訊或包含不相關的資訊,可能無法產生您想要的結果。這項工具會分析並改寫提示,讓提示更清楚、更有效,且更符合模型功能,進而產生品質更高的回覆。 零樣本最佳化工具適用於下列情境: 本頁說明如何使用零樣本提示最佳化工具,並包含下列章節: 最佳化工具的使用方法有兩種。下表比較這兩種方法。 最佳化工具可透過 Vertex AI SDK 使用,並支援 Gemini 支援的所有語言。以下範例說明如何呼叫最佳化工具: 以下為輸出範例:
零樣本最佳化工具的使用時機
選項
說明
用途
生成指令
根據您以簡單語言描述的目標,生成完整且結構良好的系統指令集。
需要從頭建立複雜的新提示,並確保提示結構良好。
修正提示
分析及改善現有提示,生成更一致、詳細或切題的回覆。
提示可正常運作,但模型輸出內容未達品質標準。
將提示最佳化
# Import libraries
import vertexai
import logging
# Google Colab authentication
from google.colab import auth
PROJECT_NAME = "PROJECT"
auth.authenticate_user(project_id=PROJECT_NAME)
# Initialize the Vertex AI client
client = vertexai.Client(project=PROJECT_NAME, location='us-central1')
# Input original prompt to optimize
prompt = """You are a professional chef. Your goal is teaching how to cook healthy cooking recipes to your apprentice.
Given a question from your apprentice and some context, provide the correct answer to the question.
Use the context to return a single and correct answer with some explanation.
"""
# Optimize prompt
output = client.prompt_optimizer.optimize_prompt(prompt=prompt)
瞭解輸出內容
output
物件是 OptimizeResponse
型別,包含最佳化程序的相關資訊。回應會包括下列重要欄位:
suggested_prompt
:經過最佳化的提示,可讓模型產生更優質的結果。applicable_guidelines
:說明系統改善提示的原因和方式,有助於你日後撰寫更優質的提示。{
"optimization_mode": "zero_shot",
"applicable_guidelines": [
{
"applicable_guideline": "Structure",
"suggested_improvement": "Add role definition.",
"text_before_change": "...",
"text_after_change": "Role: You are an AI assistant...\n\nTask Context:\n..."
},
{
"applicable_guideline": "RedundancyInstructions",
"suggested_improvement": "Remove redundant explanation.",
"text_before_change": "...",
"text_after_change": ""
}
],
"original_prompt": "...",
"suggested_prompt": "Role: You are an AI assistant...\n\nTask Context:\n..."
}
零樣本最佳化工具
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。