|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIU. - OpenAI API > !Output Formatting and Delivery > AIU. - Artificial Intelligence Utility |
MiniRobotLanguage (MRL)
AIU.SetResponseFormat
Set the Format for AI Responses (e.g., JSON or b64_json)
Intention
SetResponseFormat Command: Define Response Structure
The SetResponseFormat command specifies the format in which the AI delivers its responses, such as plain text, JSON, or base64-encoded JSON (b64_json).
This enables structured output for easier parsing or handling.
It’s part of the AIU - OpenAI API suite.
The SetResponseFormat command sets the response format for AI operations like AIU.Chat or AIU.Responses.
Options include "text" (default), "json" (structured data), or "b64_json" (base64-encoded JSON). The format affects how tokens (words or symbols) are structured, not their count or cost directly.
Setting the response format is useful for:
•Parsing: Use JSON for structured, machine-readable output.
•Encoding: Use b64_json for compact or secure data transfer.
•Simplicity: Stick to text for straightforward responses.
Provide a string parameter: "text", "json", or "b64_json".
The format choice may slightly affect token usage due to structural overhead (e.g., JSON brackets). Pricing (as of March 18, 2025, from OpenAI’s pricing page) includes:
•gpt-4o: $5.00/1M input tokens, $15.00/1M output tokens (128K context).
•gpt-4o-mini: $0.15/1M input tokens, $0.60/1M output tokens (128K context).
•gpt-3.5-turbo: $0.50/1M input tokens, $1.50/1M output tokens (16K context).
A JSON response might add ~10-20 tokens for formatting, slightly increasing costs (e.g., $0.000006-$0.000012 for gpt-4o-mini).
Example Usage
AIU.SetResponseFormat|json
AIU.Chat|What’s the capital of France?|$$RES
DBP.JSON Response: $$RES
Sets the format to JSON, returning a structured response like {"answer": "Paris"}.
Illustration
┌──────────────┬────────────────────┐
│ Format │ Response Example │
├──────────────┼────────────────────┤
│ text │ Paris │
├──────────────┼────────────────────┤
│ json │ {"answer": "Paris"}│
└──────────────┴────────────────────┘
Illustration of how response format changes output structure.
Syntax
AIU.SetResponseFormat|P1
AIU.Set_ResponseFormat|P1
Parameter Explanation
P1 - A string specifying the response format: "text", "json", or "b64_json". Required.
Example
AIU.SetResponseFormat|b64_json
AIU.Chat|List 3 colors|$$COL
DBP.Base64 Response: $$COL
ENR.
Remarks
- Default is typically "text"; other formats depend on model support.
- Structured formats (json, b64_json) may add minor token overhead.
Limitations
- Requires exactly one parameter; omitting or adding extra parameters causes an error.
- Invalid formats may result in errors or default behavior.
See also:
• AIU.Chat
• Response Format Configuration