Prompt

A prompt record represents a generative artificial intelligence (AI) prompt. Generative AI prompts are the instructions given to a large language model (LLM). The Text Enhance feature uses prompts to provide instructions to the LLM to generate or modify text. For more information, see Text Enhance. You can also manage prompt records using SuiteScript. For more information, see N/llm Module.

A prompt record includes information about the prompt and the LLM to send the prompt to, such as:

The internal ID for this record is prompt.

For help working with this record in the UI, see Prompt Studio.

Note:

For information about using the SuiteScript Records Browser, see Working with the SuiteScript Records Browser in the NetSuite Help Center.

For information about scripting with this record in SuiteScript, see the following help topics:

Supported Script Types

The prompt record is scriptable in both client and server SuiteScript.

Supported Functions

The prompt record is partially scriptable — it can be created, updated, and deleted using SuiteScript.

Certain fields cannot be updated after a prompt record is created. You can update the values of these fields in your scripts, but you will receive an error if you try to save the record with the updated values.

Code Sample

The following code sample demonstrates how to create a prompt record, set field values, and save the prompt record. The sample also calls llm.evaluatePrompt(options) and llm.evaluatePrompt.promise(options) to test the new prompt.

            require(['N/record', 'N/llm'], function(record, llm) {
    const rec = record.create({
        type: "prompt"
    });
     
    rec.setValue({
        fieldId: "name",
        value: "Test"
    });
    rec.setValue({
        fieldId: "prompttype",
        value: "CUSTOM"
    });
    rec.setValue({
        fieldId: "modelfamily",
        value: "COHERE_COMMAND_R"
    });
    rec.setValue({
        fieldId: "template",
        value: "${mandatoryVariable} <#if optionalVariable?has_content>${optionalVariable}<#else>World</#if>"
    });
     
    const id = rec.save();
     
    try {
        llm.evaluatePrompt({
            id: id
        });
    }
    catch (e){
        if (e.name === "TEMPLATE_PROCESSING_EXCEPTION")
            log.debug("Exception", "Expected exception was thrown");
    }
     
    const response = llm.evaluatePrompt({
        id: id,
        variables: {
            mandatoryVariable: "Hello",
            optionalVariable: "People"
        }
    });
    if ("Hello People" === response.chatHistory[0].text)
        log.debug("Evaluation", "Correct prompt got evaluated");
         
    llm.evaluatePrompt.promise({
        id: id,
        variables: {
            mandatoryVariable: "Hello", optionalVariable: "World"
        }
    }).then(function(response) {
        if ("Hello World" === response.chatHistory[0].text)
            log.debug("Evaluation", "Correct prompt got evaluated");
        record.delete({
            type: "prompt",
            id: id
        });
        debugger;
    })
}); 

          

Related Topics

General Notices