generated from guardrails-ai/validator-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from guardrails-ai/jc/update_for_new_guardrails
Update validator, fixing a handful of imports that were incompatible with new guardrails.
- Loading branch information
Showing
6 changed files
with
71 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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,7 +1,7 @@ | ||
[project] | ||
name = "validator-template" | ||
version = "0.0.0" | ||
description = "Template repo for Guardrails Hub validators." | ||
name = "bias_check" | ||
version = "0.2.0" | ||
description = "Wrapping a bias check model into a validator." | ||
authors = [ | ||
{name = "Guardrails AI", email = "[email protected]"} | ||
] | ||
|
@@ -10,7 +10,8 @@ readme = "README.md" | |
requires-python = ">= 3.8.1" | ||
dependencies = [ | ||
"guardrails-ai>=0.4.0", | ||
"Dbias" | ||
"transformers>=4.40.2", | ||
"tensorflow>=2.18.0" | ||
] | ||
|
||
[project.optional-dependencies] | ||
|
This file contains 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,25 +1,22 @@ | ||
# to run these, run | ||
# make tests | ||
|
||
from guardrails import Guard | ||
import pytest | ||
from validator import BiasCheck | ||
from guardrails.validator_base import FailResult, PassResult | ||
|
||
from validator import BiasCheck | ||
|
||
# We use 'exception' as the validator's fail action, | ||
# so we expect failures to always raise an Exception | ||
# Learn more about corrective actions here: | ||
# https://www.guardrailsai.com/docs/concepts/output/#%EF%B8%8F-specifying-corrective-actions | ||
def test_success_case(self): | ||
validator = BiasCheck(debias_strength=0.5) | ||
def test_success_case(): | ||
validator = BiasCheck() | ||
input_text = "The sun rises in the morning." | ||
result = validator.validate(input_text, {}) | ||
assert isinstance(result, PassResult) | ||
|
||
def test_failure_case(self): | ||
validator = BiasCheck(debias_strength=0.5) | ||
def test_failure_case(): | ||
validator = BiasCheck(threshold=0.5) | ||
input_text = "The sun only rises for Humanists." | ||
result = validator.validate(input_text, {}) | ||
assert isinstance(result, FailResult) | ||
assert result.error_message == "The original response contains potential biases that are now addressed." | ||
assert result.fix_value == "The sun rises for everyone." | ||
assert result.error_message == "The original response contains potentially biased messages:\nThe sun only rises for Humanists.\n (Message scores: 0.6546186208724976)" | ||
assert result.fix_value == "" |
This file contains 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,3 +1,3 @@ | ||
from .main import ValidatorTemplate | ||
from .main import BiasCheck | ||
|
||
__all__ = ["ValidatorTemplate"] | ||
__all__ = ["BiasCheck"] |
This file contains 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 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,4 +1,4 @@ | ||
from transformers import pipeline | ||
print("post-install starting...") | ||
print("This is where you would do things like download nltk tokenizers or login to the HuggingFace hub...") | ||
print("post-install complete!") | ||
# If you don't have anything to add here you should delete this file. | ||
_ = pipeline("text-classification", "d4data/bias-detection-model") | ||
print("post-install complete!") |