AIN. - AnythingLLM AI

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

AIN. - AnythingLLM AI

AIN.SetResponseFormat

Previous Top Next


MiniRobotLanguage (MRL)

 

AIN.SetResponseFormat
Set the Response Format for AnythingLLM API Calls

 

Intention

 

SetResponseFormat Command: Configuring API Response Format
 
The SetResponseFormat command allows you to specify the format in which responses from the AnythingLLM API are returned, such as "json" or plain text.

This customization ensures compatibility with your script’s parsing needs.

It’s part of the AIN - AnythingLLM AI suite.

 

What is the SetResponseFormat Command?

 

This command sets the AIN_RespFormat global variable, determining how API responses are formatted.

By default, it is set to "json" if no value is provided or if an empty string is passed, ensuring structured data output that can be parsed easily.

 

Why Do You Need It?

 

Controlling the response format is essential for:

Compatibility: Match the format to your script’s JSON parsing or text processing capabilities.

Flexibility: Adapt to different use cases, such as raw text for simple outputs or JSON for detailed data.

Consistency: Ensure predictable response handling across multiple API calls.

 

How to Use the SetResponseFormat Command?

 

Use this command to define the expected format before making API calls like AIN.Ask or AIN.AskV.

If no parameter is provided or it’s empty, it defaults to "json".

 

Example Usage

 

AIN.SetResponseFormat|json

AIN.Ask|What is AI?|$$RES

DBP.JSON Response: $$RES

 

This sets the response format to JSON and retrieves a text chat completion.

 

Illustration

 

┌────────────────────┐

│ Response Format    │

├────────────────────┤

│ json (default)     │

└────────────────────┘

Setting the response format to JSON for structured output.

 

Syntax

 

AIN.SetResponseFormat|P1

AIN.Set_ResponseFormat|P1

 

Parameter Explanation

 

P1 - The desired response format (e.g., "json" or "text"). If empty or omitted, defaults to "json".

 

Example

 

AIN.SetResponseFormat|text

AIN.Ask|Hello, how are you?|$$OUT

DBP.Raw Text Response: $$OUT

ENR.

 

Remarks

 

- The format affects how AIN.GetRaw retrieves the response.

- Use AIN.GetResponseFormat to verify the current setting.

 

Limitations

 

- Only "json" is explicitly supported as of March 20, 2025; other formats depend on API capabilities.

- Invalid formats may lead to parsing errors in subsequent API calls.

 

See also:

 

AIN.GetResponseFormat

AIN.Ask

AIN.AskV

Response Format Configuration