-
Notifications
You must be signed in to change notification settings - Fork 472
feat: refactor validators and fields to support pydantic v2 #967
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
base: develop
Are you sure you want to change the base?
Conversation
@xiaobo8204 thanks for your contribution to NeMo Guardrails 👍🏻 would you please sign all your commits following the contributing guidelines. You should see a Verified tag for all your commits. |
@@ -65,7 +65,7 @@ langchain-community = ">=0.0.16,<0.4.0" | |||
lark = ">=1.1.7" | |||
nest-asyncio = ">=1.5.6," | |||
prompt-toolkit = ">=3.0" | |||
pydantic = ">=1.10" |
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.
we should relax it a bit, probably >= 2.0
And I still need to see the reasons we were still supporting Pydantic 1.0, I'll get back to this 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.
removed the extra log.text and hidden file, changed the version to >= 2.0, and signed the commit, thanks...
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.
and <3.0
8581787
to
bb87907
Compare
- Refactored code to use `@model_validator` instead of `@root_validator` - Updated `Field` usage to align with Pydantic v2 standards - Modified validation logic to comply with the new API - Updated `poetry.lock` and dependencies in `pyproject.toml`
6c0bf2c
to
9af0695
Compare
@xiaobo8204 Apologies for the delay in reviewing your PR. The issue is that we currently don’t have proper tests for the code your PR affects. I’ll open a separate PR to add the necessary tests. Once that’s in place, we can rebase your branch and move forward from there. Thanks for your patience! |
@@ -61,12 +61,12 @@ class TRTLLM(BaseLLM): | |||
client: Any | |||
streaming: Optional[bool] = True | |||
|
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.
should be
@classmethod
def validate_environment(cls, self) -> "TRTLLM":
"""Validate that python package exists in environment."""
try:
# instantiate and attach the client
self.client = TritonClient(self.server_url)
except ImportError as err:
raise ImportError(
"Could not import triton client python package. "
"Please install it with `pip install tritonclient[all]`."
) from err
return self
@@ -147,11 +147,11 @@ class EvalConfig(BaseModel): | |||
description="The prompts that should be used for the various LLM tasks.", | |||
) | |||
|
|||
@root_validator(pre=False, skip_on_failure=True) | |||
def validate_policy_ids(cls, values: Any): | |||
@model_validator(mode="after") |
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.
should be
@model_validator(mode="after")
def validate_policy_ids(cls, self) -> "EvalConfig":
"""Validates the policy ids used in the interactions."""
policy_ids = {policy.id for policy in self.policies}
for interaction_set in self.interactions:
for expected_output in interaction_set.expected_output:
if expected_output.policy not in policy_ids:
raise ValueError(
f"Invalid policy id {expected_output.policy} used in interaction set."
)
for policy_id in (
interaction_set.include_policies + interaction_set.exclude_policies
):
if policy_id not in policy_ids:
raise ValueError(
f"Invalid policy id {policy_id} used in interaction set."
)
return self
Description
This PR aims to update Pydantic to the latest v2.10.6, and switch to use the new model_validator/Field/field_validator in the new Pydantic version.
Related Issue(s)
Checklist