Member Junction
    Preparing search index...

    This class is an extension for the Nunjucks template engine that allows for the use of an AI prompt in a template.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    AllowFormattingText: string = "Do not use markdown, HTML, or any other special formatting."
    Tags: string[] = []

    One or more tags that represent case-sensitive tag names that will invoke this extension.

    NoRenderUserMessage: string = ...

    Why an {% AIPrompt %} tag fails in a render that has no user.

    Accessors

    • get ContextUser(): UserInfo

      The user this extension acts for: the user of the render in progress. An extension instance is shared by every render in the process, so it must read this at run time and never cache it. Inside a render that has no user it is undefined; it never falls back to the user the instance was constructed with, which is whichever caller first configured the engine. Outside a render it returns the constructed user.

      Returns UserInfo

    Methods

    • Executes AI prompt processing using the configured language model.

      Parameter Mapping from CallExtensionAsync:

      • In parse(): new nodes.CallExtensionAsync(this, 'run', params, [body])
      • Results in: run(context, params, body, callBack)

      The key difference from TemplateEmbed is that we pass [body] as the 4th parameter to CallExtensionAsync, which shifts the parameter order to include both params and body as separate arguments. The body contains the prompt text between the opening and closing tags.

      Parameters

      • context: any

        Nunjucks template rendering context containing variables and data

      • params: any

        Parsed parameters from the opening tag (AIModel, AllowFormatting, etc.)

      • body: any

        Function that returns the rendered prompt content between {% AIPrompt %} and {% endAIPrompt %}

      • callBack: NunjucksCallback

        Async callback function to return the AI-generated response or errors

      Returns void

      {% AIPrompt AIModel="gpt-4", AllowFormatting=true %}
      Generate a personalized greeting for {{ user.name }} who works as {{ user.jobTitle }}.
      Make it professional but warm.
      {% endAIPrompt %}