Skip to content

Commit

Permalink
move config into sample-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nichwch committed Jun 25, 2024
1 parent a1e756c commit e95c594
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 79 deletions.
22 changes: 1 addition & 21 deletions guardrails_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 18 additions & 58 deletions sample-config.py
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",
# )
# )

0 comments on commit e95c594

Please sign in to comment.