Interface for performing AI operations using LaunchDarkly.

Hierarchy

  • LDAIClient

Methods

Methods

  • Retrieves and processes an AI configuration based on the provided key, LaunchDarkly context, and variables. This includes the model configuration and the customized messages.

    Parameters

    • key: string

      The key of the AI configuration.

    • context: LDContext

      The LaunchDarkly context object that contains relevant information about the current environment, user, or session. This context may influence how the configuration is processed or personalized.

    • defaultValue: LDAIDefaults

      A fallback value containing model configuration and messages. This will be used if the configuration is not available from LaunchDarkly.

    • Optional variables: Record<string, unknown>

      A map of key-value pairs representing dynamic variables to be injected into the message content. The keys correspond to placeholders within the template, and the values are the corresponding replacements.

      Optional

    Returns Promise<LDAIConfig>

    The AI config, customized messages, and a tracker. If the configuration cannot be accessed from LaunchDarkly, then the return value will include information from the defaultValue. The returned tracker can be used to track AI operation metrics (latency, token usage, etc.).

    Example

    const key = "welcome_prompt";
    const context = {...};
    const variables = {username: 'john'};
    const defaultValue = {
    enabled: false,
    };

    const result = config(key, context, defaultValue, variables);
    // Output:
    {
    enabled: true,
    config: {
    modelId: "gpt-4o",
    temperature: 0.2,
    maxTokens: 4096,
    userDefinedKey: "myValue",
    },
    messages: [
    {
    role: "system",
    content: "You are an amazing GPT."
    },
    {
    role: "user",
    content: "Explain how you're an amazing GPT."
    }
    ],
    tracker: ...
    }

Generated using TypeDoc