> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # getScorer() `getScorer()` 方法會使用註冊鍵,擷取已向 Mastra 執行個體註冊的指定評分器。此方法提供類型安全的評分器存取方式,如找不到所要求的評分器,則會擲回錯誤。 ## 使用範例 ```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`): 要擷取的評分器的註冊鍵。此鍵應與在 Mastra 建構函式中註冊評分器時使用的鍵相符。 ## 傳回值 **scorer** (`MastraScorer`): 與所提供鍵相關聯的 MastraScorer 執行個體。 ## 錯誤處理 在以下情況下,此方法會擲回 `MastraError`: - 找不到具有指定鍵的評分器 - 沒有向 Mastra 執行個體註冊任何評分器 ```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-HK/reference/core/listScorers):取得所有已註冊的評分器 - [getScorerById()](https://mastra.zisheng.pro/zh-HK/reference/core/getScorerById):按評分器的 id 屬性取得評分器 - [自訂評分器](https://mastra.zisheng.pro/zh-HK/docs/evals/custom-scorers):了解如何建立自訂評分器