From e95c594ff95d9ea96688c40125b0e709d171f17b Mon Sep 17 00:00:00 2001 From: Nicholas Chen Date: Tue, 25 Jun 2024 14:44:50 -0400 Subject: [PATCH] move config into sample-config --- guardrails_api/config.py | 22 +----------- sample-config.py | 76 ++++++++++------------------------------ 2 files changed, 19 insertions(+), 79 deletions(-) diff --git a/guardrails_api/config.py b/guardrails_api/config.py index af69aa7..199eab2 100644 --- a/guardrails_api/config.py +++ b/guardrails_api/config.py @@ -7,25 +7,5 @@ and guards will be persisted into postgres. In that case, these guards will not be initialized. """ -# from guardrails_hub import AtomicFactuality # noqa -from guardrails import Guard -from guardrails.hub import ( - DetectPII, - CompetitorCheck -) - - -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'] - ) -) +from guardrails import Guard diff --git a/sample-config.py b/sample-config.py index 7df5938..2677590 100644 --- a/sample-config.py +++ b/sample-config.py @@ -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", -# ) -# ) \ No newline at end of file