From 6948c9bc8f52ec2f28aa96f827195b66d9085e4b Mon Sep 17 00:00:00 2001 From: Alejandro Date: Thu, 18 Jul 2024 13:49:18 -0700 Subject: [PATCH] Add user-facing messages on startup (guards, docs url) --- guardrails_api/app.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/guardrails_api/app.py b/guardrails_api/app.py index d43a15c..583acc1 100644 --- a/guardrails_api/app.py +++ b/guardrails_api/app.py @@ -10,7 +10,8 @@ from guardrails_api.clients.postgres_client import postgres_is_enabled from guardrails_api.otel import otel_is_disabled, initialize from guardrails_api.clients.cache_client import CacheClient - +from rich.console import Console +from rich.rule import Rule # TODO: Move this to a separate file class OverrideJsonProvider(DefaultJSONProvider): @@ -50,6 +51,9 @@ def register_config(config: Optional[str] = None): def create_app( env: Optional[str] = None, config: Optional[str] = None, port: Optional[int] = None ): + # used to print user-facing messages during server startup + console = Console() + if os.environ.get("APP_ENVIRONMENT") != "production": from dotenv import load_dotenv @@ -96,9 +100,23 @@ def create_app( cache_client.initialize(app) from guardrails_api.blueprints.root import root_bp - from guardrails_api.blueprints.guards import guards_bp + from guardrails_api.blueprints.guards import guards_bp, guard_client app.register_blueprint(root_bp) app.register_blueprint(guards_bp) + console.print( + f"\n:rocket: Guardrails API is available at {self_endpoint}" + ) + console.print(f":book: Visit {self_endpoint}/docs to see available API endpoints.\n") + + console.print(":green_circle: Active guards and OpenAI compatible endpoints:") + + for g in guard_client.get_guards(): + g = g.to_dict() + console.print(f"- Guard: [bold white]{g.get('name')}[/bold white] {self_endpoint}/guards/{g.get('name')}/openai/v1") + + console.print("") + console.print(Rule("[bold grey]Server Logs[/bold grey]", characters="=", style="white")) + return app