|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > AI - Artificial Intelligence Commands > AIX. - Grok / X - API > !Response Behavior Settings > AIX. - Artificial Intelligence Extended Utility |
MiniRobotLanguage (MRL)
AIX.GetStream
Retrieve the Current Streaming Mode Setting
Intention
GetStream Command: Check Streaming Status in Detail
The GetStream command is designed to retrieve the current streaming mode setting of the AIX framework, which governs how responses from the Grok API are delivered during interactions.
This command is particularly useful for developers and users who need to verify or adjust the delivery mechanism of AI-generated content, ensuring it aligns with their application's requirements—whether for real-time processing, batch operations, or debugging purposes.
It is an integral part of the AIX - Grok / X - API suite, providing a means to monitor and maintain control over the response delivery workflow.
The GetStream command retrieves the current value of the AIX_Stream global variable, a critical configuration setting that determines whether the Grok API delivers responses in a streaming or non-streaming manner.
This variable is initialized to 0 (disabled) by default and can be modified using the AIX.SetStream command. The returned value is a LONG integer: 1 indicates streaming is enabled (responses are delivered incrementally), while 0 indicates it is disabled (responses are returned all at once).
The result can be stored in an optional variable or pushed onto the Top of Stack (TOS) for further manipulation within a script. This command is a local operation and does not incur additional API costs, making it an efficient way to monitor the streaming configuration as of March 18, 2025.
Retrieving the current streaming mode setting offers several practical benefits, including:
•Verification: Confirm whether streaming is active to ensure compatibility with your application's design, especially in real-time interfaces or batch processing systems.
•Debugging: Identify the streaming status to troubleshoot issues related to response delivery timing or incomplete data reception, particularly when integrating with external displays or logs.
•Dynamic Adjustment: Retrieve the current setting to decide whether to toggle streaming mode using AIX.SetStream based on runtime conditions, such as network latency or user preferences.
•Workflow Optimization: Monitor streaming settings across multiple script executions to maintain consistency or adapt to changing requirements, such as switching between interactive and offline modes.
The GetStream command can be invoked with an optional variable parameter to store the current streaming mode value, or without a parameter to push the value onto the Top of Stack (TOS) for subsequent use in a script.
The streaming mode setting directly impacts how responses from AIX.Ask and AIX.AskVision are handled by the AIX_ChatCompletion function. When streaming is enabled (1), responses are delivered incrementally, allowing for real-time processing or display, whereas a value of 0 delivers the entire response at once, which may be preferable for batch operations or when full context is needed immediately.
This command is a local operation and does not interact with the Grok API directly, meaning no additional costs are incurred beyond the standard API call costs as of March 18, 2025. However, the effectiveness of streaming depends on the API endpoint and model configuration, which should be verified in the AIX.GetEndpoint documentation.
Example Usage
AIX.SetStream|1
AIX.GetStream|$$STM
DBP.Current Streaming Mode: $$STM ; Displays '1' indicating streaming is enabled
AIX.Ask|Tell me a story|$$STORY
DBP.Streaming Story: $$STORY ; Incremental story output
Enables streaming, retrieves the setting into $$STM, and demonstrates incremental story delivery.
AIX.SetStream|0
AIX.GetStream
POP.$$MODE
DBP.Stack Streaming Mode: $$MODE ; Displays '0' indicating streaming is disabled
AIX.Ask|Explain AI|$$EXP
DBP.Full Explanation: $$EXP ; Single response output
ENR.
Disables streaming, retrieves the setting via the stack into $$MODE, and shows a full response at once.
Illustration
┌──────────────┬────────────────────┬────────────────────┐
│ Stream Value │ Delivery Method │ Use Case │
├──────────────┼────────────────────┼────────────────────┤
│ 1 │ Incremental │ Real-time chat │
├──────────────┼────────────────────┼────────────────────┤
│ 0 │ All at once │ Batch processing │
├──────────────┼────────────────────┼────────────────────┤
│ (default) │ All at once │ Initial setup │
└──────────────┴────────────────────┴────────────────────┘
Detailed illustration of streaming mode settings, delivery methods, and typical use cases.
Syntax
AIX.GetStream[|P1]
AIX.Get_Stream[|P1]
Parameter Explanation
P1 - (Optional) The variable where the streaming mode value (LONG, 0 or 1) is stored. If omitted, the value is placed on the Top of Stack (TOS) for later retrieval using commands like POP.
Example
AIX.SetStream|1
AIX.GetStream|$$MODE
IF ($$MODE = 1)
DBP.Streaming is enabled
ELSE
DBP.Streaming is disabled
ENDIF
AIX.Ask|Describe a sunset|$$SUN
DBP.Sunset Description: $$SUN ; Incremental if streaming enabled
ENR.
Checks the streaming mode and conditionally displays the status, followed by a streaming or non-streaming response.
Remarks
- The default streaming mode is 0 (disabled), unless modified by AIX.SetStream.
- Streaming mode is included in the API payload as "stream": true or "stream": false via the AIX_CreateGrokJSONPayload function, affecting how HTP_CallGrokAPI processes the response.
- When streaming is enabled, the HTP_AnalyzeGrokResponse subroutine may need to handle partial responses, which could require custom scripting to assemble the full content if needed.
- The clipboard behavior, controlled by AIX.SetClipboardOutput, may be affected by streaming mode, as incremental data might not be fully copied until the response is complete.
Limitations
- Accepts zero or one parameter; providing additional parameters may result in an error depending on the MiniRobotLanguage (MRL) interpreter's error handling.
- Only retrieves the current streaming mode and does not provide historical data or statistics about past streaming behaviors.
- Streaming support depends on the Grok API endpoint and model; some configurations may ignore the streaming setting or require specific headers, which should be checked using AIX.GetEndpoint.
- Incremental responses from streaming may not be fully compatible with all downstream processing steps, such as clipboard operations limited to %MAX_CLIPBOARD_SIZE (1MB), potentially requiring manual aggregation.
See also:
• AIX.Ask