-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Add save/load functionality and improved repr for LLM-based metrics #2320
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
Conversation
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.
Looks good overall. 2 minor suggestions added.
And need to fix the merge conflict.
prompt: t.Optional[t.Union[str, "Prompt"]] = None | ||
_response_model: t.Type["BaseModel"] = field(init=False) | ||
|
||
def __post_init__(self): |
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.
Some metrics can be created without prompts but will fail during save.
Either we can make prompts required here or allow None in serialization..
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.
good catch - SimpleLLMMetric
will always have prompt so I'll make it required
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like
Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
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.
I've address everything - could you take a look and merge it if you think everything looks good?
prompt: t.Optional[t.Union[str, "Prompt"]] = None | ||
_response_model: t.Type["BaseModel"] = field(init=False) | ||
|
||
def __post_init__(self): |
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.
good catch - SimpleLLMMetric
will always have prompt so I'll make it required
Summary
This PR adds persistence capabilities and better string representations for LLM-based metrics, making them easier to save, share, and debug.
Changes
1. Save/Load Functionality
save()
andload()
methods toSimpleLLMMetric
and its subclasses (DiscreteMetric
,NumericMetric
,RankingMetric
)Prompt
andDynamicFewShotPrompt
metric.save()
saves to./metric_name.json
2. Improved
__repr__
Methods<locals>
, internal attributes)Before:
After:
3. Response Model Handling
create_auto_response_model()
factory to mark auto-generated modelsUsage Examples
Testing
Dependencies
Note: This PR builds on #2316 (Fix metric inheritance patterns) and requires it to be merged first. The changes here depend on the cleaned-up metric inheritance structure from that PR.
Checklist