Skip to content

Commit 16da954

Browse files
authored
Merge pull request #518 from guardrails-ai/fix-deps
Fix Dependencies
2 parents 37672e5 + 34ff7f9 commit 16da954

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

guardrails/validators/on_topic.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import openai
66
from tenacity import retry, stop_after_attempt, wait_random_exponential
7-
from transformers import pipeline
87

98
from guardrails.utils.casting_utils import to_int
109
from guardrails.utils.openai_utils import OpenAIClient
@@ -16,6 +15,11 @@
1615
register_validator,
1716
)
1817

18+
try:
19+
from transformers import pipeline
20+
except ImportError:
21+
pipeline = None
22+
1923

2024
@register_validator(name="on_topic", data_type="string")
2125
class OnTopic(Validator):
@@ -94,6 +98,13 @@ def __init__(
9498
)
9599
self._valid_topics = valid_topics
96100

101+
if pipeline is None:
102+
raise ValueError(
103+
"You must install transformers in order to "
104+
"use the OnTopic validator."
105+
"Install it using `pip install transformers`."
106+
)
107+
97108
if invalid_topics is None:
98109
self._invalid_topics = []
99110
else:
@@ -209,7 +220,7 @@ def openai_callable(text: str, topics: List[str]) -> str:
209220
def get_topic_zero_shot(
210221
self, text: str, candidate_topics: List[str]
211222
) -> Tuple[str, float]:
212-
classifier = pipeline(
223+
classifier = pipeline( # type: ignore
213224
"zero-shot-classification",
214225
model=self._model,
215226
device=self._device,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pydash = "^7.0.6"
5353
[tool.poetry.extras]
5454
sql = ["sqlvalidator", "sqlalchemy", "sqlglot"]
5555
summary = ["thefuzz", "nltk"]
56-
vectordb = ["faiss-cpu", "tiktoken", "numpy"]
56+
vectordb = ["faiss-cpu", "numpy"]
5757
profanity = ["alt-profanity-check"]
5858
detect-secrets = ["detect-secrets"]
5959
manifest = ["manifest-ml"]

0 commit comments

Comments
 (0)