|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIX. - Grok / X - API > !Response Analysis > AIX. - Artificial Intelligence Extended Utility |
MiniRobotLanguage (MRL)
AIX.Analyze
Analyze Grok API Response Data
Intention
Analyze Command: Process and Extract Response Details
The Analyze command processes a raw Grok API response to extract detailed information, including text content, word count, finish reason, token usage, and function call status.
It supports both text and vision-based responses, with optional clipboard copying, and stores results for further use or debugging.
It is part of the AIX - Grok / X - API suite.
The Analyze command leverages the HTP_AnalyzeGrokResponse subroutine to parse a raw JSON response from the Grok API, extracting key details such as the content, word count, finish reason, total tokens, and whether the response includes a function call.
It accepts up to six parameters: the raw response, an optional pre-parsed text response, a vision mode flag, a clipboard copy flag, and two optional return variables for storing the analyzed content and metadata.
The command uses the W_JSON_* functions from the JSON Wide-Library to handle parsing and supports Unicode text. Results are stored in variables or AIX_ globals for later access, with an option to copy content to the clipboard (limited to 1MB).
Analyzing the response is valuable for:
•Insight: Extract detailed metrics (e.g., tokens, word count) to monitor API usage and performance.
•Debugging: Identify issues like malformed responses or unexpected function calls.
•Automation: Process vision or text responses programmatically, with optional clipboard output for manual review.
Call the command with a minimum of one parameter (the raw response) and up to six parameters to customize the analysis.
The raw response ($$RAW) is the JSON string from a prior AIX.Ask or AIX.AskVision call. Optional parameters include a pre-parsed text response ($$TEXT), a vision flag (VISION), a clipboard copy flag (CLIP), and two return variables ($$REA, $$REB) for content and metadata.
The command processes the response using HTP_AnalyzeGrokResponse, storing results in the specified variables or AIX_ globals. No additional API costs are incurred as of March 18, 2025, since it operates locally on existing data.
Example Usage
AIX.Ask|Describe a cat|$$RAW
AIX.Analyze|$$RAW|$$TXT|0|1|$$CONTENT|$$META
DBP.Content: $$CONTENT ; Displays 'Content: [cat description]'
DBP.Metadata: $$META ; Displays word count, finish reason, etc.
Analyzes a text response, copies to clipboard, and stores content and metadata in variables.
AIX.AskVision|image.jpg|Describe this|$$RAW
AIX.Analyze|$$RAW||1|0|$$VIS|$$INFO
DBP.Vision Content: $$VIS ; Displays vision description
DBP.Vision Info: $$INFO ; Displays metadata
ENR.
Analyzes a vision response without clipboard copying.
Illustration
┌──────────────┬──────────────┬──────────────┬──────────────┐
│ Param # │ Required? │ Type │ Description │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 0 ($$RAW) │ Yes │ STRING │ Raw JSON │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 1 ($$TEXT) │ No │ WSTRING │ Pre-parsed │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 2 (VISION) │ No │ LONG │ Vision flag │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 3 (CLIP) │ No │ LONG │ Clipboard │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 4 ($$REA) │ No │ STRING │ Content var │
├──────────────┼──────────────┼──────────────┼──────────────┤
│ 5 ($$REB) │ No │ STRING │ Metadata var │
└──────────────┴──────────────┴──────────────┴──────────────┘
Illustration of parameter structure and usage.
Syntax
AIX.Analyze|$$RAW[|$$TEXT][|VISION][|CLIP][|$$REA][|$$REB]
Parameter Explanation
$$RAW - (Required) The raw JSON response string from a Grok API call.
$$TEXT - (Optional) A pre-parsed text response (WSTRING) as a fallback if JSON parsing fails.
VISION - (Optional) A LONG value (0 = text-only, 1 = vision) to indicate response type.
CLIP - (Optional) A LONG value (-1 = use default, 0 = no copy, 1 = copy to clipboard) to control clipboard behavior.
$$REA - (Optional) A variable to store the extracted content (e.g., text or tool call JSON).
$$REB - (Optional) A variable to store metadata (word count, finish reason, tokens, function call flag).
Example
AIX.Ask|What is AI?|$$RAW
AIX.Analyze|$$RAW|||1|$$RES|$$MET
DBP.Response: $$RES ; Displays 'Content: [AI description]'
DBP.Metadata: $$MET ; Displays detailed metrics
ENR.
Analyzes a text response with clipboard copying enabled.
Remarks
- Requires a valid raw JSON response; malformed data may result in errors logged via SetError.
- Vision mode (1) treats responses as text descriptions; images are not directly returned.
- Clipboard copying is limited to 1MB; large responses may be truncated or fail.
Limitations
- Requires at least one parameter; fewer than 2 or more than 7 parameters trigger an error.
- Does not support direct image analysis; vision mode relies on text descriptions.
- Clipboard operation may fail with very large Unicode strings due to Windows API limitations.
See also:
• AIX.Ask