-
Notifications
You must be signed in to change notification settings - Fork 504
fix missing ToolRubric import #741
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
Closed
ADharaUTEXAS123007
wants to merge
1
commit into
PrimeIntellect-ai:main
from
ADharaUTEXAS123007:fix/missing_tool_rubric
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from typing import Callable | ||
|
|
||
| from verifiers.rubrics.rubric import Rubric | ||
| from verifiers.types import Messages | ||
| from verifiers.utils.tool_utils import convert_func_to_oai_tool | ||
|
|
||
|
|
||
| class ToolRubric(Rubric): | ||
| """Simple rubric that counts tool calls in completion messages.""" | ||
|
|
||
| def __init__(self, tools: list[Callable] | None = None): | ||
| self.tools = tools or [] | ||
| self.oai_tools = [convert_func_to_oai_tool(tool) for tool in self.tools] | ||
| self.tool_names = [tool.__name__ for tool in self.tools] | ||
|
|
||
| # Build initial reward functions and weights | ||
| reward_funcs = [self.total_tool_calls] | ||
| reward_weights = [0.0] | ||
|
|
||
| for tool_name in self.tool_names: | ||
| reward_funcs.append(self.get_tool_call_count_func(tool_name)) | ||
| reward_weights.append(0.0) | ||
|
|
||
| # Pass them to parent class | ||
| super().__init__(funcs=reward_funcs, weights=reward_weights) | ||
|
|
||
| def total_tool_calls(self, completion: Messages, **kwargs) -> float: | ||
| """Count the total number of tool calls across all assistant messages.""" | ||
| total = 0 | ||
| for msg in completion: | ||
| if msg.get("role") == "assistant" and "tool_calls" in msg: | ||
| tool_calls = msg.get("tool_calls", []) | ||
| if isinstance(tool_calls, list): | ||
| total += len(tool_calls) | ||
| return float(total) | ||
|
|
||
| def get_tool_call_count_func(self, tool_name: str) -> Callable: | ||
| """Create a reward function that counts calls to a specific tool.""" | ||
|
|
||
| def tool_call_count_func(completion: Messages, **kwargs) -> float: | ||
| """Count calls to {tool_name} tool.""" | ||
| count = 0 | ||
|
|
||
| # Find tool calls in assistant messages | ||
| for msg in completion: | ||
| if msg.get("role") == "assistant" and "tool_calls" in msg: | ||
| tool_calls = msg.get("tool_calls", []) | ||
| if not isinstance(tool_calls, list): | ||
| continue | ||
|
|
||
| for tool_call in tool_calls: | ||
| if hasattr(tool_call, "function") and hasattr( | ||
| tool_call.function, "name" | ||
| ): | ||
| if tool_call.function.name == tool_name: | ||
| count += 1 | ||
|
|
||
| return float(count) | ||
|
|
||
| tool_call_count_func.__name__ = f"{tool_name}_calls" | ||
| return tool_call_count_func | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per-tool counter uses attribute access on dictionary
High Severity
The
get_tool_call_count_funcmethod uses attribute access (hasattr(tool_call, "function")andtool_call.function.name) ontool_callitems, butcompletionmessages passed to rubric functions are dictionaries, not OpenAI response objects. Dictionary items don't have afunctionattribute, sohasattrreturnsFalseand per-tool counts are always 0. The existingToolMonitorRubricintool_env.pycorrectly uses dictionary access:tool_call.get("function", {}).get("name").