Skip to content

Commit

Permalink
fix: Remove underscore token usage. Improve documentation. (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Nov 7, 2024
1 parent 3683f0a commit 5fe36fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
47 changes: 27 additions & 20 deletions packages/sdk/server-ai/src/api/LDAIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,50 @@ export interface LDAIClient {
/**
* Parses and interpolates a template string with the provided variables.
*
* @param template - The template string to be parsed and interpolated.
* @param variables - An object containing the variables to be used for interpolation.
* @param template The template string to be parsed and interpolated.
* @param variables An object containing the variables to be used for interpolation.
* @returns The interpolated string.
*/
interpolateTemplate(template: string, variables: Record<string, unknown>): string;

/**
* Retrieves and processes a prompt template based on the provided key, LaunchDarkly context, and
* variables.
* Retrieves and processes an AI configuration based on the provided key, LaunchDarkly context,
* and variables. This includes the model configuration and the processed prompts.
*
* @param key - A unique identifier for the prompt template. This key is used to fetch the correct
* prompt from storage or configuration.
* @param context - The LaunchDarkly context object that contains relevant information about the
* current environment, user, or session. This context may influence how the prompt is processed
* or personalized.
* @param variables - A map of key-value pairs representing dynamic variables to be injected into
* @param key The key of the AI configuration.
* @param context 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.
* @param variables 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.
* @param defaultValue - A fallback value to be used if the prompt template associated with the
* key is not found or if any errors occur during processing.
* @param defaultValue A fallback value containing model configuration and prompts. This will
* be used if the configurationuration is not available from launchdarkly.
*
* @returns The processed prompt after all variables have been substituted in the stored prompt
* template. If the prompt cannot be retrieved or processed, the `defaultValue` is returned.
* @returns 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.
*
* @example
* ```
* const key = "welcome_prompt";
* const context = {...};
* const variables = {username: 'john'};
* const defaultValue = {};
* const defaultValue = {
* enabled: false,
* };
*
* const result = modelConfig(key, context, defaultValue, variables);
* // Output:
* {
* modelId: "gpt-4o",
* temperature: 0.2,
* maxTokens: 4096,
* userDefinedKey: "myValue",
* enabled: true,
* config: {
* modelId: "gpt-4o",
* temperature: 0.2,
* maxTokens: 4096,
* userDefinedKey: "myValue",
* },
* prompt: [
* {
* role: "system",
Expand All @@ -57,7 +63,8 @@ export interface LDAIClient {
* role: "user",
* content: "Explain how you're an amazing GPT."
* }
* ]
* ],
* tracker: ...
* }
* ```
*/
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/sdk/server-ai/src/api/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './BedrockTokenUsage';
export * from './LDFeedbackKind';
export * from './LDTokenUsage';
export * from './UnderScoreTokenUsage';

0 comments on commit 5fe36fb

Please sign in to comment.