Intent Detection - Detect what the user wants
Another feature of the AI studio is the ability to detect the intent of the user or to classify a given information and extract additional information based on the detected intent.
Lets consider this example use case for better understanding: An employee sends an email with a PDF as attachment. This PDF can be an invoice, a termination or a documentation. The AI can detect, which intent it is and can then additionally extract all required information from the document. For the invoice this could be the invoice numer and the positions for example, for the termination it could the contract number and for the documentation it could a short summary for example. Lets model this use case now in a PIPEFORCE pipeline:
pipeline: # Read email from inbox - imap.get: host: outlook.office365.com secret: my-office365-secret # Detect the intent in the email - ai.intent.detect: advice: intentCandidates: - intentId: "invoice" prompt: "Use this intent in case the attachment is an invoice." params: supplierAddress: prompt: Extract the supplier address from the invoice. invoiceNumber: prompt: Extract the invoice number from the invoice. totalAmount: prompt: Extract the total amount of the invoice in cents without any currency chars, separators or other special characters. - intentId: "temination" prompt: "Use this intent in case the attachment is a termination of a contract." params: contractNumber: prompt: Extract the contract number. customerNumber: prompt: Extract the customer number. reason: prompt: Summarize in one sentence the reason for the termination. - intentId: "documentation" prompt: "Use this intent in case the attachment is a documentation." params: summary: prompt: Create a short summary what this documentation is about.
After executing this pipeline, the response could look like this:
{ "params": { "supplierAddress": { "name": "supplierAddress", "value": "ABC Software (Germany) GmbH - Im Weg 3 - 12345 Worth", "required": false, "pass": true, "type": "string" }, "invoiceNumber": { "name": "invoiceNumber", "value": "123100401", "required": false, "pass": true, "type": "string" }, "totalAmount": { "name": "totalAmount", "value": "45353", "required": false, "pass": true, "type": "string" } }, "enabled": true, "intentId": "invoice", "command": null }
As you can see in this example, the command ai.intent.detect
is used and three intents are configured under advice.intentCandidates
for invoice, termination and documentation. Each with its own parameters to be extracted.
Each intent can have these attributes:
intentId
This attribute is mandatory and gives the intent a unique id. This should be an explainatory, unique name without special charaters or whitespaces.prompt
Each intent has anprompt
in order to instruct the AI about the criteria to select this intent. In case such an intent is selected by AI, additionally the parameters will be extracted from the input. This parameter is mandatory.params
The list of optional parameters to be detected in case this intent was selected.command
The optional name of the command to be executed in case this intent was detected. Note: AdditionallyrundDetectecCommand
must be set totrue
on theai.intent.detect
command which isfalse
by default.enabled
An intent can optionally be disabled by setting enabled = false. This is useful mainly for testing purposes for example. In this case only the other intents will be considered by the AI.
Intent Parameters
The params
section on each intent lists the parameters of the intent. These parameters will be automatically set in case the given intent was detected. They can later be used for further processing by calling a command of by passing them to external systems for example.
Each parameter can have a fixed/templated value
or its value can be detected by AI using the prompt
attribute.
All parameter attributes are explained below.
name
(optional)
The name of the parameter.
This attribute is optional. If not set, the params id will be used.
required
(optional)
Defines whether this parameter is required. In case it is required and its value is finally missing or cannot be detected by AI, an error is thrown and further execution stops.
The default value is false
.
type
(optional)
The data type of the parameter such as string
, boolean
, integer
, number
, json
If different from string and parameter is detected by AI, the AI also tries to convert to this format.
The default value is string
.
value
(optional)
The value
of the intent parameter.
This can be a fixed value (literal) or a template.
Templated values
The value can also be template string. By default the Mustache template syntax can be used which starts with {{
and ends with }}
. The variables advice
and intent
are passed as model context to the template. This way you can access for example settings and values of other parameters after they have been resolved by the AI in order to formulate the final parameter for a command.
See this example to construct a message out of advice parameters using a template:
... params: customerId: value: "1234567" message: value: "The customerId is: {{intent.params.customerId}}" ...
prompt
(optional)
For each parameter, an attribute prompt
instead of a value
can be set. Not both!
In this case the AI will auto-detect the value of the parameter by reading and applying this prompt on the input and setting the result on the value field automatically.
See this example where the subject
parameter for the mail.send
command will be auto-detected by AI:
... params: subject: prompt: "Use the subject from initial sender email" ...
As you can see in this example, there is no fixed value for parameter subject
set. Instead the AI was instructured to extract the value from the given email input.
Add Comment