-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
19 additions
and
79 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
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,71 +1,31 @@ | ||
''' | ||
""" | ||
All guards defined here will be initialized, if and only if | ||
the application is using in memory guards. | ||
The application will use in memory guards if pg_host is left | ||
undefined. Otherwise, a postgres instance will be started | ||
undefined. Otherwise, a postgres instance will be started | ||
and guards will be persisted into postgres. In that case, | ||
these guards will not be initialized. | ||
''' | ||
""" | ||
|
||
from guardrails import Guard | ||
from guardrails.hub import RegexMatch, ValidChoices, ValidLength #, RestrictToTopic | ||
|
||
name_case = Guard( | ||
name='name-case', | ||
description='Checks that a string is in Name Case format.' | ||
).use( | ||
RegexMatch(regex="^(?:[A-Z][^\s]*\s?)+$") | ||
) | ||
|
||
all_caps = Guard( | ||
name='all-caps', | ||
description='Checks that a string is all capital.' | ||
).use( | ||
RegexMatch(regex="^[A-Z\\s]*$") | ||
) | ||
|
||
lower_case = Guard( | ||
name='lower-case', | ||
description='Checks that a string is all lowercase.' | ||
).use( | ||
RegexMatch(regex="^[a-z\\s]*$") | ||
).use( | ||
ValidLength(1, 100) | ||
).use( | ||
ValidChoices(["music", "cooking", "camping", "outdoors"]) | ||
from guardrails.hub import ( | ||
DetectPII, | ||
CompetitorCheck | ||
) | ||
|
||
print(lower_case.to_json()) | ||
|
||
|
||
no_guards = Guard() | ||
no_guards.name = "No Guards" | ||
|
||
output_guard = Guard() | ||
output_guard.name = "Output Guard" | ||
output_guard.use_many( | ||
DetectPII( | ||
pii_entities='pii' | ||
), | ||
CompetitorCheck( | ||
competitors=['OpenAI', 'Anthropic'] | ||
) | ||
) | ||
|
||
# valid_topics = ["music", "cooking", "camping", "outdoors"] | ||
# invalid_topics = ["sports", "work", "ai"] | ||
# all_topics = [*valid_topics, *invalid_topics] | ||
|
||
# def custom_llm (text: str, *args, **kwargs): | ||
# return [ | ||
# { | ||
# "name": t, | ||
# "present": (t in text), | ||
# "confidence": 5 | ||
# } | ||
# for t in all_topics | ||
# ] | ||
|
||
# custom_code_guard = Guard( | ||
# name='custom', | ||
# description='Uses a custom llm for RestrictToTopic' | ||
# ).use( | ||
# RestrictToTopic( | ||
# valid_topics=valid_topics, | ||
# invalid_topics=invalid_topics, | ||
# llm_callable=custom_llm, | ||
# disable_classifier=True, | ||
# disable_llm=False, | ||
# # Pass this so it doesn't load the bart model | ||
# classifier_api_endpoint="https://m-1e7af27102f54c3a9eb9cb11aa4715bd-m.default.model-v2.inferless.com/v2/models/RestrictToTopic_1e7af27102f54c3a9eb9cb11aa4715bd/versions/1/infer", | ||
# ) | ||
# ) |