llm.generateTextStreamed(options)
The content in this help topic pertains to SuiteScript 2.1.
|
Method Description |
Returns the streamed response from the LLM for a given prompt. This method is similar to llm.generateText(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:
In this example, This method consumes AI Units. For more information, see NetSuite AI Units and NetSuite Features and AI Units FAQ. |
|
Returns |
|
|
Aliases |
Note:
These aliases use the same parameters and can throw the same errors as the llm.generateTextStreamed(options) method. |
|
Supported Script Types |
Server scripts For more information, see SuiteScript 2.1 Script Types. |
|
Governance |
100 |
|
Module |
|
|
Since |
2025.1 |
Parameters
|
Parameter |
Type |
Required / Optional |
Description |
Since |
|---|---|---|---|---|
|
|
string |
required if |
Prompt for the LLM. If you specify a set of tool results using the |
2025.1 |
|
|
optional |
Chat history to be taken into consideration. |
2025.1 |
|
|
|
optional |
A list of documents to provide additional context for the LLM to generate the response. This parameter is supported only for Cohere models. |
2025.1 |
|
|
|
optional |
An image to query. You can send an image (as a file.File object) to the LLM and ask questions about the image. For example, you can ask for the following:
Note:
Image processing is available only when using the Cohere Command A Vision model ( For more information about creating and loading files, see N/file Module. |
2026.1 |
|
|
|
enum |
optional |
Specifies the LLM to use. Use llm.ModelFamily to set the value. If not specified, the Cohere Command A model ( |
2025.1 |
|
|
Object |
optional |
Parameters of the model. For more information about the model parameters, refer to Offered Pretrained Foundational Models in Generative AI in the Oracle Cloud Infrastructure Documentation. |
2025.1 |
|
|
number |
optional |
A penalty that's assigned to a token when that token appears frequently. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. See Model Parameter Values by LLM for valid values. |
2025.1 |
|
|
number |
optional |
The maximum number of tokens the LLM is allowed to generate. The average number of tokens per word is 3. See Model Parameter Values by LLM for valid values. |
2025.1 |
|
|
number |
optional |
A penalty that's assigned to each token when it appears in the output to encourage generating outputs with tokens that haven't been used. Similar to |
2025.1 |
|
|
number |
optional |
Defines a range of randomness for the response. A lower temperature will lean toward the highest probability tokens and expected answers, and a higher temperature will deviate toward random and unconventional responses. A lower value works best for responses that must be more factual or accurate, and a higher value works best for getting more creative responses. See Model Parameter Values by LLM for valid values. |
2025.1 |
|
|
number |
optional |
Determines how many tokens are considered for generation at each step. See Model Parameter Values by LLM for valid values. |
2025.1 |
|
|
number |
optional |
Sets the probability, which ensures that only the most likely tokens with total probability mass of |
2025.1 |
|
|
Object |
optional |
Important:
This object is no longer supported. Any values specified in this object are ignored. |
2025.1 |
|
|
string |
optional |
Preamble override for the LLM. A preamble is the Initial context or guiding message for an LLM. For more details about using a preamble, refer to Offered Pretrained Foundational Models in Generative AI in the Oracle Cloud Infrastructure Documentation. |
2025.1 |
|
|
string |
optional |
Specifies the safety mode to use. This parameter is supported for Cohere models only. Use values from the llm.SafetyMode enum to set the value of this parameter. If not specified, the |
2025.1 |
|
|
number |
optional |
Timeout in milliseconds, defaults to 30,000. |
2025.1 |
|
|
optional |
The tool results to use to generate a follow-up response. When you call llm.generateTextStreamed(options) and provide a set of tools using the When you specify a value for this parameter, any prompt you provide using the |
2025.2 |
|
|
|
llm.Tool[] |
optional |
The tools that are available for the LLM to request. |
2025.2 |
Errors
|
Error Code |
Thrown If |
|---|---|
|
|
The |
|
|
|
|
|
One or more unrecognized model parameters have been used. |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
Documents provided using the |
|
|
The response from the LLM included sensitive or inappropriate content that is restricted by the specified safety mode. |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
The |
|
|
The number of parallel requests to the LLM is greater than 5. |
Syntax
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.generateTextStreamed({
// preamble is optional for Cohere models
preamble: "You are a successful salesperson. Answer in an enthusiastic, professional tone.",
prompt: "Hello World!",
documents: [doc1, doc2], // create documents using llm.createDocument(options)
modelFamily: llm.ModelFamily.COHERE_COMMAND, // uses COHERE_COMMAND when modelFamily is omitted
modelParameters: {
maxTokens: 1000,
temperature: 0.2,
topK: 3,
topP: 0.7,
frequencyPenalty: 0.4,
presencePenalty: 0
}
});
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