llm.evaluatePromptStreamed(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Takes the ID of an existing prompt and values for variables used in the prompt and returns the streamed response from the LLM.

You can use this method to evaluate a prompt that's available in Prompt Studio by providing values for any variables that the prompt uses. The resulting prompt is sent to the LLM, and this method returns the LLM response, similar to the llm.generateText(options) method. For more information about Prompt Studio, see Prompt Studio.

This method is similar to llm.evaluatePrompt(options) but returns the LLM response as a stream. After calling this method, you can access the partial response (using the StreamedResponse.text property of the returned llm.StreamedResponse object) before the entire response has been generated. You can also use an iterator to examine each token returned by the LLM, as the following example shows:

                    var response = llm.evaluatePromptStreamed({
    id: -1
});
var iter = response.iterator();
iter.each(function(token){
    log.debug("token.value: " + token.value);
    log.debug("response.text: " + response.text);
    return true;
}) 

                  

In this example, token.value contains the values of each token returned by the LLM, and response.text contains the partial response up to and including that token. For more information about iterators in SuiteScript, see Iterator.

This method consumes AI Units. For more information, see NetSuite AI Units and NetSuite Features and AI Units FAQ.

Returns

llm.StreamedResponse

Aliases

llm.executePromptStreamed(options)

Note:

These aliases use the same parameters and can throw the same errors as the llm.evaluatePromptStreamed(options) method.

Supported Script Types

Server scripts

For more information, see SuiteScript 2.1 Script Types.

Governance

100

Module

N/llm Module

Since

2025.1

Parameters

Parameter

Type

Required / Optional

Description

Since

options.id

string | number

required

ID of the prompt to evaluate.

2025.1

options.ociConfig

Object

optional

Important:

This object is no longer supported. Any values specified in this object are ignored.

2025.1

options.timeout

number

optional

Timeout in milliseconds, defaults to 30,000.

2025.1

options.variables

Object

optional

Values for the variables that are used in the prompt. Provide these values as an object with key-value pairs. For an example, see the Syntax section.

You can use Prompt Studio to generate a SuiteScript example that uses this method and includes the variables for a prompt in the correct format. When viewing a prompt in Prompt Studio, click Show SuiteScript Example to generate SuiteScript code with all of the variables that prompt uses. You can then use this code in your scripts and provide a value for each variable.

2025.1

Errors

Error Code

Thrown If

SSS_MISSING_REQD_ARGUMENT

The options.id parameter is missing.

INVALID_ID_PREFIX

The prefix of the options.id parameter is not custprompt.

MAXIMUM_PARALLEL_REQUESTS_LIMIT_EXCEEDED

The number of parallel requests to the LLM is greater than 5.

TEMPLATE_PROCESSING_EXCEPTION

The template for the specified prompt contains errors and cannot be processed. For example, this error is thrown in the following cases:

  • The prompt template uses required variables that are not specified in the options.variables parameter.

  • The prompt template contains syntax errors, such as an opening if statement without a corresponding closing one.

Syntax

Important:

The following code sample shows the syntax for this member. It isn't a functional example. For a complete script example, see N/llm Module Script Samples.

            // Add additional code
...

const response = llm.evaluatePromptStreamed({
    id: -1,
    variables: {
        "form": {
            "itemid": "My Item",
            "stockdescription": "This is a custom item for my business.",
            "vendorname": "Item Supplier Inc.",
            "isdropshipitem": "false",
            "isspecialorderitem": "true",
            "displayname": "My Awesome Item"
        },
        "text": "This item increases productivity."
    }
});

var iter = response.iterator();
iter.each(function(token){
    log.debug("token.value: " + token.value);
    log.debug("response.text: " + response.text);
    return true;
})

...
// Add additional code 

          

Related Topics

General Notices