examples/basics/scorers/tone-consistency/README.md
This example demonstrates how to use Mastra's Tone Scorer to evaluate emotional tone patterns and sentiment consistency between input and output text.
Clone the repository and navigate to the project directory:
git clone https://github.com/mastra-ai/mastra
cd examples/basics/scorers/tone-consistency
Install dependencies:
pnpm install --ignore-workspace
Run the example:
pnpm start
The Tone Scorer evaluates emotional tone and sentiment consistency in text by analyzing sentiment patterns and emotional alignment. It operates in different modes:
The scorer uses sentiment analysis algorithms to detect emotional tone and calculate consistency scores.
The example includes three scenarios:
Each scenario demonstrates:
The example will output:
createToneScorer: Function that creates the tone scorer instancescorer.run(): Method to evaluate input/output pairs for tone consistency
{ input, output } where:
input: Array of chat messages (e.g., [{ role: 'user', content: 'text' }])output: Response object (e.g., { role: 'assistant', text: 'response' })score: Numerical consistency score (0-1)analyzeStepResult: Detailed tone analysis including sentiment scores and consistency metrics