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

add support for specifying a template in cli create #952

Merged
merged 12 commits into from
Aug 6, 2024

Conversation

dtam
Copy link
Contributor

@dtam dtam commented Jul 19, 2024

Adds support for templates via the guardrails create cli. To test a local file create a template like chatbot.json

{
    "name": "chatbot",
    "description": "a basic guard to facilitate chat w llms",
    "template_version": "0.0.1",
    "namespace": "guardrails",
    "guards": [
      {
        id: "chatbot",
        "name": "chatbot",
        "validators": [
            {
                "id": "guardrails/competitor_check",
                "on": "$",
                "onFail": "exception",
                "kwargs": {
                    "competitors": [
                        "OpenAI",
                        "Anthropic"
                    ]
                }
            },
            {
                "id": "guardrails/detect_pii",
                "on": "$",
                "onFail": "exception",
                "kwargs": {
                    "pii_entities": [
                        "EMAIL_ADDRESS",
                        "PHONE_NUMBER"
                    ]
                }
            },
            {
                "id": "guardrails/profanity_free",
                "on": "$",
                "onFail": "exception",
                "kwargs": {}
            }
        ],
      }
    ]
  }

run guardrails create --template template.json
add a openAI api key like os.environ["OPENAI_API_KEY"] = "sk-proj"
run guardrails start --config config.py

to test full end to end
run https://github.com/guardrails-ai/validator-hub-ui/pull/22 via bun run dev
go to http://localhost:3000/guard-templates
observe
Screenshot 2024-07-31 at 1 47 21 PM
run guardrails create --template hub:template://guardrails/chatbot
run guardrails start --config config.py --port 8080

use this script to test both cases

import os
import json

os.environ["OPENAI_LOG"] = "debug"

import openai
openai.base_url = "http://localhost:8080/guards/chatbot/openai/v1/"
openai.default_headers = {"x-foo": "true"}
os.environ["OPENAI_API_KEY"] = "sk-proj"
messages = [
        {
            "role": "user",
            "content": "Tell me about the llm llama"
            # "content": "Tell me about chat gpt from openai"
        },
    ]


completion = openai.chat.completions.create(
    model="gpt-4o",
    messages=messages,
)

print("===completion===", completion)

@zsimjee zsimjee added this to the v0.5.2 release tracker milestone Jul 23, 2024
@zsimjee zsimjee merged commit 2b7bf43 into main Aug 6, 2024
12 checks passed
@zsimjee zsimjee deleted the dtam/cli_create_from_template branch August 6, 2024 22:39
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