StreamedResponse Object Members

Explore the StreamedResponse object members in SuiteScript 2.1 for detailed LLM response management.

·3 min read·View Oracle Docs

The StreamedResponse object in SuiteScript 2.1 provides essential members for managing responses from a Large Language Model (LLM). This object allows developers to access various attributes such as chat history and citations, enabling dynamic interactions with AI-generated content.

What Are the Members of the StreamedResponse Object?

The StreamedResponse object includes several properties, each serving a unique purpose:

Member NameReturn TypeSupported Script TypesDescription
StreamedResponse.chatHistoryllm.ChatMessage[]Server scriptsThis is a list of chat messages.
StreamedResponse.citationsllm.Citation[]Server scriptsThis contains a list of citations used in the response.
StreamedResponse.documentsllm.Document[]Server scriptsThis property holds a list of documents relevant to the response.
StreamedResponse.modelstringServer scriptsIndicates the model used to generate the response.
StreamedResponse.textstringServer scriptsThe actual text generated by the LLM.
StreamedResponse.toolCallsllm.ToolCall[]Server scriptsLists tool calls requested by the LLM.

Understanding Each Member

  • chatHistory: This property provides insights into the ongoing conversation. However, it's important to note that its value isn't accessible until the entire response from the LLM has been generated.
  • citations and documents: Both properties are useful for tracking the sources of information that were leveraged to produce the output, enhancing transparency and credibility.
  • model: Knowing which model generated the response can help evaluate the response's context and accuracy.
  • text: This is the output content provided by the LLM, which developers will typically utilize within their applications.

Handling Errors in StreamedResponse

A common error associated with the StreamedResponse is READ_ONLY, which occurs if there attempt to set any of its properties.

Practical Example

The following code snippet demonstrates how to use the StreamedResponse object in a SuiteScript 2.1 server script:

suitescript
1const response = llm.generateTextStreamed({
2 prompt: 'Hello World'
3});
4
5var iter = response.iterator();
6iters.each(function(token) {
7 log.debug('token.value: ' + token.value);
8 log.debug('response.text: ' + response.text);
9 return true;
10});
11
12const responseChatHistory = response.chatHistory;

This example shows how to generate a streamed response and iterate through tokens while logging valuable information, including the final text produced by the LLM.

Key Considerations

When working with the StreamedResponse object:

  • Ensure that you are familiar with the overall structure and capabilities of the llm module in SuiteScript 2.1.
  • Understand the timing of when properties like chatHistory and text become available.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The StreamedResponse object comprises several valuable members for handling AI outputs.
  • Understanding the individual properties aids in effective LLM response management.
  • Careful handling of error conditions can help maintain optimal performance while interacting with the LLM.

Frequently Asked Questions (4)

What types of scripts support the StreamedResponse object in SuiteScript 2.1?
The StreamedResponse object is supported by server scripts in SuiteScript 2.1.
Are there any error conditions to be aware of when using the StreamedResponse object?
Yes, a common error associated with the StreamedResponse is 'READ_ONLY', which occurs if there is an attempt to set any of its properties.
When does the chatHistory property of the StreamedResponse object become available?
The chatHistory property becomes available only after the entire response from the LLM has been generated.
How do the citations and documents properties of the StreamedResponse object benefit users?
The citations and documents properties are useful for tracking the sources of information utilized to produce the output, which enhances transparency and credibility.
Source: StreamedResponse Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →