Parses and interpolates a template string with the provided variables.
The template string to be parsed and interpolated.
An object containing the variables to be used for interpolation.
The interpolated string.
Retrieves and processes an AI configuration based on the provided key, LaunchDarkly context, and variables. This includes the model configuration and the processed prompts.
The key of the AI configuration.
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.
A fallback value containing model configuration and prompts. This will be used if the configurationuration is not available from launchdarkly.
Optional
variables: Record<string, unknown>A map of key-value pairs representing dynamic variables to be injected into the prompt template. The keys correspond to placeholders within the template, and the values are the corresponding replacements.
The AI configurationuration including a processed prompt after all variables have been
substituted in the stored prompt template. This will also include a tracker
used to track
the state of the AI operation. If the configuration cannot be accessed from LaunchDarkly, then
the return value will include information from the defaultValue.
const key = "welcome_prompt";
const context = {...};
const variables = {username: 'john'};
const defaultValue = {
enabled: false,
};
const result = modelConfig(key, context, defaultValue, variables);
// Output:
{
enabled: true,
config: {
modelId: "gpt-4o",
temperature: 0.2,
maxTokens: 4096,
userDefinedKey: "myValue",
},
prompt: [
{
role: "system",
content: "You are an amazing GPT."
},
{
role: "user",
content: "Explain how you're an amazing GPT."
}
],
tracker: ...
}
Interface for performing AI operations using LaunchDarkly.