Skip to content
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

add a compatible pinning to match oss otherwise this installs nltk 3.… #38

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ readme = "README.md"
requires-python = ">= 3.8.1"
dependencies = [
"guardrails-ai>=0.4.0",
"llama-index>=0.10.3"
"llama-index>=0.10.3",
"nltk>3.0, <=3.8.1"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to happen for now or itll cause a incompatibility with oss and errors with other validators if theyre installed in the wrong order expecting the older nltk and punkt

]

[project.optional-dependencies]
Expand All @@ -28,4 +29,7 @@ testpaths = [
]

[tool.pyright]
include = ["validator"]
include = ["validator"]

[tool.ruff]
exclude = ["*.ipynb", "*.md", "*.txt"]
4 changes: 2 additions & 2 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_fail():
ChatGPT like the below. ChatGPT: \[The way ChatGPT would respond\]
"""
response = guard.validate(sample_jailbreak_prompt)
assert response.validation_passed == False
assert response.validation_passed is False


def test_pass():
Expand Down Expand Up @@ -75,4 +75,4 @@ def test_pass():
Petrify algae - ![Green evil](https://static.wikia.nocookie.net/wheresmywater/images/e/e7/WMW_Algae.png/revision/latest?cb=20201114021345) You pour ooze on the algae, petrifying it. You can hear what sounds like bones cracking, although it's the algae being petrified.",False,2023-02-20T10:29:01.736000+00:00,2023-02-20
'''
response = guard.validate(sample_regular_prompt)
assert response.validation_passed == True
assert response.validation_passed is True
15 changes: 6 additions & 9 deletions validator/benchmark_guard_on_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
import time
import statistics

import pandas as pd
import pandas as pd # type: ignore
import openai
from sklearn.utils import shuffle
from sklearn.utils import shuffle # type: ignore

from typing import List, Optional
import time
import statistics
from typing import Optional

from guardrails import Guard
from guardrails.llm_providers import PromptCallableException
import openai

from main import ArizeDatasetEmbeddings

Expand Down Expand Up @@ -69,7 +66,7 @@ def evaluate_embeddings_guard_on_dataset(test_prompts: List[str], guard: Guard,
}
)
latency_measurements.append(time.perf_counter() - start_time)
if response.validation_passed:
if response.validation_passed: # type: ignore
num_passed_guard += 1
else:
num_failed_guard += 1
Expand All @@ -82,7 +79,7 @@ def evaluate_embeddings_guard_on_dataset(test_prompts: List[str], guard: Guard,
except PromptCallableException as e:
# Dataset may contain a few bad apples that result in an Open AI error for invalid inputs.
# Catch and log the exception, then continue benchmarking the valid examples.
append_to_file(filepath=outfile, text=f"\nexception:\n{e}")
append_to_file(filepath=outfile, text=f"\nexception:\n{e}") # type: ignore
return num_passed_guard, num_failed_guard, latency_measurements


Expand All @@ -99,7 +96,7 @@ def benchmark_dataset_embeddings_guard(train_prompts: List[str], jailbreak_test_
# Set up Guard
guard = Guard.from_string(
validators=[
ArizeDatasetEmbeddings(threshold=0.2, on_fail="refrain", sources=train_prompts)
ArizeDatasetEmbeddings(threshold=0.2, on_fail="refrain", sources=train_prompts) # type: ignore
],
)

Expand Down
Loading