genai_extract_assistant_response
This page explains how to use the genai_extract_assistant_response function in APL.
The genai_extract_assistant_response function extracts the assistant’s response from a GenAI messages array. It returns the content of the last message with the 'assistant' role, which typically contains the AI model’s generated response to the user.
You can use this function to analyze AI responses, evaluate response quality, perform sentiment analysis on AI outputs, or track specific response patterns for monitoring and debugging.
Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| messages | dynamic | Yes | An array of message objects from a GenAI conversation. Each message typically contains role and content fields. |
Returns
Returns a string containing the content of the last assistant message in the conversation, or an empty string if no assistant message is found.
Example
Extract the assistant's response from a GenAI conversation.
Query
Output
| _time | ai_response |
|---|---|
| 2024-01-15T10:30:00Z | To reset your password, click the 'Forgot Password' link on the login page. |
| 2024-01-15T10:31:00Z | Business hours are Monday to Friday, 9 AM to 5 PM EST. |
This query extracts AI responses, helping you analyze response quality and patterns.
List of related functions
- genai_extract_user_prompt: Extracts the user's prompt. Use this to analyze what users are asking.
- genai_extract_system_prompt: Extracts the system prompt. Use this to understand how the AI is configured.
- genai_get_content_by_role: Gets content by any role. Use this when you need messages from roles other than assistant.
- genai_concat_contents: Concatenates all message contents. Use this when you need the full conversation instead of just the assistant's response.
- genai_has_tool_calls: Checks for tool calls in messages. Use this to detect when the assistant made function calls.