@launchdarkly/server-sdk-ai 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +14 -4
- package/__tests__/LDAIClientImpl.test.ts +136 -0
- package/__tests__/LDAIConfigTrackerImpl.test.ts +270 -0
- package/__tests__/TokenUsage.test.ts +78 -0
- package/dist/LDAIClientImpl.d.ts.map +1 -1
- package/dist/LDAIClientImpl.js +4 -1
- package/dist/LDAIClientImpl.js.map +1 -1
- package/dist/api/LDAIClient.d.ts +27 -20
- package/dist/api/LDAIClient.d.ts.map +1 -1
- package/dist/api/metrics/index.d.ts +0 -1
- package/dist/api/metrics/index.d.ts.map +1 -1
- package/dist/api/metrics/index.js +0 -1
- package/dist/api/metrics/index.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/enums/LDFeedbackKind.html +4 -4
- package/docs/functions/createBedrockTokenUsage.html +1 -1
- package/docs/functions/initAi.html +2 -2
- package/docs/index.html +5 -3
- package/docs/interfaces/LDAIClient.html +15 -14
- package/docs/interfaces/LDAIConfig.html +5 -5
- package/docs/interfaces/LDAIConfigTracker.html +9 -9
- package/docs/interfaces/LDGenerationConfig.html +4 -4
- package/docs/interfaces/LDMessage.html +4 -4
- package/docs/interfaces/LDModelConfig.html +3 -3
- package/docs/interfaces/LDTokenUsage.html +5 -5
- package/jest.config.js +7 -0
- package/package.json +2 -2
- package/src/LDAIClientImpl.ts +4 -1
- package/src/api/LDAIClient.ts +27 -20
- package/src/api/metrics/index.ts +0 -1
- package/src/index.ts +8 -0
- package/dist/api/metrics/UnderScoreTokenUsage.d.ts +0 -3
- package/dist/api/metrics/UnderScoreTokenUsage.d.ts.map +0 -1
- package/dist/api/metrics/UnderScoreTokenUsage.js +0 -12
- package/dist/api/metrics/UnderScoreTokenUsage.js.map +0 -1
- package/docs/functions/createUnderscoreTokenUsage.html +0 -1
- package/src/api/metrics/UnderScoreTokenUsage.ts +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@launchdarkly/server-sdk-ai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "LaunchDarkly AI SDK for Server-Side JavaScript",
|
|
5
5
|
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/sdk/server-ai",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
|
|
17
17
|
"lint:fix": "yarn run lint --fix",
|
|
18
18
|
"check": "yarn prettier && yarn lint && yarn build && yarn test",
|
|
19
|
-
"test": "
|
|
19
|
+
"test": "jest"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"launchdarkly",
|
package/src/LDAIClientImpl.ts
CHANGED
|
@@ -41,7 +41,10 @@ export class LDAIClientImpl implements LDAIClient {
|
|
|
41
41
|
const value: VariationContent = await this._ldClient.variation(key, context, defaultValue);
|
|
42
42
|
// We are going to modify the contents before returning them, so we make a copy.
|
|
43
43
|
// This isn't a deep copy and the application developer should not modify the returned content.
|
|
44
|
-
const config: LDGenerationConfig = {
|
|
44
|
+
const config: LDGenerationConfig = {};
|
|
45
|
+
if (value.model) {
|
|
46
|
+
config.model = { ...value.model };
|
|
47
|
+
}
|
|
45
48
|
const allVariables = { ...variables, ldctx: context };
|
|
46
49
|
|
|
47
50
|
if (value.prompt) {
|
package/src/api/LDAIClient.ts
CHANGED
|
@@ -10,44 +10,50 @@ export interface LDAIClient {
|
|
|
10
10
|
/**
|
|
11
11
|
* Parses and interpolates a template string with the provided variables.
|
|
12
12
|
*
|
|
13
|
-
* @param template
|
|
14
|
-
* @param variables
|
|
13
|
+
* @param template The template string to be parsed and interpolated.
|
|
14
|
+
* @param variables An object containing the variables to be used for interpolation.
|
|
15
15
|
* @returns The interpolated string.
|
|
16
16
|
*/
|
|
17
17
|
interpolateTemplate(template: string, variables: Record<string, unknown>): string;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Retrieves and processes
|
|
21
|
-
* variables.
|
|
20
|
+
* Retrieves and processes an AI configuration based on the provided key, LaunchDarkly context,
|
|
21
|
+
* and variables. This includes the model configuration and the processed prompts.
|
|
22
22
|
*
|
|
23
|
-
* @param key
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param variables - A map of key-value pairs representing dynamic variables to be injected into
|
|
23
|
+
* @param key The key of the AI configuration.
|
|
24
|
+
* @param context The LaunchDarkly context object that contains relevant information about the
|
|
25
|
+
* current environment, user, or session. This context may influence how the configuration is
|
|
26
|
+
* processed or personalized.
|
|
27
|
+
* @param variables A map of key-value pairs representing dynamic variables to be injected into
|
|
29
28
|
* the prompt template. The keys correspond to placeholders within the template, and the values
|
|
30
29
|
* are the corresponding replacements.
|
|
31
|
-
* @param defaultValue
|
|
32
|
-
*
|
|
30
|
+
* @param defaultValue A fallback value containing model configuration and prompts. This will
|
|
31
|
+
* be used if the configurationuration is not available from launchdarkly.
|
|
33
32
|
*
|
|
34
|
-
* @returns The processed prompt after all variables have been
|
|
35
|
-
*
|
|
33
|
+
* @returns The AI configurationuration including a processed prompt after all variables have been
|
|
34
|
+
* substituted in the stored prompt template. This will also include a `tracker` used to track
|
|
35
|
+
* the state of the AI operation. If the configuration cannot be accessed from LaunchDarkly, then
|
|
36
|
+
* the return value will include information from the defaultValue.
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
38
39
|
* ```
|
|
39
40
|
* const key = "welcome_prompt";
|
|
40
41
|
* const context = {...};
|
|
41
42
|
* const variables = {username: 'john'};
|
|
42
|
-
* const defaultValue = {
|
|
43
|
+
* const defaultValue = {
|
|
44
|
+
* enabled: false,
|
|
45
|
+
* };
|
|
43
46
|
*
|
|
44
47
|
* const result = modelConfig(key, context, defaultValue, variables);
|
|
45
48
|
* // Output:
|
|
46
49
|
* {
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
50
|
+
* enabled: true,
|
|
51
|
+
* config: {
|
|
52
|
+
* modelId: "gpt-4o",
|
|
53
|
+
* temperature: 0.2,
|
|
54
|
+
* maxTokens: 4096,
|
|
55
|
+
* userDefinedKey: "myValue",
|
|
56
|
+
* },
|
|
51
57
|
* prompt: [
|
|
52
58
|
* {
|
|
53
59
|
* role: "system",
|
|
@@ -57,7 +63,8 @@ export interface LDAIClient {
|
|
|
57
63
|
* role: "user",
|
|
58
64
|
* content: "Explain how you're an amazing GPT."
|
|
59
65
|
* }
|
|
60
|
-
* ]
|
|
66
|
+
* ],
|
|
67
|
+
* tracker: ...
|
|
61
68
|
* }
|
|
62
69
|
* ```
|
|
63
70
|
*/
|
package/src/api/metrics/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the API reference for the LaunchDarkly AI SDK for Server-Side JavaScript.
|
|
3
|
+
*
|
|
4
|
+
* In typical usage, you will call {@link initAi} once at startup time to obtain an instance of
|
|
5
|
+
* {@link LDAIClient}, which provides access to all of the SDK's functionality.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
1
9
|
import { LDAIClient } from './api/LDAIClient';
|
|
2
10
|
import { LDAIClientImpl } from './LDAIClientImpl';
|
|
3
11
|
import { LDClientMin } from './LDClientMin';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnderScoreTokenUsage.d.ts","sourceRoot":"","sources":["../../../src/api/metrics/UnderScoreTokenUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,GAAG,GAAG,YAAY,CAMlE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createUnderscoreTokenUsage = void 0;
|
|
4
|
-
function createUnderscoreTokenUsage(data) {
|
|
5
|
-
return {
|
|
6
|
-
total: data.total_tokens || 0,
|
|
7
|
-
input: data.prompt_tokens || 0,
|
|
8
|
-
output: data.completion_tokens || 0,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
exports.createUnderscoreTokenUsage = createUnderscoreTokenUsage;
|
|
12
|
-
//# sourceMappingURL=UnderScoreTokenUsage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnderScoreTokenUsage.js","sourceRoot":"","sources":["../../../src/api/metrics/UnderScoreTokenUsage.ts"],"names":[],"mappings":";;;AAEA,SAAgB,0BAA0B,CAAC,IAAS;IAClD,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,YAAY,IAAI,CAAC;QAC7B,KAAK,EAAE,IAAI,CAAC,aAAa,IAAI,CAAC;QAC9B,MAAM,EAAE,IAAI,CAAC,iBAAiB,IAAI,CAAC;KACpC,CAAC;AACJ,CAAC;AAND,gEAMC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>createUnderscoreTokenUsage | @launchdarkly/server-sdk-ai - v0.1.0</title><meta name="description" content="Documentation for @launchdarkly/server-sdk-ai"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.1.0</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../index.html">@launchdarkly/server-sdk-ai</a></li><li><a href="createUnderscoreTokenUsage.html">createUnderscoreTokenUsage</a></li></ul><h1>Function createUnderscoreTokenUsage</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="createUnderscoreTokenUsage" class="tsd-anchor"></a><span class="tsd-kind-call-signature">create<wbr/>Underscore<wbr/>Token<wbr/>Usage</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">data</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/LDTokenUsage.html" class="tsd-signature-type tsd-kind-interface">LDTokenUsage</a><a href="#createUnderscoreTokenUsage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">data</span>: <span class="tsd-signature-type">any</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../interfaces/LDTokenUsage.html" class="tsd-signature-type tsd-kind-interface">LDTokenUsage</a></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/cc35e9ed1c2a3fe9d6cacb7e9654b9160e90879c/packages/sdk/server-ai/src/api/metrics/UnderScoreTokenUsage.ts#L3">api/metrics/UnderScoreTokenUsage.ts:3</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@launchdarkly/server-sdk-ai - v0.1.0</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|