Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove underscore token usage. Improve documentation. #667

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';