Skip to content

Expose templates of LLM grader instances and default templates of LLM grader classes.#124

Open
weizhang25 wants to merge 1 commit intoagentscope-ai:mainfrom
weizhang25:expose-templates-and-default-templates-of-llm-graders
Open

Expose templates of LLM grader instances and default templates of LLM grader classes.#124
weizhang25 wants to merge 1 commit intoagentscope-ai:mainfrom
weizhang25:expose-templates-and-default-templates-of-llm-graders

Conversation

@weizhang25
Copy link
Collaborator

  1. Define get_template instance method in LLMGrader to expose the template of LLM grader instances.
  2. Define get_default_template class method in LLMGrader to expose the default templates of LLM grader classes.
  3. Updated UTs.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @weizhang25, 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 enhances the LLMGrader system by providing explicit methods to access both instance-specific and class-level default prompt templates. This change improves the introspection capabilities of the grading framework, allowing developers to easily inspect and understand the prompts used by different LLM graders, and establishes a clearer pattern for defining default templates in subclasses.

Highlights

  • Template Exposure: Introduced get_template instance method to retrieve the current prompt template of an LLMGrader instance.
  • Default Template Access: Added get_default_template class method to access the default prompt template for LLMGrader classes.
  • Template Consistency: Updated ActionAlignmentGrader to use a DEFAULT_TEMPLATE class variable for consistent default template definition.
  • Unit Test Enhancements: Enhanced unit tests to cover the new template exposure methods and enforce template validation during initialization.
Changelog
  • openjudge/graders/agent/action/action_alignment.py
    • Defined DEFAULT_TEMPLATE as a class attribute.
    • Updated the __init__ method to reference DEFAULT_TEMPLATE for the default prompt.
    • Modified the super().__init__ call to use self.DEFAULT_TEMPLATE when no template is provided.
  • openjudge/graders/llm_grader.py
    • Added a DEFAULT_TEMPLATE class attribute as a placeholder, with a comment instructing subclasses to override it.
    • Introduced a ValueError check in __init__ to ensure a template is always provided.
    • Implemented get_template instance method to return the grader's current template.
    • Implemented get_default_template class method to return the class's default template.
  • tests/graders/agent/action/test_action_alignment.py
    • Added assertions to test_initialization to verify get_template and get_default_template functionality and content.
    • Adjusted the pytestmark decorator application for quality tests.
  • tests/graders/test_llm_grader.py
    • Imported LanguageEnum.
    • Added a new test case test_initialization_failure_with_invalid_template_type to check for ValueError when an invalid template type is passed.
    • Extended test_initialization_with_model_dict to include assertions for get_template and get_default_template.
    • Adjusted the pytestmark decorator application for quality tests.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a way to expose templates from LLMGrader instances and classes. It adds a DEFAULT_TEMPLATE class attribute to LLMGrader and its subclasses, and two new methods: get_template() for instance-specific templates and get_default_template() for class-level default templates. The changes are well-implemented and include corresponding updates to unit tests. My main feedback is to consider enforcing that subclasses of LLMGrader override the DEFAULT_TEMPLATE attribute to prevent potential runtime issues.

Comment on lines +56 to +58
# The default template value is just a placeholder.
# Extended classes must set proper value to DEFAULT_TEMPLATE
DEFAULT_TEMPLATE = PromptTemplate(messages={})
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 the comment correctly states that extended classes must set DEFAULT_TEMPLATE, this is just a convention and not enforced. A developer creating a new subclass of LLMGrader might forget to override this, leading to a grader that uses an empty template, which will likely cause difficult-to-debug runtime errors.

To make this more robust, consider adding a check in LLMGrader.__init__ to ensure that subclasses have overridden DEFAULT_TEMPLATE. For example:

# In LLMGrader.__init__
if type(self) is not LLMGrader and self.DEFAULT_TEMPLATE is LLMGrader.DEFAULT_TEMPLATE:
    raise NotImplementedError(
        f"{type(self).__name__} must override the 'DEFAULT_TEMPLATE' class attribute."
    )

This would make the class hierarchy safer and improve the developer experience when extending LLMGrader.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do when I update all the sub classes of LLMGrader,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant