Answer a set of named questions about an input, such as whether a customer is complaining, which team should handle a request, or how angry a customer is.
The questions are defined in the task settings of the inference endpoint, and can be replaced for a single request through task_settings.
Only the elastic service currently supports the decision task.
Required authorization
- Cluster privileges:
monitor_inference
Query parameters
-
The amount of time to wait for the inference request to complete.
Default value is
30s.
Body
Required
- input
string | object Required The input to answer the questions about. It can be specified as a string, or as an object. The object form additionally allows specifying images.
string example:
"input": "I was charged twice for my order and nobody answers my emails."object example:
"input": { "type": "image", "format": "base64", "value": "data:image/jpeg;base64,..." } -
Task settings for the individual inference request. These settings override the task settings specified when creating the inference endpoint.
POST _inference/decision/my-decision-endpoint
{
"input": "I was charged twice for my order and nobody answers my emails.",
"task_settings": {
"questions": {
"is_complaint": {
"type": "predicate",
"instructions": "Is the customer complaining?"
},
"team": {
"type": "choice",
"instructions": "Which team should handle this?",
"choices": {
"billing": "Charges, refunds, invoices",
"shipping": "Deliveries and returns",
"other": null
}
},
"anger": {
"type": "score",
"instructions": "How angry is the customer?",
"levels": ["calm", "annoyed", { "label": "furious", "description": "Threatens to leave" }]
}
}
}
}
resp = client.inference.decision(
inference_id="my-decision-endpoint",
input="I was charged twice for my order and nobody answers my emails.",
task_settings={
"questions": {
"is_complaint": {
"type": "predicate",
"instructions": "Is the customer complaining?"
},
"team": {
"type": "choice",
"instructions": "Which team should handle this?",
"choices": {
"billing": "Charges, refunds, invoices",
"shipping": "Deliveries and returns",
"other": None
}
},
"anger": {
"type": "score",
"instructions": "How angry is the customer?",
"levels": [
"calm",
"annoyed",
{
"label": "furious",
"description": "Threatens to leave"
}
]
}
}
},
)
const response = await client.inference.decision({
inference_id: "my-decision-endpoint",
input: "I was charged twice for my order and nobody answers my emails.",
task_settings: {
questions: {
is_complaint: {
type: "predicate",
instructions: "Is the customer complaining?",
},
team: {
type: "choice",
instructions: "Which team should handle this?",
choices: {
billing: "Charges, refunds, invoices",
shipping: "Deliveries and returns",
other: null,
},
},
anger: {
type: "score",
instructions: "How angry is the customer?",
levels: [
"calm",
"annoyed",
{
label: "furious",
description: "Threatens to leave",
},
],
},
},
},
});
response = client.inference.decision(
inference_id: "my-decision-endpoint",
body: {
"input": "I was charged twice for my order and nobody answers my emails.",
"task_settings": {
"questions": {
"is_complaint": {
"type": "predicate",
"instructions": "Is the customer complaining?"
},
"team": {
"type": "choice",
"instructions": "Which team should handle this?",
"choices": {
"billing": "Charges, refunds, invoices",
"shipping": "Deliveries and returns",
"other": nil
}
},
"anger": {
"type": "score",
"instructions": "How angry is the customer?",
"levels": [
"calm",
"annoyed",
{
"label": "furious",
"description": "Threatens to leave"
}
]
}
}
}
}
)
$resp = $client->inference()->decision([
"inference_id" => "my-decision-endpoint",
"body" => [
"input" => "I was charged twice for my order and nobody answers my emails.",
"task_settings" => [
"questions" => [
"is_complaint" => [
"type" => "predicate",
"instructions" => "Is the customer complaining?",
],
"team" => [
"type" => "choice",
"instructions" => "Which team should handle this?",
"choices" => [
"billing" => "Charges, refunds, invoices",
"shipping" => "Deliveries and returns",
"other" => null,
],
],
"anger" => [
"type" => "score",
"instructions" => "How angry is the customer?",
"levels" => array(
"calm",
"annoyed",
[
"label" => "furious",
"description" => "Threatens to leave",
],
),
],
],
],
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"input":"I was charged twice for my order and nobody answers my emails.","task_settings":{"questions":{"is_complaint":{"type":"predicate","instructions":"Is the customer complaining?"},"team":{"type":"choice","instructions":"Which team should handle this?","choices":{"billing":"Charges, refunds, invoices","shipping":"Deliveries and returns","other":null}},"anger":{"type":"score","instructions":"How angry is the customer?","levels":["calm","annoyed",{"label":"furious","description":"Threatens to leave"}]}}}}' "$ELASTICSEARCH_URL/_inference/decision/my-decision-endpoint"
var response = await client.Inference
.DecisionAsync(inferenceId: "my-decision-endpoint", d1 => d1
.Input("I was charged twice for my order and nobody answers my emails.")
.TaskSettings(d2 => d2
.Questions(d3 => d3
.Predicate("is_complaint", d4 => d4
.Instructions("Is the customer complaining?")
)
.Choice("team", d4 => d4
.Choices(new Dictionary<string, string?>()
{
{ "billing", "Charges, refunds, invoices" },
{ "shipping", "Deliveries and returns" },
{ "other", null }
})
.Instructions("Which team should handle this?")
)
.Score("anger", d4 => d4
.Instructions("How angry is the customer?")
.Levels(["calm", "annoyed", new DecisionScoreLevelObject()
{
Description = "Threatens to leave",
Label = "furious"
}])
)
)
)
);
{
"input": "I was charged twice for my order and nobody answers my emails.",
"task_settings": {
"questions": {
"is_complaint": {
"type": "predicate",
"instructions": "Is the customer complaining?"
},
"team": {
"type": "choice",
"instructions": "Which team should handle this?",
"choices": {
"billing": "Charges, refunds, invoices",
"shipping": "Deliveries and returns",
"other": null
}
},
"anger": {
"type": "score",
"instructions": "How angry is the customer?",
"levels": ["calm", "annoyed", { "label": "furious", "description": "Threatens to leave" }]
}
}
}
}
{
"decision": {
"answers": {
"is_complaint": {
"type": "predicate",
"probability": 0.94
},
"team": {
"type": "choice",
"choice": "billing",
"probabilities": [
{ "value": "billing", "probability": 0.91 },
{ "value": "shipping", "probability": 0.04 },
{ "value": "other", "probability": 0.05 }
],
"confidence": 0.89
},
"anger": {
"type": "score",
"score": 1.4,
"probabilities": [
{ "value": 0, "label": "calm", "probability": 0.1 },
{ "value": 1, "label": "annoyed", "probability": 0.4 },
{ "value": 2, "label": "furious", "probability": 0.5 }
],
"confidence": 0.62
}
}
}
}