examples/basics/scorers/custom-scorer/README.md
This example demonstrates how to create a custom Scorer in Mastra to check recipes for gluten content.
Clone the repository and navigate to the project directory:
git clone https://github.com/mastra-ai/mastra
cd examples/basics/scorers/custom-scorer
Copy the environment variables file and add your OpenAI API key:
cp .env.example .env
Then edit .env and add your OpenAI API key:
OPENAI_API_KEY=sk-your-api-key-here
Install dependencies:
pnpm install --ignore-workspace
Run the example script:
pnpm start
This example shows how to create a custom scorer to evaluate recipes for gluten content. It demonstrates:
The example includes two scenarios:
Each evaluation provides:
The example will output:
Example 1 - Recipe with Gluten:
Input: "Can you give me a simple pasta recipe with exact measurements and timing?"
Agent Response: [Recipe details...]
Result: {
score: 0,
glutenSources: ["pasta"],
reason: "The recipe contains gluten from pasta."
}
Example 2 - Gluten-Free Recipe:
Input: "What is a quick way to make rice and beans?"
Agent Response: [Recipe details...]
Result: {
score: 1,
glutenSources: [],
reason: "The recipe is gluten-free as rice and beans do not contain gluten."
}
glutenCheckerScorer: LLM-based scorer for evaluating gluten content in recipes