> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # getScorer() `getScorer()` 方法依註冊鍵取得在 Mastra 執行個體中註冊的指定 Scorer。此方法提供對 Scorer 的類型安全存取;如果找不到所請求的 Scorer,則擲回錯誤。 ## 使用範例 ```typescript import { mastra } from './mastra' // Get a specific scorer by key const relevancyScorer = mastra.getScorer('relevancyScorer') const weatherAgent = mastra.getAgent('weatherAgent') // Use the scorer to evaluate an AI output await weatherAgent.generate('What is the weather in Rome', { scorers: { answerRelevancy: { scorer: relevancyScorer, }, }, }) ``` ## 參數 **key** (`string`): 要取得的 Scorer 的註冊鍵。它應與在 Mastra 建構函式中註冊 Scorer 時使用的鍵相符。 ## 傳回值 **scorer** (`MastraScorer`): 與所提供鍵關聯的 MastraScorer 執行個體。 ## 錯誤處理 以下情況會擲回 `MastraError`: - 找不到具有指定鍵的 Scorer - Mastra 執行個體未註冊任何 Scorer ```typescript try { const scorer = mastra.getScorer('nonExistentScorer') } catch (error) { if (error.id === 'MASTRA_GET_SCORER_NOT_FOUND') { console.log('Scorer not found, using default evaluation') } } ``` ## 相關內容 - [listScorers()](https://mastra.zisheng.pro/zh-TW/reference/core/listScorers): 取得所有已註冊的 Scorer - [getScorerById()](https://mastra.zisheng.pro/zh-TW/reference/core/getScorerById): 依 id 屬性取得 Scorer - [自訂 Scorer](https://mastra.zisheng.pro/zh-TW/docs/evals/custom-scorers): 瞭解如何建立自訂 Scorer