Skip to content

Set default templates in all subclasses of LLMGrader.#131

Open
weizhang25 wants to merge 4 commits intoagentscope-ai:mainfrom
weizhang25:set-default-templates-in-llm-graders
Open

Set default templates in all subclasses of LLMGrader.#131
weizhang25 wants to merge 4 commits intoagentscope-ai:mainfrom
weizhang25:set-default-templates-in-llm-graders

Conversation

@weizhang25
Copy link
Collaborator

Set the default template in all subclasses of LLMGrader.

… grader classes. (agentscope-ai#124)

* Expose templates of grader instances and default templates of grader classes.

* Resolve code review feedbacks.

* Update function argument type annotation.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refactors the handling of default templates within the LLMGrader hierarchy. By centralizing the default template definition as a class attribute in each subclass, it enhances code consistency and maintainability. This change simplifies how templates are accessed and overridden during object instantiation, making the system more robust and easier to extend.

Highlights

  • Standardized Default Template Assignment: The pull request introduces a consistent pattern for assigning default templates across all subclasses of LLMGrader. Each grader now defines its specific default template as a class attribute named DEFAULT_TEMPLATE.
  • Improved Template Reference: The __init__ methods in all affected LLMGrader subclasses have been updated to reference self.DEFAULT_TEMPLATE when a template is not explicitly provided, ensuring that the class-defined default is used.
  • Refactored __init__ Signatures: Many __init__ method signatures were updated to use the new DEFAULT_TEMPLATE class attribute as the default value for the template parameter, promoting better encapsulation.
  • Metadata Update for HallucinationGrader: The HallucinationGrader's get_metadata static method was updated to correctly retrieve the prompt using the new HallucinationGrader.DEFAULT_TEMPLATE class attribute.
Changelog
  • cookbooks/finance_grader/event_interpretation/event_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/event_interpretation/event_identification.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/industry_research/characteristics_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/industry_research/risk_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/industry_research/underlying_comparison.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/macro_analysis/concept_explanation.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/macro_analysis/macro_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_analysis/fundamental_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_analysis/overall_logic.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_analysis/stock_risk_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_analysis/valuation_analysis.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_search/search_integrity.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_search/search_relevance.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • cookbooks/finance_grader/stock_search/search_timeliness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/memory/memory_accuracy.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/memory/memory_detail_preservation.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/memory/memory_retrieval_effectiveness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/plan/plan_feasibility.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/reflection/reflection_accuracy.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/reflection/reflection_outcome_understanding.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/reflection/reflection_progress_awareness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/tool/tool_call_accuracy.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/tool/tool_call_success.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/tool/tool_parameter_check.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/tool/tool_selection.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/trajectory/trajectory_accuracy.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/agent/trajectory/trajectory_comprehensive.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/common/correctness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/common/hallucination.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
    • Updated get_metadata to reference HallucinationGrader.DEFAULT_TEMPLATE.
  • openjudge/graders/common/harmfulness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/common/instruction_following.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/common/relevance.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/anaphora_resolution_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/context_memory_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/instruction_clarification_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/proactive_interaction_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/response_repetition_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/self_correction_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multi_turn/topic_switch_grader.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multimodal/image_coherence.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
  • openjudge/graders/multimodal/image_helpfulness.py
    • Added DEFAULT_TEMPLATE class attribute.
    • Updated __init__ method signature to use DEFAULT_TEMPLATE as default.
    • Updated __init__ to use self.DEFAULT_TEMPLATE.
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.

@weizhang25
Copy link
Collaborator Author

This is the follow-up of #124. This PR sets the default templates in all sub-classes of LLMGrader.

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 refactors numerous LLMGrader subclasses to use a DEFAULT_TEMPLATE class attribute, which is a good step towards consistency. However, I've identified a critical issue across several files where this new class attribute is used as a default argument in __init__ methods. This will lead to a NameError at runtime because the class attribute is not yet defined when the method's default arguments are evaluated. I have provided specific comments and code suggestions to resolve this by setting the default value to None. Apart from this recurring issue, the refactoring is well-implemented.

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