@launchdarkly/server-sdk-ai 0.6.0 → 0.7.0
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 +7 -0
- package/__tests__/LDAIConfigTrackerImpl.test.ts +85 -3
- package/dist/LDAIConfigTrackerImpl.d.ts +1 -0
- package/dist/LDAIConfigTrackerImpl.d.ts.map +1 -1
- package/dist/LDAIConfigTrackerImpl.js +28 -11
- package/dist/LDAIConfigTrackerImpl.js.map +1 -1
- package/dist/api/config/LDAIConfigTracker.d.ts +18 -0
- package/dist/api/config/LDAIConfigTracker.d.ts.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/enums/LDFeedbackKind.html +6 -6
- package/docs/functions/createBedrockTokenUsage.html +4 -4
- package/docs/functions/initAi.html +4 -4
- package/docs/index.html +4 -4
- package/docs/interfaces/LDAIClient.html +5 -5
- package/docs/interfaces/LDAIConfig.html +9 -9
- package/docs/interfaces/LDAIConfigTracker.html +33 -12
- package/docs/interfaces/LDMessage.html +6 -6
- package/docs/interfaces/LDModelConfig.html +7 -7
- package/docs/interfaces/LDProviderConfig.html +5 -5
- package/docs/interfaces/LDTokenUsage.html +7 -7
- package/docs/types/LDAIDefaults.html +4 -4
- package/package.json +1 -1
- package/src/LDAIConfigTrackerImpl.ts +27 -11
- package/src/api/config/LDAIConfigTracker.ts +19 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDTokenUsage | @launchdarkly/server-sdk-ai - v0.
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDTokenUsage | @launchdarkly/server-sdk-ai - v0.7.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/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
2
2
|
<div class="tsd-toolbar-contents container">
|
|
3
3
|
<div class="table-cell" id="tsd-search" data-base="..">
|
|
4
4
|
<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"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<div id="tsd-toolbar-links"></div></div>
|
|
7
7
|
<ul class="results">
|
|
8
8
|
<li class="state loading">Preparing search index...</li>
|
|
9
|
-
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.
|
|
9
|
+
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.7.0</a></div>
|
|
10
10
|
<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"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
11
11
|
<div class="container container-main">
|
|
12
12
|
<div class="col-content">
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
<ul class="tsd-hierarchy">
|
|
25
25
|
<li><span class="target">LDTokenUsage</span></li></ul></section><aside class="tsd-sources">
|
|
26
26
|
<ul>
|
|
27
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
27
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/d723e62/packages/sdk/server-ai/src/api/metrics/LDTokenUsage.ts#L4">api/metrics/LDTokenUsage.ts:4</a></li></ul></aside>
|
|
28
28
|
<section class="tsd-panel-group tsd-index-group">
|
|
29
29
|
<section class="tsd-panel tsd-index-panel">
|
|
30
30
|
<details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary">
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
</div>
|
|
46
46
|
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
|
|
47
47
|
<ul>
|
|
48
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
48
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/d723e62/packages/sdk/server-ai/src/api/metrics/LDTokenUsage.ts#L13">api/metrics/LDTokenUsage.ts:13</a></li></ul></aside></section>
|
|
49
49
|
<section class="tsd-panel tsd-member"><a id="output" class="tsd-anchor"></a>
|
|
50
50
|
<h3 class="tsd-anchor-link"><span>output</span><a href="#output" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="#icon-anchor"></use></svg></a></h3>
|
|
51
51
|
<div class="tsd-signature"><span class="tsd-kind-property">output</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
</div>
|
|
54
54
|
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
|
|
55
55
|
<ul>
|
|
56
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
56
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/d723e62/packages/sdk/server-ai/src/api/metrics/LDTokenUsage.ts#L18">api/metrics/LDTokenUsage.ts:18</a></li></ul></aside></section>
|
|
57
57
|
<section class="tsd-panel tsd-member"><a id="total" class="tsd-anchor"></a>
|
|
58
58
|
<h3 class="tsd-anchor-link"><span>total</span><a href="#total" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="#icon-anchor"></use></svg></a></h3>
|
|
59
59
|
<div class="tsd-signature"><span class="tsd-kind-property">total</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</div>
|
|
62
62
|
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
|
|
63
63
|
<ul>
|
|
64
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
64
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/d723e62/packages/sdk/server-ai/src/api/metrics/LDTokenUsage.ts#L8">api/metrics/LDTokenUsage.ts:8</a></li></ul></aside></section></section></div>
|
|
65
65
|
<div class="col-sidebar">
|
|
66
66
|
<div class="page-menu">
|
|
67
67
|
<div class="tsd-navigation settings">
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
<li><a href="#output" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-1024"></use></svg><span>output</span></a></li>
|
|
86
86
|
<li><a href="#total" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-1024"></use></svg><span>total</span></a></li></ul></div></details></div>
|
|
87
87
|
<div class="site-menu">
|
|
88
|
-
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.
|
|
88
|
+
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.7.0</span></a>
|
|
89
89
|
<ul class="tsd-small-nested-navigation">
|
|
90
90
|
<li><a href="../enums/LDFeedbackKind.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-8"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.45 16V7.24H14.49V8.224H10.518V10.936H14.07V11.908H10.518V15.016H14.49V16H9.45Z" fill="var(--color-text)"></path></g></svg><span>LDFeedback<wbr/>Kind</span></a></li>
|
|
91
91
|
<li><a href="LDAIClient.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-256"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)"></path></g></svg><span>LDAIClient</span></a></li>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDAIDefaults | @launchdarkly/server-sdk-ai - v0.
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LDAIDefaults | @launchdarkly/server-sdk-ai - v0.7.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/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
2
2
|
<div class="tsd-toolbar-contents container">
|
|
3
3
|
<div class="table-cell" id="tsd-search" data-base="..">
|
|
4
4
|
<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"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<div id="tsd-toolbar-links"></div></div>
|
|
7
7
|
<ul class="results">
|
|
8
8
|
<li class="state loading">Preparing search index...</li>
|
|
9
|
-
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.
|
|
9
|
+
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@launchdarkly/server-sdk-ai - v0.7.0</a></div>
|
|
10
10
|
<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"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
11
11
|
<div class="container container-main">
|
|
12
12
|
<div class="col-content">
|
|
@@ -30,7 +30,7 @@ a tracker and <code>enabled</code> is optional.</p>
|
|
|
30
30
|
<div class="tsd-comment tsd-typography"></div></li></ul></div>
|
|
31
31
|
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
|
|
32
32
|
<ul>
|
|
33
|
-
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/
|
|
33
|
+
<li>Defined in <a href="https://github.com/launchdarkly/js-core/blob/d723e62/packages/sdk/server-ai/src/api/config/LDAIConfig.ts#L77">api/config/LDAIConfig.ts:77</a></li></ul></aside></div>
|
|
34
34
|
<div class="col-sidebar">
|
|
35
35
|
<div class="page-menu">
|
|
36
36
|
<div class="tsd-navigation settings">
|
|
@@ -47,7 +47,7 @@ a tracker and <code>enabled</code> is optional.</p>
|
|
|
47
47
|
<div class="tsd-theme-toggle">
|
|
48
48
|
<h4 class="uppercase">Theme</h4><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>
|
|
49
49
|
<div class="site-menu">
|
|
50
|
-
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.
|
|
50
|
+
<nav class="tsd-navigation"><a href="../index.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>@launchdarkly/server-<wbr/>sdk-<wbr/>ai -<wbr/> v0.7.0</span></a>
|
|
51
51
|
<ul class="tsd-small-nested-navigation">
|
|
52
52
|
<li><a href="../enums/LDFeedbackKind.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-8"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.45 16V7.24H14.49V8.224H10.518V10.936H14.07V11.908H10.518V15.016H14.49V16H9.45Z" fill="var(--color-text)"></path></g></svg><span>LDFeedback<wbr/>Kind</span></a></li>
|
|
53
53
|
<li><a href="../interfaces/LDAIClient.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-256"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)"></path></g></svg><span>LDAIClient</span></a></li>
|
package/package.json
CHANGED
|
@@ -30,11 +30,15 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
30
30
|
|
|
31
31
|
async trackDurationOf<TRes>(func: () => Promise<TRes>): Promise<TRes> {
|
|
32
32
|
const startTime = Date.now();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
try {
|
|
34
|
+
// Be sure to await here so that we can track the duration of the function and also handle errors.
|
|
35
|
+
const result = await func();
|
|
36
|
+
return result;
|
|
37
|
+
} finally {
|
|
38
|
+
const endTime = Date.now();
|
|
39
|
+
const duration = endTime - startTime; // duration in milliseconds
|
|
40
|
+
this.trackDuration(duration);
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
trackFeedback(feedback: { kind: LDFeedbackKind }): void {
|
|
@@ -49,6 +53,13 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
49
53
|
trackSuccess(): void {
|
|
50
54
|
this._trackedMetrics.success = true;
|
|
51
55
|
this._ldClient.track('$ld:ai:generation', this._context, this._getTrackData(), 1);
|
|
56
|
+
this._ldClient.track('$ld:ai:generation:success', this._context, this._getTrackData(), 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
trackError(): void {
|
|
60
|
+
this._trackedMetrics.success = false;
|
|
61
|
+
this._ldClient.track('$ld:ai:generation', this._context, this._getTrackData(), 1);
|
|
62
|
+
this._ldClient.track('$ld:ai:generation:error', this._context, this._getTrackData(), 1);
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
async trackOpenAIMetrics<
|
|
@@ -60,12 +71,17 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
60
71
|
};
|
|
61
72
|
},
|
|
62
73
|
>(func: () => Promise<TRes>): Promise<TRes> {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
try {
|
|
75
|
+
const result = await this.trackDurationOf(func);
|
|
76
|
+
this.trackSuccess();
|
|
77
|
+
if (result.usage) {
|
|
78
|
+
this.trackTokens(createOpenAiUsage(result.usage));
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
this.trackError();
|
|
83
|
+
throw err;
|
|
67
84
|
}
|
|
68
|
-
return result;
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
trackBedrockConverseMetrics<
|
|
@@ -82,7 +98,7 @@ export class LDAIConfigTrackerImpl implements LDAIConfigTracker {
|
|
|
82
98
|
if (res.$metadata?.httpStatusCode === 200) {
|
|
83
99
|
this.trackSuccess();
|
|
84
100
|
} else if (res.$metadata?.httpStatusCode && res.$metadata.httpStatusCode >= 400) {
|
|
85
|
-
|
|
101
|
+
this.trackError();
|
|
86
102
|
}
|
|
87
103
|
if (res.metrics && res.metrics.latencyMs) {
|
|
88
104
|
this.trackDuration(res.metrics.latencyMs);
|
|
@@ -50,6 +50,11 @@ export interface LDAIConfigTracker {
|
|
|
50
50
|
*/
|
|
51
51
|
trackSuccess(): void;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* An error was encountered during generation.
|
|
55
|
+
*/
|
|
56
|
+
trackError(): void;
|
|
57
|
+
|
|
53
58
|
/**
|
|
54
59
|
* Track sentiment about the generation.
|
|
55
60
|
*
|
|
@@ -59,6 +64,12 @@ export interface LDAIConfigTracker {
|
|
|
59
64
|
|
|
60
65
|
/**
|
|
61
66
|
* Track the duration of execution of the provided function.
|
|
67
|
+
*
|
|
68
|
+
* If the provided function throws, then this method will also throw.
|
|
69
|
+
* In the case the provided function throws, this function will still record the duration.
|
|
70
|
+
*
|
|
71
|
+
* This function does not automatically record an error when the function throws.
|
|
72
|
+
*
|
|
62
73
|
* @param func The function to track the duration of.
|
|
63
74
|
* @returns The result of the function.
|
|
64
75
|
*/
|
|
@@ -67,6 +78,12 @@ export interface LDAIConfigTracker {
|
|
|
67
78
|
/**
|
|
68
79
|
* Track an OpenAI operation.
|
|
69
80
|
*
|
|
81
|
+
* This function will track the duration of the operation, the token usage, and the success or error status.
|
|
82
|
+
*
|
|
83
|
+
* If the provided function throws, then this method will also throw.
|
|
84
|
+
* In the case the provided function throws, this function will record the duration and an error.
|
|
85
|
+
* A failed operation will not have any token usage data.
|
|
86
|
+
*
|
|
70
87
|
* @param func Function which executes the operation.
|
|
71
88
|
* @returns The result of the operation.
|
|
72
89
|
*/
|
|
@@ -85,6 +102,8 @@ export interface LDAIConfigTracker {
|
|
|
85
102
|
/**
|
|
86
103
|
* Track an operation which uses Bedrock.
|
|
87
104
|
*
|
|
105
|
+
* This function will track the duration of the operation, the token usage, and the success or error status.
|
|
106
|
+
*
|
|
88
107
|
* @param res The result of the Bedrock operation.
|
|
89
108
|
* @returns The input operation.
|
|
90
109
|
*/
|