GenAI functions in APL help you analyze and process GenAI conversation data, including messages, token usage, costs, and conversation metadata. These functions are useful when working with logs or data from large language models (LLMs) and AI systems.

When to use GenAI functions

Use GenAI functions when you need to:

  • Extract specific information from AI conversation logs, such as user prompts, assistant responses, or system prompts
  • Calculate token costs and usage metrics for LLM API calls
  • Analyze conversation structure and flow, including turn counts and message roles
  • Process and filter conversation messages based on roles or content
  • Determine pricing information for different AI models
  • Detect truncation or tool calls in AI responses

Available GenAI functions

Function Description
genai_concat_contents Concatenates message contents from a conversation array
genai_conversation_turns Counts the number of conversation turns
genai_cost Calculates the total cost for input and output tokens
genai_estimate_tokens Estimates the number of tokens in a text string
genai_extract_assistant_response Extracts the assistant’s response from a conversation
genai_extract_function_results Extracts function call results from messages
genai_extract_system_prompt Extracts the system prompt from a conversation
genai_extract_tool_calls Extracts tool calls from messages
genai_extract_user_prompt Extracts the user prompt from a conversation
genai_get_content_by_index Gets message content by index position
genai_get_content_by_role Gets message content by role
genai_get_pricing Gets pricing information for a specific model
genai_get_role Gets the role of a message at a specific index
genai_has_tool_calls Checks if messages contain tool calls
genai_input_cost Calculates the cost for input tokens
genai_is_truncated Checks if a response was truncated
genai_message_roles Extracts all message roles from a conversation
genai_output_cost Calculates the cost for output tokens

Good evening

I'm here to help you with the docs.

I
AIBased on your context