Send a Prompt to the LLM and Receive a Response

The following sample sends a "Hello World" prompt to the default NetSuite large language model (LLM) and receives the response. It also shows the remaining free usage for the month.

For instructions about how to run a SuiteScript 2.1 code snippet in the debugger, see On-Demand Debugging of SuiteScript 2.1 Scripts. Step through the code until the line before the end of the script to see the response text returned from the LLM and the remaining free usage for the month.

Note:

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
*/
// This example shows how to query the default LLM
require(['N/llm'],
    function(llm) {        
        const response = llm.generateText({
            // modelFamily is optional. When omitted, the Cohere Command R model is used.
            // To try the Meta Llama model, remove the comment delimiter from the following line
            // modelFamily: llm.ModelFamily.META_LLAMA,
            prompt: "Hello World!",
            modelParameters: {
                maxTokens: 1000,
                temperature: 0.2,
                topK: 3,
                topP: 0.7,
                frequencyPenalty: 0.4,
                presencePenalty: 0
            }
        });
        const responseText = response.text;
        const remainingUsage = llm.getRemainingFreeUsage(); // View remaining monthly free usage
    }); 

        

Related Topics:

General Notices