When it fires
First thing in a chatbot request (POST /wp-json/kimaai/v1/chatbot), and in a search answer (assistantSurface search) before the answer cache is looked up. Nothing has run before it: after it come the masking of card numbers and IBANs, kimaai_chatbot_gate, the daily limit and the maximum message length, which counts the filtered message.
What the filter returns is the message from then on: the gate checks it, the provider gets it, and the chat history stores it. Return a string. In a search answer the cache key stays on the visitor’s own query.
Parameters
| Name | Type | Description |
|---|---|---|
prompt | mixed | The visitor’s message as the request sent it, a string. |
data | array | The request’s JSON body. |
request | WP_REST_Request | The REST request. |
Returns
mixed: The message to use, a string.
Example
add_filter(
'kimaai_chatbot_prompt',
function ($prompt, array $data, WP_REST_Request $request) {
if (!is_string($prompt)) {
return $prompt;
}
// One line, without the blank space a pasted text brings along.
return trim((string) preg_replace('/\s+/u', ' ', $prompt));
},
10,
3
);
Related
kimaai_chatbot_gate: blocks a message after this filter.kimaai_chatbot_ai_payload: changes the whole request to the provider, not only the message.