fix(evals): Use cast instead of parse, fix batch spans#4890
fix(evals): Use cast instead of parse, fix batch spans#4890
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request streamlines the evaluation process by replacing explicit Zod parsing with direct type casting for certain data structures, simplifying data validation. It also significantly enhances observability for batch evaluations by introducing more granular tracing, ensuring each test case within a batch is individually tracked. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request replaces parse with type assertions in several places within the genkit-tools/common/src/eval/evaluate.ts and js/ai/src/evaluator.ts files. It also removes an unused import and refactors the batch processing logic in js/ai/src/evaluator.ts to improve span creation and error handling.
| throw new Error(`Dataset ${datasetId} is empty`); | ||
| } | ||
| inferenceDataset = DatasetSchema.parse(dataset); | ||
| inferenceDataset = dataset as Dataset; |
There was a problem hiding this comment.
high: Using a type assertion here bypasses the validation provided by DatasetSchema.parse. While this might improve performance, it removes a layer of safety and could lead to runtime errors if the data doesn't conform to the expected schema. Consider adding a comment explaining why the validation is skipped and ensuring that the data source is trusted or validated elsewhere.
| inferenceDataset = dataset as Dataset; | |
| inferenceDataset = dataset as Dataset; // Skipping schema validation for performance, ensure data is validated elsewhere |
| testCaseId: sample.testCaseId ?? generateTestCaseId(), | ||
| })); | ||
| inferenceDataset = DatasetSchema.parse(rawData); | ||
| inferenceDataset = rawData as Dataset; |
There was a problem hiding this comment.
high: Similar to the previous comment, this type assertion bypasses schema validation. Ensure that rawData conforms to the Dataset type or consider validating it before the assertion.
| inferenceDataset = rawData as Dataset; | |
| inferenceDataset = rawData as Dataset; // Skipping schema validation for performance, ensure data is validated elsewhere |
| renderedPrompt = { | ||
| traceId: runActionResponse.telemetry?.traceId!, | ||
| result: GenerateActionOptionsSchema.parse(runActionResponse.result), | ||
| result: runActionResponse.result as GenerateActionOptions, |
There was a problem hiding this comment.
high: This type assertion bypasses the validation provided by GenerateActionOptionsSchema.parse. Ensure that runActionResponse.result conforms to the GenerateActionOptions type or consider validating it before the assertion.
result: runActionResponse.result as GenerateActionOptions; // Skipping schema validation for performance, ensure data is validated elsewhere|
|
||
| function getErrorFromModelResponse(obj: any): string | undefined { | ||
| const response = GenerateResponseSchema.parse(obj); | ||
| const response = obj as GenerateResponseData; |
There was a problem hiding this comment.
high: This type assertion bypasses the validation provided by GenerateResponseSchema.parse. Ensure that obj conforms to the GenerateResponseData type or consider validating it before the assertion.
const response = obj as GenerateResponseData; // Skipping schema validation for performance, ensure data is validated elsewhere| batchMetadata?: any | ||
| ): Promise<EvalResponses> { |
| if (batchMetadata) { | ||
| batchMetadata.input = batch; | ||
| } |
There was a problem hiding this comment.
MichaelDoyle
left a comment
There was a problem hiding this comment.
LGTM. What was the reason for the casting change, btw?
Checklist (if applicable):