您可以使用 Gen AI 評估服務,根據自己的標準,評估大型語言模型 (LLM) 的多項指標。您可以提供推論時間輸入內容、LLM 回覆和其他參數,而生成式 AI 評估服務會傳回評估工作專屬的指標。
指標包括模型指標 (例如 PointwiseMetric
和 PairwiseMetric
) 和記憶體中計算的指標 (例如 rouge
、bleu
和工具函式呼叫指標)。PointwiseMetric
和 PairwiseMetric
是一般模型指標,您可以根據自己的條件自訂。由於這項服務會直接將模型的預測結果做為輸入內容,因此評估服務可針對 Vertex AI 支援的所有模型執行推論和後續評估。
如要進一步瞭解如何評估模型,請參閱「生成式 AI 評估服務總覽」。
限制
以下是評估服務的限制:
- 評估服務在第一次呼叫時可能會延遲傳播。
- 大部分以模型為基礎的指標都會消耗 gemini-2.0-flash 配額,因為 Gen AI 評估服務會利用
gemini-2.0-flash
做為基礎判斷模型,用於計算這些以模型為基礎的指標。 - 某些以模型為基礎的指標 (例如 MetricX 和 COMET) 會使用不同的機器學習模型,因此不會消耗 gemini-2.0-flash 配額。
語法範例
傳送評估呼叫的語法。
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}:evaluateInstances \ -d '{ "pointwise_metric_input" : { "metric_spec" : { ... }, "instance": { ... }, } }'
Python
import json from google import auth from google.api_core import exceptions from google.auth.transport import requests as google_auth_requests creds, _ = auth.default( scopes=['https://www.googleapis.com/auth/cloud-platform']) data = { ... } uri = f'https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}:evaluateInstances' result = google_auth_requests.AuthorizedSession(creds).post(uri, json=data) print(json.dumps(result.json(), indent=2))
參數清單
參數 | |
---|---|
|
選用: 輸入值,用於評估預測值是否與參考值完全相符。 |
|
選用: 輸入內容,藉由比較預測結果與參考內容來計算 BLEU 分數。 |
|
選用: 輸入資料,比較預測結果與參考值,以便計算 |
|
選用: 輸入內容,以便評估單一回覆的語言精通程度。 |
|
選用: 輸入內容,以便評估單一回覆是否能提供連貫、易懂的回覆。 |
|
選用: 用於評估單一回覆的安全性等級。 |
|
選用: 輸入內容,用於評估單一回應是否能提供或參照輸入文字中包含的資訊。 |
|
選用: 輸入內容,用於評估單一回覆是否能完全執行指示。 |
|
選用: 輸入內容,以便評估單一回應總結文字的重點能力。 |
|
選用: 輸入內容,比較兩個回覆的整體摘要品質。 |
|
選用: 輸入內容,用於評估單一回覆是否能提供摘要,其中包含用於取代原始文字的必要詳細資料。 |
|
選用: 輸入內容,以評估單一回覆是否能提供簡潔的摘要。 |
|
選用: 輸入內容,以便在參考文字內容的情況下,評估單一回覆的整體答題能力。 |
|
選用: 輸入內容,以便比較兩個回覆的整體答題能力,並提供可供參考的文字內容。 |
|
選用: 輸入內容可評估單一回覆在回答問題時,提供相關資訊的能力。 |
|
選用: 輸入內容,以評估單一回覆在回答問題時提供重要詳細資料的能力。 |
|
選用: 輸入內容,以評估單一回覆是否能正確回答問題。 |
|
選用: 一般逐點評估的輸入內容。 |
|
選用: 一般逐對評估的輸入內容。 |
|
選用: 輸入內容,用於評估單一回覆是否能預測有效的工具呼叫。 |
|
選用: 輸入內容,用於評估單一回覆是否能預測工具呼叫,並使用正確的工具名稱。 |
|
選用: 輸入內容,用於評估單一回覆是否能預測工具呼叫的正確參數名稱。 |
|
選用: 輸入內容:評估單一回應是否能使用正確的參數名稱和值預測工具呼叫 |
|
選用: 使用 COMET 評估的輸入內容。 |
|
選用: 使用 MetricX 評估的輸入內容。 |
ExactMatchInput
{ "exact_match_input": { "metric_spec": {}, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: LLM 回覆。 |
|
選用: 可供參考的 LLM 黃金回覆。 |
ExactMatchResults
{ "exact_match_results": { "exact_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
每個輸入例項的評估結果。 |
|
可以是下列其中一項:
|
BleuInput
{ "bleu_input": { "metric_spec": { "use_effective_order": bool }, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 是否要考慮沒有任何相符項目的 n-gram 順序。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: LLM 回覆。 |
|
選用: 可供參考的 LLM 黃金回覆。 |
BleuResults
{ "bleu_results": { "bleu_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
每個輸入例項的評估結果。 |
|
|
RougeInput
{ "rouge_input": { "metric_spec": { "rouge_type": string, "use_stemmer": bool, "split_summaries": bool }, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 可接受的值:
|
|
選用: 是否應使用 Porter stemmer 去除字詞後置字元,以便改善比對結果。 |
|
選用: 是否要為 rougeLsum 在句子之間加入換行符號。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: LLM 回覆。 |
|
選用: 可供參考的 LLM 黃金回覆。 |
RougeResults
{ "rouge_results": { "rouge_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
每個輸入例項的評估結果。 |
|
|
FluencyInput
{ "fluency_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含 LLM 回覆。 |
|
選用: LLM 回覆。 |
FluencyResult
{ "fluency_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
CoherenceInput
{ "coherence_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含 LLM 回覆。 |
|
選用: LLM 回覆。 |
CoherenceResult
{ "coherence_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
SafetyInput
{ "safety_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含 LLM 回覆。 |
|
選用: LLM 回覆。 |
SafetyResult
{ "safety_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
GroundednessInput
{ "groundedness_input": { "metric_spec": {}, "instance": { "prediction": string, "context": string } } }
參數 |
說明 |
|
選用:GroundednessSpec 指標規格,定義指標的行為。 |
|
選用:GroundednessInstance 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
GroundednessResult
{ "groundedness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
FulfillmentInput
{ "fulfillment_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
FulfillmentResult
{ "fulfillment_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
SummarizationQualityInput
{ "summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
SummarizationQualityResult
{ "summarization_quality_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
PairwiseSummarizationQualityInput
{ "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "baseline_prediction": string, "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: 基準模型 LLM 回覆。 |
|
選用: 候選模型 LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
PairwiseSummarizationQualityResult
{ "pairwise_summarization_quality_result": { "pairwise_choice": PairwiseChoice, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
SummarizationHelpfulnessInput
{ "summarization_helpfulness_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
SummarizationHelpfulnessResult
{ "summarization_helpfulness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
SummarizationVerbosityInput
{ "summarization_verbosity_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
SummarizationVerbosityResult
{ "summarization_verbosity_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringQualityInput
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
QuestionAnsweringQualityResult
{ "question_answering_quality_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
PairwiseQuestionAnsweringQualityInput
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "baseline_prediction": string, "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: 基準模型 LLM 回覆。 |
|
選用: 候選模型 LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
PairwiseQuestionAnsweringQualityResult
{ "pairwise_question_answering_quality_result": { "pairwise_choice": PairwiseChoice, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringRelevanceInput
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
QuestionAnsweringRelevancyResult
{ "question_answering_relevancy_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringHelpfulnessInput
{ "question_answering_helpfulness_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
QuestionAnsweringHelpfulnessResult
{ "question_answering_helpfulness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringCorrectnessInput
{ "question_answering_correctness_input": { "metric_spec": { "use_reference": bool }, "instance": { "prediction": string, "reference": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估是否使用參考資料。 |
|
選用: 評估輸入內容,包含推論輸入內容和相應回應。 |
|
選用: LLM 回覆。 |
|
選用: 可供參考的 LLM 黃金回覆。 |
|
選用: 推論期間使用的指令。 |
|
選用: 包含所有資訊的推論時間文字,可用於 LLM 回覆。 |
QuestionAnsweringCorrectnessResult
{ "question_answering_correctness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
PointwiseMetricInput
{ "pointwise_metric_input": { "metric_spec": { "metric_prompt_template": string }, "instance": { "json_instance": string, } } }
參數 | |
---|---|
|
必要項目: 指標規格,定義指標的行為。 |
|
必要項目: 定義指標的提示範本。此值會根據 instance.json_instance 中的鍵/值組合呈現 |
|
必要項目: 評估輸入內容,包含 json_instance。 |
|
選用: 以 JSON 格式呈現的鍵/值組合。例如:{"key_1": "value_1", "key_2": "value_2"}。用於轉譯 metric_spec.metric_prompt_template。 |
PointwiseMetricResult
{ "pointwise_metric_result": { "score": float, "explanation": string, } }
輸出 | |
---|---|
|
|
|
|
PairwiseMetricInput
{ "pairwise_metric_input": { "metric_spec": { "metric_prompt_template": string }, "instance": { "json_instance": string, } } }
參數 | |
---|---|
|
必要項目: 指標規格,定義指標的行為。 |
|
必要項目: 定義指標的提示範本。此值會根據 instance.json_instance 中的鍵/值組合呈現 |
|
必要項目: 評估輸入內容,包含 json_instance。 |
|
選用: 以 JSON 格式呈現的鍵/值組合。例如:{"key_1": "value_1", "key_2": "value_2"}。用於轉譯 metric_spec.metric_prompt_template。 |
PairwiseMetricResult
{ "pairwise_metric_result": { "score": float, "explanation": string, } }
輸出 | |
---|---|
|
|
|
|
ToolCallValidInput
{ "tool_call_valid_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: 候選模型 LLM 回應,這是包含 { "content": "", "tool_calls": [ { "name": "book_tickets", "arguments": { "movie": "Mission Impossible Dead Reckoning Part 1", "theater": "Regal Edwards 14", "location": "Mountain View CA", "showtime": "7:30", "date": "2024-03-30", "num_tix": "2" } } ] } |
|
選用: 與預測結果相同格式的黃金模型輸出內容。 |
ToolCallValidResults
{ "tool_call_valid_results": { "tool_call_valid_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
重複 |
|
|
ToolNameMatchInput
{ "tool_name_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: 候選模型 LLM 回應,這是包含 |
|
選用: 與預測結果相同格式的黃金模型輸出內容。 |
ToolNameMatchResults
{ "tool_name_match_results": { "tool_name_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
重複 |
|
|
ToolParameterKeyMatchInput
{ "tool_parameter_key_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: 候選模型 LLM 回應,這是包含 |
|
選用: 與預測結果相同格式的黃金模型輸出內容。 |
ToolParameterKeyMatchResults
{ "tool_parameter_key_match_results": { "tool_parameter_key_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
重複 |
|
|
ToolParameterKVMatchInput
{ "tool_parameter_kv_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
選用: 候選模型 LLM 回應,這是包含 |
|
選用: 與預測結果相同格式的黃金模型輸出內容。 |
ToolParameterKVMatchResults
{ "tool_parameter_kv_match_results": { "tool_parameter_kv_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
重複 |
|
|
CometInput
{ "comet_input" : { "metric_spec" : { "version": string }, "instance": { "prediction": string, "source": string, "reference": string, }, } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選用:
|
|
選用: 以 BCP-47 格式輸入原始語言。例如「es」。 |
|
選用: 以 BCP-47 格式輸入目標語言。例如「es」 |
|
選用: 評估輸入內容,包含 LLM 回覆和參考資料。用於評估的確切欄位取決於 COMET 版本。 |
|
選用: 候選模型 LLM 回覆。這是正在評估的 LLM 輸出內容。 |
|
選用: 原文內容。這是系統預測的內容所使用的原始語言。 |
|
選用: 用於比較預測結果的基準真相。與預測內容使用相同語言。 |
CometResult
{ "comet_result" : { "score": float } }
輸出 | |
---|---|
|
|
MetricxInput
{ "metricx_input" : { "metric_spec" : { "version": string }, "instance": { "prediction": string, "source": string, "reference": string, }, } }
參數 | |
---|---|
|
選用: 指標規格,定義指標的行為。 |
|
選填:
可以是下列其中一項:
|
|
選用: 以 BCP-47 格式輸入原始語言。例如「es」。 |
|
選用: 以 BCP-47 格式輸入目標語言。例如「es」。 |
|
選用: 評估輸入內容,包含 LLM 回覆和參考資料。用於評估的確切欄位取決於 MetricX 版本。 |
|
選用: 候選模型 LLM 回覆。這是正在評估的 LLM 輸出內容。 |
|
選用: 預測結果的來源文字,也就是系統翻譯的來源語言。 |
|
選用: 用於比較預測結果的基準真相。與預測內容使用相同語言。 |
MetricxResult
{ "metricx_result" : { "score": float } }
輸出 | |
---|---|
|
|
範例
評估輸出內容
以下範例說明如何呼叫 Gen AI Evaluation API,以各種評估指標評估 LLM 的輸出內容,包括:
summarization_quality
groundedness
fulfillment
summarization_helpfulness
summarization_verbosity
Python
Go
評估輸出內容:成對摘要品質
以下範例示範如何呼叫 Gen AI 評估服務 API,以成對摘要品質比較方式評估 LLM 的輸出內容。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- PREDICTION:大型語言模型回應。
- BASELINE_PREDICTION:基準模型 LLM 回覆。
- INSTRUCTION:在推論期間使用的指令。
- CONTEXT:推論時間文字,包含可用於 LLM 回覆的所有相關資訊。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \
JSON 要求主體:
{ "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": "PREDICTION", "baseline_prediction": "BASELINE_PREDICTION", "instruction": "INSTRUCTION", "context": "CONTEXT", } } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \" | Select-Object -Expand Content
Python
Python 適用的 Vertex AI SDK
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Vertex AI SDK for Python API 參考說明文件。
Go
Go
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Go。詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
取得 ROUGE 分數
以下範例會呼叫 Gen AI 評估服務 API,取得多個輸入內容產生的預測結果 ROUGE 分數。ROUGE 輸入會使用 metric_spec
,用來決定指標的行為。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的專案 ID。
- LOCATION:處理要求的區域。
- PREDICTION:大型語言模型回應。
- REFERENCE:用於參考的 LLM 黃金回應。
- ROUGE_TYPE:用於判斷 Rouge 分數的計算方式。如要查看可接受的值,請參閱
metric_spec.rouge_type
。 - USE_STEMMER:決定是否要使用 Porter 字根詞去除字尾,以便改善比對結果。如需接受的值,請參閱
metric_spec.use_stemmer
。 - SPLIT_SUMMARIES:決定是否要在
rougeLsum
句之間新增行。如需接受的值,請參閱metric_spec.split_summaries
。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \
JSON 要求主體:
{ "rouge_input": { "instances": { "prediction": "PREDICTION", "reference": "REFERENCE.", }, "metric_spec": { "rouge_type": "ROUGE_TYPE", "use_stemmer": USE_STEMMER, "split_summaries": SPLIT_SUMMARIES, } } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \" | Select-Object -Expand Content
Python
Python 適用的 Vertex AI SDK
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Vertex AI SDK for Python API 參考說明文件。
Go
Go
在試用這個範例之前,請先按照 Vertex AI 快速入門:使用用戶端程式庫中的操作說明設定 Go。詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
後續步驟
- 如需詳細說明文件,請參閱「執行評估」。