You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
guard.validate("""
In Super Bowl LVII in 2023, the Chiefs clashed with the Philadelphia Eagles in a fiercely contested battle, ultimately emerging victorious with a score of 38-35.
""") # Validator passes
guard.validate("""
The Beatles were a charismatic English pop-rock band of the 1960s.
""") # Validator fails
How they modifying above code to utilize openai api key?
26 frames
OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
The above exception was the direct cause of the following exception:
RetryError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/tenacity/init.py in iter(self, retry_state)
324 if self.reraise:
325 raise retry_exc.reraise()
--> 326 raise retry_exc from fut.exception()
327
328 if self.wait:
RetryError: RetryError[<Future at 0x783bd95637c0 state=finished raised OpenAIError>
The text was updated successfully, but these errors were encountered:
That seems to be the culprit according the error message you posted: OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
zsimjee
changed the title
!guardrails hub install hub://tryolabs/restricttotopic
RestrictToTopic validator does not work in guard
Apr 25, 2024
Import Guard and Validator
from guardrails.hub import RestrictToTopic
from guardrails import Guard
Setup Guard
guard = Guard().use(
RestrictToTopic(
valid_topics=["sports"],
invalid_topics=["music"],
disable_classifier=True,
disable_llm=False,
on_fail="exception"
)
)
guard.validate("""
In Super Bowl LVII in 2023, the Chiefs clashed with the Philadelphia Eagles in a fiercely contested battle, ultimately emerging victorious with a score of 38-35.
""") # Validator passes
guard.validate("""
The Beatles were a charismatic English pop-rock band of the 1960s.
""") # Validator fails
How they modifying above code to utilize openai api key?
I'm getting this error:
OpenAIError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/tenacity/init.py in call(self, fn, *args, **kwargs)
381 try:
--> 382 result = fn(*args, **kwargs)
383 except BaseException: # noqa: B902
26 frames
OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
The above exception was the direct cause of the following exception:
RetryError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/tenacity/init.py in iter(self, retry_state)
324 if self.reraise:
325 raise retry_exc.reraise()
--> 326 raise retry_exc from fut.exception()
327
328 if self.wait:
RetryError: RetryError[<Future at 0x783bd95637c0 state=finished raised OpenAIError>
The text was updated successfully, but these errors were encountered: