Evaluate an Existing Prompt and Receive a Response

The following sample evaluates an existing prompt, sends it to the default NetSuite large language model (LLM), and receives the response. The sample also shows the remaining free usage for the month.

In this sample, the llm.evaluatePrompt(options) method loads an existing prompt with an ID of stdprompt_gen_purch_desc_invt_item. This prompt applies to an inventory item record in NetSuite, and it uses several variables that represent fields on this record type, such as item ID, stock description, and vendor name. The method replaces the variables in the prompt with the values you specify, then sends it to the LLM and returns the response.

You can create and manage prompts using Prompt Studio. You can also use Prompt Studio to generate a SuiteScript example that uses the llm.evaluatePrompt(options) 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.

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
*/
require(['N/llm'],
    function(llm) {        
        const response = llm.evaluatePrompt({
            id: 'stdprompt_gen_purch_desc_invt_item',
            variables: {
                "form": {
                    "itemid": "My Inventory Item",
                    "stockdescription": "This is the stock description of the item.",
                    "vendorname": "My Item Vendor Inc.",
                    "isdropshipitem": "false",
                    "isspecialorderitem": "true",
                    "displayname": "My Amazing Inventory Item"
                },
                "text": "This is the purchase description of the item."
            }
        });
        const responseText = response.text;
        const remainingUsage = llm.getRemainingFreeUsage(); // View remaining monthly free usage
    }); 

        

General Notices