UNPKG

@mastra/core

Version:
1 lines 2.84 kB
{"version":3,"file":"index.cjs","names":["Agent","isSupportedLanguageModel"],"sources":["../../src/relevance/relevance-score-provider.ts","../../src/relevance/mastra-agent/index.ts"],"sourcesContent":["// Provider interfaces\nexport interface RelevanceScoreProvider {\n getRelevanceScore(text1: string, text2: string): Promise<number>;\n}\n\n// Helper function used by providers\nexport function createSimilarityPrompt(query: string, text: string): string {\n return `Rate the semantic similarity between the following the query and the text on a scale from 0 to 1 (decimals allowed), where 1 means exactly the same meaning and 0 means completely different:\n\nQuery: ${query}\n\nText: ${text}\n\nRelevance score (0-1):`;\n}\n","import { Agent, isSupportedLanguageModel } from '../../agent';\nimport type { MastraModelConfig } from '../../llm/model/shared.types';\nimport { createSimilarityPrompt } from '../relevance-score-provider';\nimport type { RelevanceScoreProvider } from '../relevance-score-provider';\n\n// Mastra Agent implementation\nexport class MastraAgentRelevanceScorer implements RelevanceScoreProvider {\n private agent: Agent;\n\n constructor(name: string, model: MastraModelConfig) {\n this.agent = new Agent({\n id: `relevance-scorer-${name}`,\n name: `Relevance Scorer ${name}`,\n instructions: `You are a specialized agent for evaluating the relevance of text to queries.\nYour task is to rate how well a text passage answers a given query.\nOutput only a number between 0 and 1, where:\n1.0 = Perfectly relevant, directly answers the query\n0.0 = Completely irrelevant\nConsider:\n- Direct relevance to the question\n- Completeness of information\n- Quality and specificity\nAlways return just the number, no explanation.`,\n model,\n });\n }\n\n async getRelevanceScore(query: string, text: string): Promise<number> {\n const prompt = createSimilarityPrompt(query, text);\n\n const model = await this.agent.getModel();\n\n let response: string;\n if (isSupportedLanguageModel(model)) {\n const responseText = await this.agent.generate(prompt);\n response = responseText.text;\n } else {\n const responseText = await this.agent.generateLegacy(prompt);\n response = responseText.text;\n }\n return parseFloat(response);\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,uBAAuB,OAAe,MAAsB;CAC1E,OAAO;;SAEA,MAAM;;QAEP,KAAK;;;AAGb;;;ACRA,IAAa,6BAAb,MAA0E;CACxE;CAEA,YAAY,MAAc,OAA0B;EAClD,KAAK,QAAQ,IAAIA,cAAAA,MAAM;GACrB,IAAI,oBAAoB;GACxB,MAAM,oBAAoB;GAC1B,cAAc;;;;;;;;;;GAUd;EACF,CAAC;CACH;CAEA,MAAM,kBAAkB,OAAe,MAA+B;EACpE,MAAM,SAAS,uBAAuB,OAAO,IAAI;EAEjD,MAAM,QAAQ,MAAM,KAAK,MAAM,SAAS;EAExC,IAAI;EACJ,IAAIC,kBAAAA,yBAAyB,KAAK,GAEhC,YAAW,MADgB,KAAK,MAAM,SAAS,MAAM,EAAA,CAC7B;OAGxB,YAAW,MADgB,KAAK,MAAM,eAAe,MAAM,EAAA,CACnC;EAE1B,OAAO,WAAW,QAAQ;CAC5B;AACF"}