Refund only when sure
Open in playground →Classify a ticket with a confidence, and ask for the refund amount only when it is billing and the model is sure, in the same call.
Challenges
refundruns only ifcategoryisbillingwith a confidence of at least 0.8:"when": {"category": {"in": ["billing"], "confidence": {"gte": 0.8}}}.- This ticket is plainly billing, so the refund is asked. A vaguer one, "Since I changed my email I can't log in, and my last invoice looks wrong too.", came back
accountat confidence 0.34, andrefundwas skipped.
import os
from typellm import TypeLLMClient
client = TypeLLMClient(api_key=os.environ["TYPELLM_API_KEY"])
response = client.generate(
context="I was charged twice for my Pro upgrade ($49 each). Please refund one.",
questions={
"category": {
"type": "string",
"enum": [
"billing",
"technical",
"account"
],
"return_probabilities": True
},
"refund": {
"type": "number",
"instructions": "Refund in dollars.",
"when": {
"category": {
"in": [
"billing"
],
"confidence": {
"gte": 0.8
}
}
}
}
},
)
print(response)Generation(
result={
'category': {
'value': 'billing',
'probabilities': {
'billing': 1,
'technical': 0,
'account': 0,
},
'confidence': 1,
},
'refund': 49,
},
thinking={},
usage=Usage(input_tokens=87, thinking_tokens=0),
)