Utilizing the N/llm Module for Generative AI in NetSuite: A Developer's Guide

Explore the syntax and implementation details for using the N/llm module in SuiteScript to leverage generative AI features.

·View Oracle Docs

In the dynamic landscape of ERP systems and cloud computing, Oracle NetSuite continues to evolve, offering developers advanced tools to integrate artificial intelligence into applications. Leveraging the N/llm module in SuiteScript 2.1 provides an exciting opportunity to incorporate generative AI into your NetSuite environment.

Understanding the N/llm Module Syntax

The N/llm module is a part of SuiteScript 2.1, allowing NetSuite developers to interact with AI models for tasks like text generation, chatbots, and more. Let's delve into the syntax and its practical applications in NetSuite.

Consider this base structure for invoking the llm.generateText function:

const response = llm.generateText({
    preamble: "You are a successful salesperson. Answer in an enthusiastic, professional tone.",
    prompt: "Hello World!",
    documents: [doc1, doc2], // create documents using llm.createDocument(options)
    modelFamily: llm.ModelFamily.COHERE_COMMAND, 
    modelParameters: {
        maxTokens: 1000,
        temperature: 0.2,
        topK: 3,
        topP: 0.7,
        frequencyPenalty: 0.4,
        presencePenalty: 0
    },
    ociConfig: {
        userId: 'ocid1.user.oc1..aaaaaaaanld….exampleuserid',
        tenancyId: 'ocid1.tenancy.oc1..aaaaaaaabt….exampletenancyid',
        compartmentId: 'ocid1.compartment.oc1..aaaaaaaaph….examplecompartmentid',
        fingerprint: 'custsecret_oci_fingerprint',
        privateKey: 'custsecret_oci_private_key'
    }
});

Key Components

  • Preamble: Set the stage for the AI's response by giving a narrative context or tone, useful for maintaining consistent AI outputs.
  • Prompt: The actual request or input you want the model to respond to, shaping the nature of the output.
  • Documents: These are supplementary data points that can influence the AI's responses, added via llm.createDocument() method.
  • ModelFamily: Specifies the AI model to use, such as COHERE_COMMAND. Omitting this defaults to COHERE_COMMAND.
  • Model Parameters: Fine-tune the AI response, controlling factors like creativity (temperature) and result diversity (topP).
  • OCI Config: Credentials and configurations for Oracle Cloud Infrastructure, ensuring secure and authenticated access to your cloud resources.

Practical Applications

Using the N/llm module in NetSuite allows for innovative applications such as:

  • Implementing interactive chatbots that enhance user experience within NetSuite.
  • Automating text generation for customer interaction or sales emails.
  • Leveraging embeddings to find similar transaction records or SKUs in inventory.

Note: Always keep your OCI configurations secure, and regularly update your API keys to maintain security.

Best Practices

  1. Security First: Always manage and rotate your OCI and API credentials carefully to prevent unauthorized access.
  2. Test and Tweak: Utilize model parameters to experiment with output until you achieve the desired balance of creativity and accuracy.
  3. Leverage Documentation: The module provides comprehensive capabilities; explore documentation for specialized use cases, like embeddings.

Key Takeaways

  • The N/llm module in SuiteScript 2.1 introduces AI-driven functionalities within NetSuite.
  • Understanding and manipulating prompt, preamble, and model parameters is crucial for optimal outcomes.
  • Configuring OCI access is essential for leveraging cloud-based generative AI features securely.
  • Testing different model settings can significantly impact the quality and utility of AI outputs.
Source: Syntax — Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.