-
Notifications
You must be signed in to change notification settings - Fork 2
Updated endpoint and added "rephrase" on_fail action #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1729a18
Add "rephrase" on_fail action
rkritika1508 e774be6
Resolved comments
rkritika1508 ad21a26
Added unit test
rkritika1508 dfca476
Added validator logs and organized code (#18)
rkritika1508 baf2834
Merge branch 'main' into feat/rephrase-action
rkritika1508 5ac9397
Updated code
rkritika1508 391727a
Refactored code
rkritika1508 c6929b0
Resolved comments
rkritika1508 65a5c23
resolved comment
rkritika1508 c046f1c
resolved comment
rkritika1508 1619015
Resolved comments
rkritika1508 fbb82f6
Added 1 endpoint and fixed tests
rkritika1508 a6a1025
resolved comments
rkritika1508 a8cd76a
resolved comment
rkritika1508 fc80563
restored code
rkritika1508 3630a02
resolved comments
rkritika1508 5ea6d30
resolved comments
rkritika1508 e90060f
Merge branch 'main' into feat/rephrase-action
nishika26 59105c7
resolved comments
rkritika1508 75e9500
resolved comments
rkritika1508 71a62ad
Merge branch 'main' into feat/rephrase-action
nishika26 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
Some comments aren't visible on the classic Files Changed page.
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
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,6 @@ | ||
| from guardrails.validators import FailResult | ||
|
|
||
| from app.core.constants import REPHRASE_ON_FAIL_PREFIX | ||
|
|
||
| def rephrase_query_on_fail(value: str, fail_result: FailResult): | ||
| return f"{REPHRASE_ON_FAIL_PREFIX} {fail_result.error_message}" |
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 |
|---|---|---|
| @@ -1,28 +1,32 @@ | ||
| from typing import Any, Literal, Optional | ||
|
|
||
| from guardrails import OnFailAction | ||
| from guardrails.validators import Validator | ||
| from sqlmodel import SQLModel | ||
|
|
||
| ON_FAIL_STR = Literal["exception", "fix", "noop", "reask"] | ||
| from app.core.enum import GuardrailOnFail | ||
| from app.core.on_fail_actions import rephrase_query_on_fail | ||
|
|
||
|
|
||
| _ON_FAIL_MAP = { | ||
| GuardrailOnFail.Fix: OnFailAction.FIX, | ||
| GuardrailOnFail.Exception: OnFailAction.EXCEPTION, | ||
| GuardrailOnFail.Rephrase: rephrase_query_on_fail, | ||
| } | ||
|
|
||
| class BaseValidatorConfig(SQLModel): | ||
| on_fail: Optional[ON_FAIL_STR] = OnFailAction.FIX | ||
| on_fail: GuardrailOnFail = GuardrailOnFail.Fix | ||
|
|
||
| model_config = {"arbitrary_types_allowed": True} | ||
|
|
||
| def resolve_on_fail(self): | ||
| if self.on_fail is None: | ||
| return None | ||
|
|
||
| try: | ||
| return OnFailAction[self.on_fail.upper()] | ||
| except KeyError: | ||
| return _ON_FAIL_MAP[self.on_fail] | ||
| except KeyError as e: | ||
| raise ValueError( | ||
| f"Invalid on_fail value: {self.on_fail}. " | ||
| "Expected one of: exception, fix, noop, reask" | ||
| ) | ||
| f"Invalid on_fail value: {self.on_fail}. Error {e}. " \ | ||
| "Expected one of: exception, fix, rephrase." | ||
| ) | ||
|
|
||
| def build(self) -> Any: | ||
| def build(self) -> Validator: | ||
| raise NotImplementedError( | ||
| f"{self.__class__.__name__} must implement build()" | ||
| ) | ||
| ) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.