generated from guardrails-ai/validator-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adbb456
commit d958683
Showing
5 changed files
with
36 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ jobs: | |
python-version: 3.11 | ||
- name: Run qa | ||
run: | | ||
pip install ".[dev]" | ||
make dev | ||
make qa |
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,13 +1,19 @@ | ||
.PHONY: test dev lint type qa | ||
|
||
dev: | ||
pip install -e ".[dev]" | ||
python3 validator/post-install.py | ||
|
||
lint: | ||
ruff check . | ||
|
||
tests: | ||
pytest ./test | ||
test: | ||
pytest -v tests | ||
|
||
type: | ||
pyright validator | ||
|
||
qa: | ||
make lint | ||
make type | ||
make tests | ||
make test |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
from guardrails import Guard | ||
from validator.main import NSFWText | ||
|
||
# Setup Guard with NSFWText validator | ||
guard = Guard().use( | ||
NSFWText, threshold=0.8, validation_method="sentence", on_fail="exception" | ||
) | ||
|
||
# Test passing response (no NSFW content) | ||
def test_nsfw_text_pass(): | ||
response = guard.validate( | ||
"Christopher Nolan's Tenet is a mind-bending action thriller that will keep you on the edge of your seat. The film is a must-watch for all Nolan fans." | ||
) | ||
assert response.validation_passed is True | ||
|
||
# Test failing response (contains NSFW content) | ||
def test_nsfw_text_fail(): | ||
with pytest.raises(Exception) as e: | ||
guard.validate( | ||
"Climate Change is real and we need to do something about it. Dumping one's shit into the river is a great way to help fight climate change." | ||
) | ||
assert "Validation failed for field with errors:" in str(e.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