getScorerById()
getScorerById() メソッドは、登録キーではなく Scorer の id プロパティ(見つからない場合は name プロパティ)を検索して取得します。Scorer の id は分かっていても、Mastra インスタンスへの登録方法が分からない場合に便利です。
使用例使用例への直接リンク
import { mastra } from './mastra'
// Get a scorer by its id property
const relevancyScorer = mastra.getScorerById('answer-relevancy-scorer')
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,
},
},
})
パラメーターパラメーターへの直接リンク
id:
string
取得する Scorer の id プロパティ。createScorer() で Scorer を作成したときに指定した 'id' フィールドと一致する必要があります。見つからない場合は 'name' プロパティも検索します。
戻り値戻り値への直接リンク
scorer:
MastraScorer
一致する id(または name)プロパティを持つ MastraScorer インスタンス。
エラー処理エラー処理への直接リンク
次の場合、このメソッドは MastraError をスローします。
- 指定した id の Scorer が見つからない
- Mastra インスタンスに Scorer が登録されていない
try {
const scorer = mastra.getScorerById('non-existent-scorer')
} catch (error) {
if (error.id === 'MASTRA_GET_SCORER_BY_ID_NOT_FOUND') {
console.log('Scorer with that id not found')
}
}
関連項目関連項目への直接リンク
- getScorer(): 登録キーで Scorer を取得
- listScorers(): 登録済みのすべての Scorer を取得
- createScorer(): ID を指定した Scorer の作成方法