You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/langium-ai-tools/README.md
+292Lines changed: 292 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,298 @@ You can also define custom evaluators that are more tuned to the needs of your D
151
151
152
152
In general we stick to focusing on what Langium can do to help with evaluation, but leave the opportunity open for you to extend, supplement, or modify evaluation logic as you see fit.
153
153
154
+
### Evaluation Matrix
155
+
156
+
The Evaluation Matrix provides a framework for testing multiple model configurations against a set of test cases using Langium AI evaluators. This is particularly helpful when comparing across models, prompt strategies, RAG setups, or other variations in your AI stack.
157
+
158
+
In practice an evaluation matrix can be helpful when deciding between which models or services to use up front, but this can also be done externally by levering the evaluator directly yourself.
159
+
160
+
#### Overview
161
+
162
+
The evaluation matrix orchestrates three key components:
163
+
- **Runners**: Functions that execute prompts against models, services, or other response generators
164
+
- **Cases**: Test scenarios with expected outputs, which can be defined in code or loaded from YAML files
165
+
- **Evaluators**: Metrics that score actual responses against expected responses
166
+
167
+
The matrix fires off each runner against each test case, evaluates the results with all configured evaluators, and produces reports with aggregated metrics.
168
+
169
+
#### Runners
170
+
171
+
A runner is an interface that takes a prompt and message history, returning a response string. This serves as an abstraction so you can test your own setup as it stands
172
+
173
+
Runners can wrap:
174
+
- Direct model calls (Ollama, OpenAI, Anthropic, etc.)
175
+
- RAG pipelines with vector database lookups
176
+
- Multi-step agent workflows
177
+
- Really any system that produces some text output
178
+
179
+
```ts
180
+
import { type Runner, type Message } from'langium-ai-tools/evaluator';
description: 'Testing model performance on grammar generation',
420
+
history_folder: '.eval-results',
421
+
num_runs: 5
422
+
},
423
+
runners: [baseRunner],
424
+
evaluators: [{
425
+
name: 'Langium Evaluator',
426
+
eval: newLangiumEvaluator(services)
427
+
}],
428
+
cases
429
+
});
430
+
431
+
constresults=awaitmatrix.run();
432
+
433
+
// process and display results
434
+
constaveraged=averageAcrossCases(results);
435
+
console.log('\nAveraged Results:');
436
+
console.table(averaged.map(r=> ({
437
+
name: r.name,
438
+
errors: r.data.errors,
439
+
warnings: r.data.warnings,
440
+
runtime: r.data.runtime
441
+
})));
442
+
```
443
+
444
+
For more complete examples, see the [example-dsl-evaluator](../examples/example-dsl-evaluator) project.
445
+
154
446
## Contributing
155
447
156
448
If you want to help feel free to open an issue or a PR. As a general note we're open to accept changes that focus on improving how we can support AI application development for Langium DSLs. But we don't want to provide explicit bindings to actual services/providers at this time, such as LLamaIndex, Ollama, LangChain, or others. Similarly this package doesn't provide direct bindings for AI providers such as OpenAI and Anthropic here. Instead these changes will go into a separate package under Langium AI that is intended for this purpose.
0 commit comments