Provide Source Documents When Calling the LLM
The following code sample demonstrates how to provide source documents to the LLM when calling llm.generateText(options).
This sample creates two documents using llm.createDocument(options) that contain information about emperor penguins. These documents are provided as additional context when calling llm.generateText(options). The LLM uses information in the provided documents to augment its response using retrieval-augmented generation (RAG). For more information about RAG, see What is Retrieval-Augmented Generation (RAG)?
If the LLM uses information in the provided documents to generate its response, the llm.Response object that is returned from llm.generateText(options) includes a list of citations (as llm.Citation objects). These citations indicate which source documents the information was taken from.
For instructions about how to run a SuiteScript 2.1 code snippet in the debugger, see On-Demand Debugging of SuiteScript 2.1 Scripts.
This sample script uses the require
function so that you can copy it into the SuiteScript Debugger and test it. You must use the define
function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
/**
* @NApiVersion 2.1
*/
require(['N/llm'], function(llm) {
const doc1 = llm.createDocument({
id: "doc1",
data: "Emperor penguins are the tallest."
});
const doc2 = llm.createDocument({
id: "doc2",
data: "Emperor penguins only live in the Sahara desert."
});
llm.generateText({
prompt: "Where do the tallest penguins live?",
documents: [doc1, doc2],
modelFamily: llm.ModelFamily.COHERE_COMMAND_R,
modelParameters: {
maxTokens: 1000,
temperature: 0.2,
topK: 3,
topP: 0.7,
frequencyPenalty: 0.4,
presencePenalty: 0
}
});
});