Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr_qc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
python-version: 3.11
- name: Run qa
run: |
pip install ".[dev]"
make dev
make qa
18 changes: 18 additions & 0 deletions .github/workflows/publish_pypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish to Guardrails Hub

on:
workflow_dispatch:
push:
# Publish when new releases are tagged.
tags:
- '*'

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Build & Deploy
uses: guardrails-ai/guardrails/.github/actions/validator_pypi_publish@main
with:
guardrails_token: ${{ secrets.GR_GUARDRAILS_TOKEN }}
validator_id: guardrails/gibberish_text
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
dev:
pip install ".[dev]"
python validator/post-install.py

lint:
ruff check .

Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
| --- | --- |
| Date of development | Feb 15, 2024 |
| Validator type | Format |
| Blog | - |
| Blog | |
| License | Apache 2 |
| Input/Output | Output |

Expand All @@ -13,12 +13,20 @@
This validator validates the "cleanliness" of the text generated by a language model. It uses a pre-trained model to determine if the text is coherent and not gibberish. The validator can be used to filter out text that is not coherent or does not make sense.

## Requirements
- Dependencies: `nltk`, `transformers`, `torch`

* Dependencies:
- guardrails-ai>=0.4.0
- `nltk`
- `transformers`
- `torch`

* Foundation model access keys:
- HF_TOKEN

## Installation

```bash
guardrails hub install hub://guardrails/gibberish_text
$ guardrails hub install hub://guardrails/gibberish_text
```

## Usage Examples
Expand Down Expand Up @@ -59,7 +67,7 @@ Validation failed for field with errors: The following sentences in your respons
```
**Note: See how only the first 2 sentences within the failing response are considered gibberish.**

## API Reference
# API Reference

**`__init__(self, threshold=0.5, validation_method='sentence', on_fail="noop")`**
<ul>
Expand All @@ -78,7 +86,7 @@ Initializes a new instance of the Validator class.

<br/>

**`__call__(self, value, metadata={}) -> ValidationResult`**
**`validate(self, value, metadata={}) -> ValidationResult`**

<ul>

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gibberish_text"
version = "0.0.1"
version = "0.0.2"
description = "A Guardrails AI validator to detect gibberish text."
authors = [
{name = "Guardrails AI", email = "[email protected]"}
Expand Down
2 changes: 2 additions & 0 deletions validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ def validate(self, value: str, metadata: Dict[str, Any]) -> ValidationResult:

if self._validation_method == "full":
return self.validate_full_text(value, metadata)

raise ValueError("validation_method must be 'sentence' or 'full'.")
1 change: 0 additions & 1 deletion validator/post-install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import nltk
from transformers import pipeline

# Download NLTK data if not already present
Expand Down