Skip to content

add handling for validation errors to return 400 and message #56

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

Merged
merged 5 commits into from
Jul 11, 2024

Conversation

dtam
Copy link
Contributor

@dtam dtam commented Jul 9, 2024

Pull Request Type

  • Breaking Change
  • Feature
  • Bug Fix
  • Non-bug Patch (dependency update, non-production code, etc.)

Link to Notion Task or Github Issue

Summary of Feature(s)

config.py

regexG = Guard().use(RegexMatch(regex="^[A-Z][a-z]*$", on_fail="exception"))
regexG.name = "reg_ex"
regexG.configure(num_reasks=0)

post to guards/reg_ex/validate with any prompt that returns more than 1 word will now return a 400 with the correct string
or use the openai sdk with the code below

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

import openai

# OpenAI compatible Guardrails API Guard
openai.base_url = "http://localhost:8000/guards/reg_ex/openai/v1/"

openai.api_key = os.getenv("OPENAI_API_KEY") or 'some key'

messages = [
        {
            "role": "user",
            "content": "return a two words to describe a good day",
        },
    ]

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


print("===output===", completion.choices[0].message.content)

Summary of Bug Fix(es)

Previous Behaviour

Description of the bug and it's impact

New Behaviour

Description of the bug fix and it's impact

Other details

Dependencies

@dtam dtam requested a review from zsimjee July 9, 2024 22:13
@zsimjee
Copy link
Contributor

zsimjee commented Jul 10, 2024

lgtm other than not using .last

@dtam dtam requested a review from zsimjee July 11, 2024 00:10
@zsimjee zsimjee merged commit c683d29 into main Jul 11, 2024
1 check passed
@zsimjee zsimjee deleted the dtam/update_validation_error_handling branch July 11, 2024 20:43
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.

2 participants