Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openjudge/generator/llm_grader_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async def generate(self, dataset: List[dict], **kwargs) -> LLMGrader:
rubrics = await self._generate_rubrics(dataset, **kwargs)
return LLMGrader(
model=self.config.model, # type: ignore
name=self.config.grader_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding the name parameter is correct, the surrounding type: ignore comments are concerning as they can hide potential runtime bugs. For instance, self.config.model can be None, but LLMGrader requires a model and will raise an error. The type: ignore comments are likely necessary because the type of self.config is not being correctly inferred as LLMGraderGeneratorConfig.

To improve type safety and make the code more robust, this block could be refactored. Since this is a pre-existing issue, it could be addressed in a follow-up, but here is an example of how it could be improved:

from typing import cast

...
async def generate(self, dataset: List[dict], **kwargs) -> LLMGrader:
    config = cast(LLMGraderGeneratorConfig, self.config)

    if not config.model:
        raise ValueError("LLMGraderGenerator requires a model to be configured.")
    if not config.custom_evaluation_prompt:
        raise ValueError("LLMGraderGenerator requires a custom_evaluation_prompt to be configured.")

    rubrics = await self._generate_rubrics(dataset, **kwargs)
    return LLMGrader(
        model=config.model,
        name=config.grader_name,
        mode=config.grader_mode,
        template=config.custom_evaluation_prompt,
        rubrics=rubrics,
    )

This change would provide proper type inference, allow for the removal of the type: ignore comments, and add necessary guards against None values.

mode=self.config.grader_mode, # type: ignore
template=self.config.custom_evaluation_prompt, # type: ignore
rubrics=rubrics,
Expand Down