-
Notifications
You must be signed in to change notification settings - Fork 1
feat: better scorers #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: better scorers #106
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the scorer system to improve type inference and ergonomics. The key changes separate scorer definitions from usage requirements, introduce automatic type inference from function arguments, and simplify the API by removing the need for explicit type parameters in most cases.
- Introduces
ScorerLikefor flexible scorer consumption andScorerfor strict scorer definitions with anameproperty - Implements automatic type inference in
createScorerbased on the callback's argument types - Updates scorer factory to attach the name as a property instead of embedding it in the returned score
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ai/src/evals/scorers.ts | Separates Score and ScoreWithName types, introduces ScorerLike vs Scorer distinction with TExtra support |
| packages/ai/src/evals/scorer.factory.ts | Refactors createScorer to infer types from arguments and attach name as function property |
| packages/ai/test/evals/scorer.types.test.ts | Adds comprehensive type inference tests for the new scorer system |
| packages/ai/src/evals/eval.types.ts | Updates type references and strengthens OutputOf type constraints |
| packages/ai/src/evals/eval.ts | Updates to use ScorerLike and extract scorer name from function property |
| packages/ai/src/evals/builder.ts | Adds TODO comment about unused function |
| packages/ai/README.md | Documents Node version requirement for evals |
| examples/example-evals-nextjs/test/feature.eval.ts | Migrates to new Scorer factory pattern |
| examples/example-evals-nextjs/src/lib/scorers.ts | Updates scorers to use typed arguments and removes optional expected handling |
| examples/example-evals-nextjs/src/lib/capabilities/classify-ticket/evaluations/ticket-classification.eval.ts | Adds wrapped autoevals scorer example |
| .github/workflows/ci.yaml | Reorders CI steps to run format check before build |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change so we should probably merge it after your other PRs, potentially even have a release in between?
This PR improves the Scorer API, making it easier to use, more type-safe, and just in general bringing it in line with other APIs in the SDK.
Cleaner Scorer Definition with Type Inference
Before:
After:
Better types
Name Property on Scorer Functions
Scorer names are now attached to the function itself as a property:
This means users don't need to worry about returning it in the scorer.
The name is also included in scorer span names now, ie they will be something like
scorer exact-matchSupport for Custom Extra Parameters
Scorers can now accept additional custom parameters beyond
input,expected, andoutput:These type parameters are automatically inferred.
Better interop with
autoevalsscorersUsers now get
Unfortunately we can't make
autoevalsscorers plug and play, because their input/output args are all over the place.Examples
The
example-evals-nextjsscorers have been updated.Internal improvements
Score(without name) fromScoreWithName(internal use)createScorerfactory