-
Notifications
You must be signed in to change notification settings - Fork 4
fix(evals): infer task input types from eval data #281
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
Merged
+147
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ce7151
fix(evals): infer task input types from eval data
c-ehrlich cc49914
fix(evals): avoid scorer-driven input inference
c-ehrlich 367a019
add another test
c-ehrlich 9f8d283
add ts peer dep
c-ehrlich 3331a1c
another test
c-ehrlich ee92aa6
fix(ai): mark typescript peer dependency optional
c-ehrlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import { describe, it, expectTypeOf } from 'vitest'; | ||
| import { Eval } from '../../src/evals'; | ||
| import { Scorer } from '../../src/scorers/scorers'; | ||
|
|
||
| describe('Eval type inference', () => { | ||
| it('infers task input and expected from data when scorer omits input', () => { | ||
| const answerSimilarityScorer = Scorer( | ||
| 'answer-similarity', | ||
| ({ output, expected }: { output: string; expected: string }) => { | ||
| output; | ||
| expected; | ||
| return 1; | ||
| }, | ||
| ); | ||
|
|
||
| const compileOnly = () => | ||
| Eval('name-apl-query', { | ||
| capability: 'name_query', | ||
| data: () => [ | ||
| { | ||
| input: "['nginx-access-logs'] | where status >= 500", | ||
| expected: 'Nginx 5xx Errors', | ||
| }, | ||
| ], | ||
| task: async ({ input }: { input: string }) => input, | ||
| scorers: [answerSimilarityScorer], | ||
| }); | ||
|
|
||
| compileOnly; | ||
| }); | ||
|
|
||
| it('preserves contextual task input typing from data when scorer omits input', () => { | ||
| const exactMatch = Scorer( | ||
| 'exact-match', | ||
| ({ expected, output }: { expected: string; output: string }) => expected === output, | ||
| ); | ||
|
|
||
| const compileOnly = () => | ||
| Eval('categorize-messages', { | ||
| capability: 'support-agent', | ||
| data: [ | ||
| { | ||
| input: 'Hello world', | ||
| expected: 'support', | ||
| }, | ||
| ], | ||
| task: ({ input }) => { | ||
| expectTypeOf(input).toEqualTypeOf<string>(); | ||
| return input; | ||
| }, | ||
| scorers: [exactMatch], | ||
| }); | ||
|
|
||
| compileOnly; | ||
| }); | ||
|
|
||
| it('keeps structured task input inference anchored to data when scorers only use output', () => { | ||
| const queueMatchScorer = Scorer( | ||
| 'queue-match', | ||
| ({ expected, output }: { expected: { queue: string }; output: { queue: string } }) => | ||
| expected.queue === output.queue, | ||
| ); | ||
|
|
||
| const compileOnly = () => | ||
| Eval('route-support-ticket', { | ||
| capability: 'support-routing', | ||
| data: [ | ||
| { | ||
| input: { | ||
| ticketId: 'ticket-123', | ||
| message: 'Need help with a refund', | ||
| customer: { | ||
| tier: 'enterprise' as const, | ||
| }, | ||
| }, | ||
| expected: { | ||
| queue: 'billing' as const, | ||
| }, | ||
| }, | ||
| ], | ||
| task: ({ input, expected }) => { | ||
| expectTypeOf(input.ticketId).toEqualTypeOf<string>(); | ||
| expectTypeOf(input.customer.tier).toEqualTypeOf<'enterprise'>(); | ||
| expectTypeOf(expected.queue).toEqualTypeOf<'billing'>(); | ||
|
|
||
| return { | ||
| queue: input.customer.tier === 'enterprise' ? 'billing' : 'general', | ||
| }; | ||
| }, | ||
| scorers: [queueMatchScorer], | ||
| }); | ||
|
|
||
| compileOnly; | ||
| }); | ||
|
|
||
| it('rejects task input that conflicts with the data source', () => { | ||
| const OutputOnlyScorer = Scorer( | ||
| 'output-only', | ||
| ({ output }: { output: string }) => output.length > 0, | ||
| ); | ||
|
|
||
| const invalid = () => | ||
| Eval('mismatched-task-input', { | ||
| capability: 'name_query', | ||
| // @ts-expect-error task input must match the data input type | ||
| data: () => [ | ||
| { | ||
| input: 'foo', | ||
| expected: 'bar', | ||
| }, | ||
| ], | ||
| task: async ({ input }: { input: number }) => String(input), | ||
| scorers: [OutputOnlyScorer], | ||
| }); | ||
|
|
||
| invalid; | ||
| }); | ||
|
|
||
| it('rejects a scorer whose input type conflicts with data', () => { | ||
| const inputAwareScorer = Scorer( | ||
| 'input-aware', | ||
| ({ input, output }: { input: { id: number }; output: string }) => { | ||
| return input.id > 0 && output.length > 0; | ||
| }, | ||
| ); | ||
|
|
||
| const invalid = () => | ||
| Eval('scorer-input-mismatch', { | ||
| capability: 'test', | ||
| data: [{ input: 'hello', expected: 'world' }], | ||
| task: ({ input }) => input, | ||
| // @ts-expect-error scorer input type conflicts with data input type | ||
| scorers: [inputAwareScorer], | ||
| }); | ||
|
|
||
| invalid; | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.