Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guardrails Top Level Settings #930

Merged
merged 3 commits into from
Jul 16, 2024
Merged

Guardrails Top Level Settings #930

merged 3 commits into from
Jul 16, 2024

Conversation

CalebCourier
Copy link
Collaborator

@CalebCourier CalebCourier commented Jul 16, 2024

Adds a settings singleton to the guardrails package. Currently only supports one setting use_server that allows users to specify when to run guards on the guardrails-api vs on the client.

Tested with the following:

config.py

from guardrails import Guard
from guardrails.hub import RegexMatch

name_case = Guard(
    name='name-case',
    description='Checks that a string is in Name Case format.'
).use(
    RegexMatch(regex="^[A-Z][a-z\\s]*$")
)

start command

guardrails start --config=config.py

client side script

import os
import logging
from rich import print
from guardrails import configure_logging
from guardrails import Guard, settings

os.environ["GUARDRAILS_BASE_URL"] = "http://localhost:8000"

print(os.environ.get("GUARDRAILS_API_KEY", "No API key found"))
print(os.environ.get("GUARDRAILS_BASE_URL"))

settings.use_server = True
# settings.use_server = False
configure_logging(None, log_level=logging.DEBUG)


name_case = Guard(name='name-case')


result = name_case.parse(
    llm_output="z-dawg"
)

print("result: ", result)
print("number of validators run: ", len(name_case.history.last.validator_logs))

@CalebCourier CalebCourier marked this pull request as ready for review July 16, 2024 23:00
@CalebCourier CalebCourier requested review from zsimjee and a team July 16, 2024 23:01
@CalebCourier CalebCourier merged commit 7c18555 into 0.5.0-dev Jul 16, 2024
12 checks passed
@CalebCourier CalebCourier deleted the settings branch July 16, 2024 23:05
@JosephCatrambone
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants