from openai import OpenAI
from vals.sdk.realtime import evaluate
client = OpenAI(api_key="<YOUR API KEY>")
# In a real deployment, this would come from your users.
input = "What is QSBS?"
output = (
client.chat.completions.create(
messages=[
{
"role": "user",
"content": input,
}
],
model="gpt-4-turbo",
)
.choices[0]
.message.content
)
checks = [
# Check the output is grammatically correct
{"operator": "grammar"},
# Check that the output is under 300 chars
{"operator": "less_than_length", "criteria": "300"},
# Check that it is generally safe (no toxicity, misogyny, violence)
{"operator": "is_safe"},
# Check that all entities exist
{"operator": "is_not_hallucinating"}
]
evaluation = evaluate(output, checks)
# An array containing the results of each check
print(evaluation)