@launchdarkly/server-sdk-ai 0.14.1 → 0.15.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 +22 -0
- package/dist/index.cjs +1117 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1022 -0
- package/dist/index.d.ts +1022 -0
- package/dist/index.js +1071 -0
- package/dist/index.js.map +1 -0
- package/package.json +23 -6
- package/__tests__/Judge.test.ts +0 -521
- package/__tests__/LDAIClientImpl.test.ts +0 -594
- package/__tests__/LDAIConfigTrackerImpl.test.ts +0 -815
- package/__tests__/TokenUsage.test.ts +0 -119
- package/__tests__/TrackedChat.test.ts +0 -231
- package/dist/package.json +0 -53
- package/dist/src/LDAIClientImpl.d.ts +0 -39
- package/dist/src/LDAIClientImpl.d.ts.map +0 -1
- package/dist/src/LDAIClientImpl.js +0 -164
- package/dist/src/LDAIClientImpl.js.map +0 -1
- package/dist/src/LDAIConfigTrackerImpl.d.ts +0 -74
- package/dist/src/LDAIConfigTrackerImpl.d.ts.map +0 -1
- package/dist/src/LDAIConfigTrackerImpl.js +0 -207
- package/dist/src/LDAIConfigTrackerImpl.js.map +0 -1
- package/dist/src/LDClientMin.d.ts +0 -11
- package/dist/src/LDClientMin.d.ts.map +0 -1
- package/dist/src/LDClientMin.js +0 -3
- package/dist/src/LDClientMin.js.map +0 -1
- package/dist/src/api/LDAIClient.d.ts +0 -258
- package/dist/src/api/LDAIClient.d.ts.map +0 -1
- package/dist/src/api/LDAIClient.js +0 -3
- package/dist/src/api/LDAIClient.js.map +0 -1
- package/dist/src/api/chat/TrackedChat.d.ts +0 -72
- package/dist/src/api/chat/TrackedChat.d.ts.map +0 -1
- package/dist/src/api/chat/TrackedChat.js +0 -125
- package/dist/src/api/chat/TrackedChat.js.map +0 -1
- package/dist/src/api/chat/index.d.ts +0 -3
- package/dist/src/api/chat/index.d.ts.map +0 -1
- package/dist/src/api/chat/index.js +0 -19
- package/dist/src/api/chat/index.js.map +0 -1
- package/dist/src/api/chat/types.d.ts +0 -22
- package/dist/src/api/chat/types.d.ts.map +0 -1
- package/dist/src/api/chat/types.js +0 -3
- package/dist/src/api/chat/types.js.map +0 -1
- package/dist/src/api/config/LDAIConfigTracker.d.ts +0 -209
- package/dist/src/api/config/LDAIConfigTracker.d.ts.map +0 -1
- package/dist/src/api/config/LDAIConfigTracker.js +0 -3
- package/dist/src/api/config/LDAIConfigTracker.js.map +0 -1
- package/dist/src/api/config/LDAIConfigUtils.d.ts +0 -2
- package/dist/src/api/config/LDAIConfigUtils.d.ts.map +0 -1
- package/dist/src/api/config/LDAIConfigUtils.js +0 -145
- package/dist/src/api/config/LDAIConfigUtils.js.map +0 -1
- package/dist/src/api/config/index.d.ts +0 -3
- package/dist/src/api/config/index.d.ts.map +0 -1
- package/dist/src/api/config/index.js +0 -18
- package/dist/src/api/config/index.js.map +0 -1
- package/dist/src/api/config/types.d.ts +0 -206
- package/dist/src/api/config/types.d.ts.map +0 -1
- package/dist/src/api/config/types.js +0 -3
- package/dist/src/api/config/types.js.map +0 -1
- package/dist/src/api/index.d.ts +0 -7
- package/dist/src/api/index.d.ts.map +0 -1
- package/dist/src/api/index.js +0 -23
- package/dist/src/api/index.js.map +0 -1
- package/dist/src/api/judge/EvaluationSchemaBuilder.d.ts +0 -11
- package/dist/src/api/judge/EvaluationSchemaBuilder.d.ts.map +0 -1
- package/dist/src/api/judge/EvaluationSchemaBuilder.js +0 -52
- package/dist/src/api/judge/EvaluationSchemaBuilder.js.map +0 -1
- package/dist/src/api/judge/Judge.d.ts +0 -63
- package/dist/src/api/judge/Judge.d.ts.map +0 -1
- package/dist/src/api/judge/Judge.js +0 -151
- package/dist/src/api/judge/Judge.js.map +0 -1
- package/dist/src/api/judge/index.d.ts +0 -3
- package/dist/src/api/judge/index.d.ts.map +0 -1
- package/dist/src/api/judge/index.js +0 -6
- package/dist/src/api/judge/index.js.map +0 -1
- package/dist/src/api/judge/types.d.ts +0 -37
- package/dist/src/api/judge/types.d.ts.map +0 -1
- package/dist/src/api/judge/types.js +0 -3
- package/dist/src/api/judge/types.js.map +0 -1
- package/dist/src/api/metrics/BedrockTokenUsage.d.ts +0 -7
- package/dist/src/api/metrics/BedrockTokenUsage.d.ts.map +0 -1
- package/dist/src/api/metrics/BedrockTokenUsage.js +0 -12
- package/dist/src/api/metrics/BedrockTokenUsage.js.map +0 -1
- package/dist/src/api/metrics/LDAIMetrics.d.ts +0 -17
- package/dist/src/api/metrics/LDAIMetrics.d.ts.map +0 -1
- package/dist/src/api/metrics/LDAIMetrics.js +0 -3
- package/dist/src/api/metrics/LDAIMetrics.js.map +0 -1
- package/dist/src/api/metrics/LDFeedbackKind.d.ts +0 -14
- package/dist/src/api/metrics/LDFeedbackKind.d.ts.map +0 -1
- package/dist/src/api/metrics/LDFeedbackKind.js +0 -18
- package/dist/src/api/metrics/LDFeedbackKind.js.map +0 -1
- package/dist/src/api/metrics/LDTokenUsage.d.ts +0 -18
- package/dist/src/api/metrics/LDTokenUsage.d.ts.map +0 -1
- package/dist/src/api/metrics/LDTokenUsage.js +0 -3
- package/dist/src/api/metrics/LDTokenUsage.js.map +0 -1
- package/dist/src/api/metrics/OpenAiUsage.d.ts +0 -7
- package/dist/src/api/metrics/OpenAiUsage.d.ts.map +0 -1
- package/dist/src/api/metrics/OpenAiUsage.js +0 -13
- package/dist/src/api/metrics/OpenAiUsage.js.map +0 -1
- package/dist/src/api/metrics/VercelAISDKTokenUsage.d.ts +0 -9
- package/dist/src/api/metrics/VercelAISDKTokenUsage.d.ts.map +0 -1
- package/dist/src/api/metrics/VercelAISDKTokenUsage.js +0 -13
- package/dist/src/api/metrics/VercelAISDKTokenUsage.js.map +0 -1
- package/dist/src/api/metrics/index.d.ts +0 -7
- package/dist/src/api/metrics/index.d.ts.map +0 -1
- package/dist/src/api/metrics/index.js +0 -23
- package/dist/src/api/metrics/index.js.map +0 -1
- package/dist/src/api/providers/AIProvider.d.ts +0 -52
- package/dist/src/api/providers/AIProvider.d.ts.map +0 -1
- package/dist/src/api/providers/AIProvider.js +0 -88
- package/dist/src/api/providers/AIProvider.js.map +0 -1
- package/dist/src/api/providers/AIProviderFactory.d.ts +0 -39
- package/dist/src/api/providers/AIProviderFactory.d.ts.map +0 -1
- package/dist/src/api/providers/AIProviderFactory.js +0 -102
- package/dist/src/api/providers/AIProviderFactory.js.map +0 -1
- package/dist/src/api/providers/index.d.ts +0 -3
- package/dist/src/api/providers/index.d.ts.map +0 -1
- package/dist/src/api/providers/index.js +0 -19
- package/dist/src/api/providers/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -19
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -29
- package/dist/src/index.js.map +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1379
- package/docs/classes/AIProvider.html +0 -210
- package/docs/classes/AIProviderFactory.html +0 -208
- package/docs/classes/Judge.html +0 -322
- package/docs/classes/TrackedChat.html +0 -322
- package/docs/enums/LDFeedbackKind.html +0 -115
- package/docs/functions/createBedrockTokenUsage.html +0 -94
- package/docs/functions/createOpenAiUsage.html +0 -94
- package/docs/functions/createVercelAISDKTokenUsage.html +0 -98
- package/docs/functions/initAi.html +0 -93
- package/docs/index.html +0 -136
- package/docs/interfaces/ChatResponse.html +0 -130
- package/docs/interfaces/EvalScore.html +0 -119
- package/docs/interfaces/JudgeResponse.html +0 -139
- package/docs/interfaces/LDAIAgentConfig.html +0 -178
- package/docs/interfaces/LDAIAgentConfigDefault.html +0 -155
- package/docs/interfaces/LDAIAgentRequestConfig.html +0 -129
- package/docs/interfaces/LDAIClient.html +0 -449
- package/docs/interfaces/LDAICompletionConfig.html +0 -178
- package/docs/interfaces/LDAICompletionConfigDefault.html +0 -155
- package/docs/interfaces/LDAIConfig.html +0 -158
- package/docs/interfaces/LDAIConfigDefault.html +0 -133
- package/docs/interfaces/LDAIConfigTracker.html +0 -530
- package/docs/interfaces/LDAIJudgeConfig.html +0 -178
- package/docs/interfaces/LDAIJudgeConfigDefault.html +0 -155
- package/docs/interfaces/LDAIMetrics.html +0 -121
- package/docs/interfaces/LDJudge.html +0 -119
- package/docs/interfaces/LDJudgeConfiguration.html +0 -109
- package/docs/interfaces/LDLogger.html +0 -189
- package/docs/interfaces/LDMessage.html +0 -119
- package/docs/interfaces/LDModelConfig.html +0 -139
- package/docs/interfaces/LDProviderConfig.html +0 -105
- package/docs/interfaces/LDTokenUsage.html +0 -129
- package/docs/interfaces/StructuredResponse.html +0 -129
- package/docs/types/LDAIConfigDefaultKind.html +0 -81
- package/docs/types/LDAIConfigKind.html +0 -81
- package/docs/types/LDAIConfigMode.html +0 -81
- package/docs/types/SupportedAIProvider.html +0 -81
- package/docs/variables/SUPPORTED_AI_PROVIDERS.html +0 -81
- package/jest.config.js +0 -7
- package/src/LDAIClientImpl.ts +0 -327
- package/src/LDAIConfigTrackerImpl.ts +0 -288
- package/src/LDClientMin.ts +0 -18
- package/src/api/LDAIClient.ts +0 -325
- package/src/api/chat/TrackedChat.ts +0 -163
- package/src/api/chat/index.ts +0 -2
- package/src/api/chat/types.ts +0 -24
- package/src/api/config/LDAIConfigTracker.ts +0 -238
- package/src/api/config/LDAIConfigUtils.ts +0 -212
- package/src/api/config/index.ts +0 -3
- package/src/api/config/types.ts +0 -260
- package/src/api/index.ts +0 -6
- package/src/api/judge/EvaluationSchemaBuilder.ts +0 -54
- package/src/api/judge/Judge.ts +0 -218
- package/src/api/judge/index.ts +0 -2
- package/src/api/judge/types.ts +0 -41
- package/src/api/metrics/BedrockTokenUsage.ts +0 -13
- package/src/api/metrics/LDAIMetrics.ts +0 -18
- package/src/api/metrics/LDFeedbackKind.ts +0 -13
- package/src/api/metrics/LDTokenUsage.ts +0 -19
- package/src/api/metrics/OpenAiUsage.ts +0 -13
- package/src/api/metrics/VercelAISDKTokenUsage.ts +0 -15
- package/src/api/metrics/index.ts +0 -6
- package/src/api/providers/AIProvider.ts +0 -94
- package/src/api/providers/AIProviderFactory.ts +0 -152
- package/src/api/providers/index.ts +0 -2
- package/src/index.ts +0 -24
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -21
- package/tsconfig.ref.json +0 -7
- package/typedoc.json +0 -5
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { LDAIConfigTracker } from './LDAIConfigTracker';
|
|
2
|
-
/**
|
|
3
|
-
* Information about prompts.
|
|
4
|
-
*/
|
|
5
|
-
export interface LDMessage {
|
|
6
|
-
/**
|
|
7
|
-
* The role of the prompt.
|
|
8
|
-
*/
|
|
9
|
-
role: 'user' | 'assistant' | 'system';
|
|
10
|
-
/**
|
|
11
|
-
* Content for the prompt.
|
|
12
|
-
*/
|
|
13
|
-
content: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Configuration related to the model.
|
|
17
|
-
*/
|
|
18
|
-
export interface LDModelConfig {
|
|
19
|
-
/**
|
|
20
|
-
* The ID of the model.
|
|
21
|
-
*/
|
|
22
|
-
name: string;
|
|
23
|
-
/**
|
|
24
|
-
* Model specific parameters.
|
|
25
|
-
*/
|
|
26
|
-
parameters?: {
|
|
27
|
-
[index: string]: unknown;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Additional user-specified parameters.
|
|
31
|
-
*/
|
|
32
|
-
custom?: {
|
|
33
|
-
[index: string]: unknown;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export interface LDProviderConfig {
|
|
37
|
-
/**
|
|
38
|
-
* The name of the provider.
|
|
39
|
-
*/
|
|
40
|
-
name: string;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Configuration for a single judge attachment.
|
|
44
|
-
*/
|
|
45
|
-
export interface LDJudge {
|
|
46
|
-
/** The key of the judge AI Config */
|
|
47
|
-
key: string;
|
|
48
|
-
/** Sampling rate for evaluation (0.0 to 1.0) */
|
|
49
|
-
samplingRate: number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Configuration for judge attachment to AI Configs.
|
|
53
|
-
*/
|
|
54
|
-
export interface LDJudgeConfiguration {
|
|
55
|
-
/** Array of judge configurations */
|
|
56
|
-
judges: LDJudge[];
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Base AI Config interface for default implementations with optional enabled property.
|
|
60
|
-
*/
|
|
61
|
-
export interface LDAIConfigDefault {
|
|
62
|
-
/**
|
|
63
|
-
* Optional model configuration.
|
|
64
|
-
*/
|
|
65
|
-
model?: LDModelConfig;
|
|
66
|
-
/**
|
|
67
|
-
* Optional configuration for the provider.
|
|
68
|
-
*/
|
|
69
|
-
provider?: LDProviderConfig;
|
|
70
|
-
/**
|
|
71
|
-
* Whether the configuration is enabled. Defaults to false when not provided.
|
|
72
|
-
*/
|
|
73
|
-
enabled?: boolean;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Base AI Config interface without mode-specific fields.
|
|
77
|
-
*/
|
|
78
|
-
export interface LDAIConfig extends Omit<LDAIConfigDefault, 'enabled'> {
|
|
79
|
-
/**
|
|
80
|
-
* The key of the AI Config.
|
|
81
|
-
*/
|
|
82
|
-
key: string;
|
|
83
|
-
/**
|
|
84
|
-
* Whether the configuration is enabled.
|
|
85
|
-
*/
|
|
86
|
-
enabled: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* A tracker which can be used to generate analytics.
|
|
89
|
-
* Undefined for disabled configs.
|
|
90
|
-
*/
|
|
91
|
-
tracker?: LDAIConfigTracker;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Default Agent-specific AI Config with instructions.
|
|
95
|
-
*/
|
|
96
|
-
export interface LDAIAgentConfigDefault extends LDAIConfigDefault {
|
|
97
|
-
/**
|
|
98
|
-
* Instructions for the agent.
|
|
99
|
-
*/
|
|
100
|
-
instructions?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Judge configuration for AI Configs being evaluated.
|
|
103
|
-
* References judge AI Configs that should evaluate this AI Config.
|
|
104
|
-
*/
|
|
105
|
-
judgeConfiguration?: LDJudgeConfiguration;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Default Completion AI Config (default mode).
|
|
109
|
-
*/
|
|
110
|
-
export interface LDAICompletionConfigDefault extends LDAIConfigDefault {
|
|
111
|
-
/**
|
|
112
|
-
* Optional prompt data for completion configurations.
|
|
113
|
-
*/
|
|
114
|
-
messages?: LDMessage[];
|
|
115
|
-
/**
|
|
116
|
-
* Judge configuration for AI Configs being evaluated.
|
|
117
|
-
* References judge AI Configs that should evaluate this AI Config.
|
|
118
|
-
*/
|
|
119
|
-
judgeConfiguration?: LDJudgeConfiguration;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Default Judge-specific AI Config with required evaluation metric key.
|
|
123
|
-
*/
|
|
124
|
-
export interface LDAIJudgeConfigDefault extends LDAIConfigDefault {
|
|
125
|
-
/**
|
|
126
|
-
* Optional prompt data for judge configurations.
|
|
127
|
-
*/
|
|
128
|
-
messages?: LDMessage[];
|
|
129
|
-
/**
|
|
130
|
-
* Evaluation metric keys for judge configurations.
|
|
131
|
-
* The keys of the metrics that this judge can evaluate.
|
|
132
|
-
*/
|
|
133
|
-
evaluationMetricKeys?: string[];
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Union type for all default AI Config variants.
|
|
137
|
-
*/
|
|
138
|
-
export type LDAIConfigDefaultKind = LDAIAgentConfigDefault | LDAICompletionConfigDefault | LDAIJudgeConfigDefault;
|
|
139
|
-
/**
|
|
140
|
-
* Agent-specific AI Config with instructions.
|
|
141
|
-
*/
|
|
142
|
-
export interface LDAIAgentConfig extends LDAIConfig {
|
|
143
|
-
/**
|
|
144
|
-
* Instructions for the agent.
|
|
145
|
-
*/
|
|
146
|
-
instructions?: string;
|
|
147
|
-
/**
|
|
148
|
-
* Judge configuration for AI Configs being evaluated.
|
|
149
|
-
* References judge AI Configs that should evaluate this AI Config.
|
|
150
|
-
*/
|
|
151
|
-
judgeConfiguration?: LDJudgeConfiguration;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Completion AI Config (default mode).
|
|
155
|
-
*/
|
|
156
|
-
export interface LDAICompletionConfig extends LDAIConfig {
|
|
157
|
-
/**
|
|
158
|
-
* Optional prompt data for completion configurations.
|
|
159
|
-
*/
|
|
160
|
-
messages?: LDMessage[];
|
|
161
|
-
/**
|
|
162
|
-
* Judge configuration for AI Configs being evaluated.
|
|
163
|
-
* References judge AI Configs that should evaluate this AI Config.
|
|
164
|
-
*/
|
|
165
|
-
judgeConfiguration?: LDJudgeConfiguration;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Judge-specific AI Config with required evaluation metric key.
|
|
169
|
-
*/
|
|
170
|
-
export interface LDAIJudgeConfig extends LDAIConfig {
|
|
171
|
-
/**
|
|
172
|
-
* Optional prompt data for judge configurations.
|
|
173
|
-
*/
|
|
174
|
-
messages?: LDMessage[];
|
|
175
|
-
/**
|
|
176
|
-
* Evaluation metric keys for judge configurations.
|
|
177
|
-
* The keys of the metrics that this judge can evaluate.
|
|
178
|
-
*/
|
|
179
|
-
evaluationMetricKeys: string[];
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Union type for all AI Config variants.
|
|
183
|
-
*/
|
|
184
|
-
export type LDAIConfigKind = LDAIAgentConfig | LDAICompletionConfig | LDAIJudgeConfig;
|
|
185
|
-
/**
|
|
186
|
-
* Configuration for a single agent request.
|
|
187
|
-
*/
|
|
188
|
-
export interface LDAIAgentRequestConfig {
|
|
189
|
-
/**
|
|
190
|
-
* The agent key to retrieve.
|
|
191
|
-
*/
|
|
192
|
-
key: string;
|
|
193
|
-
/**
|
|
194
|
-
* Default configuration for the agent.
|
|
195
|
-
*/
|
|
196
|
-
defaultValue: LDAIAgentConfigDefault;
|
|
197
|
-
/**
|
|
198
|
-
* Variables for instructions interpolation.
|
|
199
|
-
*/
|
|
200
|
-
variables?: Record<string, unknown>;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Mode type for AI configurations.
|
|
204
|
-
*/
|
|
205
|
-
export type LDAIConfigMode = 'completion' | 'agent' | 'judge';
|
|
206
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":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,sBAAsB;IACrC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,YAAY,EAAE,sBAAsB,CAAC;IAErC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAMD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/config/types.ts"],"names":[],"mappings":""}
|
package/dist/src/api/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/src/api/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./config"), exports);
|
|
18
|
-
__exportStar(require("./chat"), exports);
|
|
19
|
-
__exportStar(require("./judge"), exports);
|
|
20
|
-
__exportStar(require("./metrics"), exports);
|
|
21
|
-
__exportStar(require("./LDAIClient"), exports);
|
|
22
|
-
__exportStar(require("./providers"), exports);
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,yCAAuB;AACvB,0CAAwB;AACxB,4CAA0B;AAC1B,+CAA6B;AAC7B,8CAA4B"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal class for building dynamic evaluation response schemas.
|
|
3
|
-
* Not exported - only used internally by TrackedJudge.
|
|
4
|
-
*/
|
|
5
|
-
declare class EvaluationSchemaBuilder {
|
|
6
|
-
static build(evaluationMetricKeys: string[]): Record<string, unknown>;
|
|
7
|
-
private static _buildKeyProperties;
|
|
8
|
-
private static _buildKeySchema;
|
|
9
|
-
}
|
|
10
|
-
export { EvaluationSchemaBuilder };
|
|
11
|
-
//# sourceMappingURL=EvaluationSchemaBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EvaluationSchemaBuilder.d.ts","sourceRoot":"","sources":["../../../../src/api/judge/EvaluationSchemaBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAM,uBAAuB;IAC3B,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAiBrE,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAUlC,OAAO,CAAC,MAAM,CAAC,eAAe;CAmB/B;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EvaluationSchemaBuilder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Internal class for building dynamic evaluation response schemas.
|
|
6
|
-
* Not exported - only used internally by TrackedJudge.
|
|
7
|
-
*/
|
|
8
|
-
class EvaluationSchemaBuilder {
|
|
9
|
-
static build(evaluationMetricKeys) {
|
|
10
|
-
return {
|
|
11
|
-
type: 'object',
|
|
12
|
-
properties: {
|
|
13
|
-
evaluations: {
|
|
14
|
-
type: 'object',
|
|
15
|
-
description: `Object containing evaluation results for ${evaluationMetricKeys.join(', ')} metrics`,
|
|
16
|
-
properties: this._buildKeyProperties(evaluationMetricKeys),
|
|
17
|
-
required: evaluationMetricKeys,
|
|
18
|
-
additionalProperties: false,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
required: ['evaluations'],
|
|
22
|
-
additionalProperties: false,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
static _buildKeyProperties(evaluationMetricKeys) {
|
|
26
|
-
return evaluationMetricKeys.reduce((acc, key) => {
|
|
27
|
-
acc[key] = this._buildKeySchema(key);
|
|
28
|
-
return acc;
|
|
29
|
-
}, {});
|
|
30
|
-
}
|
|
31
|
-
static _buildKeySchema(key) {
|
|
32
|
-
return {
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
score: {
|
|
36
|
-
type: 'number',
|
|
37
|
-
minimum: 0,
|
|
38
|
-
maximum: 1,
|
|
39
|
-
description: `Score between 0.0 and 1.0 for ${key}`,
|
|
40
|
-
},
|
|
41
|
-
reasoning: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
description: `Reasoning behind the score for ${key}`,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
required: ['score', 'reasoning'],
|
|
47
|
-
additionalProperties: false,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.EvaluationSchemaBuilder = EvaluationSchemaBuilder;
|
|
52
|
-
//# sourceMappingURL=EvaluationSchemaBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EvaluationSchemaBuilder.js","sourceRoot":"","sources":["../../../../src/api/judge/EvaluationSchemaBuilder.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAM,uBAAuB;IAC3B,MAAM,CAAC,KAAK,CAAC,oBAA8B;QACzC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU;oBAClG,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC;oBAC1D,QAAQ,EAAE,oBAAoB;oBAC9B,oBAAoB,EAAE,KAAK;iBAC5B;aACF;YACD,QAAQ,EAAE,CAAC,aAAa,CAAC;YACzB,oBAAoB,EAAE,KAAK;SACnB,CAAC;IACb,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAAC,oBAA8B;QAC/D,OAAO,oBAAoB,CAAC,MAAM,CAChC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACX,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YACrC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA6B,CAC9B,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,GAAW;QACxC,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,CAAC;oBACV,WAAW,EAAE,iCAAiC,GAAG,EAAE;iBACpD;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kCAAkC,GAAG,EAAE;iBACrD;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;YAChC,oBAAoB,EAAE,KAAK;SAC5B,CAAC;IACJ,CAAC;CACF;AAEQ,0DAAuB"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { LDLogger } from '@launchdarkly/js-server-sdk-common';
|
|
2
|
-
import { ChatResponse } from '../chat/types';
|
|
3
|
-
import { LDAIConfigTracker } from '../config/LDAIConfigTracker';
|
|
4
|
-
import { LDAIJudgeConfig, LDMessage } from '../config/types';
|
|
5
|
-
import { AIProvider } from '../providers/AIProvider';
|
|
6
|
-
import { JudgeResponse } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* Judge implementation that handles evaluation functionality and conversation management.
|
|
9
|
-
*
|
|
10
|
-
* According to the AIEval spec, judges are AI Configs with mode: "judge" that evaluate
|
|
11
|
-
* other AI Configs using structured output.
|
|
12
|
-
*/
|
|
13
|
-
export declare class Judge {
|
|
14
|
-
private readonly _aiConfig;
|
|
15
|
-
private readonly _aiConfigTracker;
|
|
16
|
-
private readonly _aiProvider;
|
|
17
|
-
private readonly _logger?;
|
|
18
|
-
private readonly _evaluationResponseStructure;
|
|
19
|
-
constructor(_aiConfig: LDAIJudgeConfig, _aiConfigTracker: LDAIConfigTracker, _aiProvider: AIProvider, logger?: LDLogger);
|
|
20
|
-
/**
|
|
21
|
-
* Evaluates an AI response using the judge's configuration.
|
|
22
|
-
*
|
|
23
|
-
* @param input The input prompt or question that was provided to the AI
|
|
24
|
-
* @param output The AI-generated response to be evaluated
|
|
25
|
-
* @param samplingRate Sampling rate (0-1) to determine if evaluation should be processed (defaults to 1)
|
|
26
|
-
* @returns Promise that resolves to evaluation results or undefined if not sampled
|
|
27
|
-
*/
|
|
28
|
-
evaluate(input: string, output: string, samplingRate?: number): Promise<JudgeResponse | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* Evaluates an AI response from chat messages and response.
|
|
31
|
-
*
|
|
32
|
-
* @param messages Array of messages representing the conversation history
|
|
33
|
-
* @param response The AI response to be evaluated
|
|
34
|
-
* @param samplingRatio Sampling ratio (0-1) to determine if evaluation should be processed (defaults to 1)
|
|
35
|
-
* @returns Promise that resolves to evaluation results or undefined if not sampled
|
|
36
|
-
*/
|
|
37
|
-
evaluateMessages(messages: LDMessage[], response: ChatResponse, samplingRatio?: number): Promise<JudgeResponse | undefined>;
|
|
38
|
-
/**
|
|
39
|
-
* Returns the AI Config used by this judge.
|
|
40
|
-
*/
|
|
41
|
-
getAIConfig(): LDAIJudgeConfig;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the tracker associated with this judge.
|
|
44
|
-
*/
|
|
45
|
-
getTracker(): LDAIConfigTracker;
|
|
46
|
-
/**
|
|
47
|
-
* Returns the AI provider used by this judge.
|
|
48
|
-
*/
|
|
49
|
-
getProvider(): AIProvider;
|
|
50
|
-
/**
|
|
51
|
-
* Constructs evaluation messages by combining judge's config messages with input/output.
|
|
52
|
-
*/
|
|
53
|
-
private _constructEvaluationMessages;
|
|
54
|
-
/**
|
|
55
|
-
* Interpolates message content with variables using Mustache templating.
|
|
56
|
-
*/
|
|
57
|
-
private _interpolateMessage;
|
|
58
|
-
/**
|
|
59
|
-
* Parses the structured evaluation response from the AI provider.
|
|
60
|
-
*/
|
|
61
|
-
private _parseEvaluationResponse;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=Judge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Judge.d.ts","sourceRoot":"","sources":["../../../../src/api/judge/Judge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAa,aAAa,EAAsB,MAAM,SAAS,CAAC;AAEvE;;;;;GAKG;AACH,qBAAa,KAAK;IAKd,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAN9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAA0B;gBAGpD,SAAS,EAAE,eAAe,EAC1B,gBAAgB,EAAE,iBAAiB,EACnC,WAAW,EAAE,UAAU,EACxC,MAAM,CAAC,EAAE,QAAQ;IAQnB;;;;;;;OAOG;IACG,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,YAAY,GAAE,MAAU,GACvB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IA6DrC;;;;;;;OAOG;IACG,gBAAgB,CACpB,QAAQ,EAAE,SAAS,EAAE,EACrB,QAAQ,EAAE,YAAY,EACtB,aAAa,GAAE,MAAU,GACxB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAOrC;;OAEG;IACH,WAAW,IAAI,eAAe;IAI9B;;OAEG;IACH,UAAU,IAAI,iBAAiB;IAI/B;;OAEG;IACH,WAAW,IAAI,UAAU;IAIzB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAYpC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,wBAAwB;CA8CjC"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Judge = void 0;
|
|
4
|
-
const Mustache = require("mustache");
|
|
5
|
-
const EvaluationSchemaBuilder_1 = require("./EvaluationSchemaBuilder");
|
|
6
|
-
/**
|
|
7
|
-
* Judge implementation that handles evaluation functionality and conversation management.
|
|
8
|
-
*
|
|
9
|
-
* According to the AIEval spec, judges are AI Configs with mode: "judge" that evaluate
|
|
10
|
-
* other AI Configs using structured output.
|
|
11
|
-
*/
|
|
12
|
-
class Judge {
|
|
13
|
-
constructor(_aiConfig, _aiConfigTracker, _aiProvider, logger) {
|
|
14
|
-
this._aiConfig = _aiConfig;
|
|
15
|
-
this._aiConfigTracker = _aiConfigTracker;
|
|
16
|
-
this._aiProvider = _aiProvider;
|
|
17
|
-
this._logger = logger;
|
|
18
|
-
this._evaluationResponseStructure = EvaluationSchemaBuilder_1.EvaluationSchemaBuilder.build(this._aiConfig.evaluationMetricKeys);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Evaluates an AI response using the judge's configuration.
|
|
22
|
-
*
|
|
23
|
-
* @param input The input prompt or question that was provided to the AI
|
|
24
|
-
* @param output The AI-generated response to be evaluated
|
|
25
|
-
* @param samplingRate Sampling rate (0-1) to determine if evaluation should be processed (defaults to 1)
|
|
26
|
-
* @returns Promise that resolves to evaluation results or undefined if not sampled
|
|
27
|
-
*/
|
|
28
|
-
async evaluate(input, output, samplingRate = 1) {
|
|
29
|
-
var _a, _b, _c, _d, _e;
|
|
30
|
-
try {
|
|
31
|
-
if (!this._aiConfig.evaluationMetricKeys ||
|
|
32
|
-
this._aiConfig.evaluationMetricKeys.length === 0) {
|
|
33
|
-
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.warn('Judge configuration is missing required evaluationMetricKeys', this._aiConfigTracker.getTrackData());
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
if (!this._aiConfig.messages) {
|
|
37
|
-
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.warn('Judge configuration must include messages', this._aiConfigTracker.getTrackData());
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
if (Math.random() > samplingRate) {
|
|
41
|
-
(_c = this._logger) === null || _c === void 0 ? void 0 : _c.debug(`Judge evaluation skipped due to sampling rate: ${samplingRate}`);
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const messages = this._constructEvaluationMessages(input, output);
|
|
45
|
-
const response = await this._aiConfigTracker.trackMetricsOf((result) => result.metrics, () => this._aiProvider.invokeStructuredModel(messages, this._evaluationResponseStructure));
|
|
46
|
-
let { success } = response.metrics;
|
|
47
|
-
const evals = this._parseEvaluationResponse(response.data);
|
|
48
|
-
if (Object.keys(evals).length !== this._aiConfig.evaluationMetricKeys.length) {
|
|
49
|
-
(_d = this._logger) === null || _d === void 0 ? void 0 : _d.warn('Judge evaluation did not return all evaluations', this._aiConfigTracker.getTrackData());
|
|
50
|
-
success = false;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
evals,
|
|
54
|
-
success,
|
|
55
|
-
judgeConfigKey: this._aiConfig.key,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
(_e = this._logger) === null || _e === void 0 ? void 0 : _e.error('Judge evaluation failed:', error);
|
|
60
|
-
return {
|
|
61
|
-
evals: {},
|
|
62
|
-
success: false,
|
|
63
|
-
error: error instanceof Error ? error.message : 'Unknown error',
|
|
64
|
-
judgeConfigKey: this._aiConfig.key,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Evaluates an AI response from chat messages and response.
|
|
70
|
-
*
|
|
71
|
-
* @param messages Array of messages representing the conversation history
|
|
72
|
-
* @param response The AI response to be evaluated
|
|
73
|
-
* @param samplingRatio Sampling ratio (0-1) to determine if evaluation should be processed (defaults to 1)
|
|
74
|
-
* @returns Promise that resolves to evaluation results or undefined if not sampled
|
|
75
|
-
*/
|
|
76
|
-
async evaluateMessages(messages, response, samplingRatio = 1) {
|
|
77
|
-
const input = messages.length === 0 ? '' : messages.map((msg) => msg.content).join('\r\n');
|
|
78
|
-
const output = response.message.content;
|
|
79
|
-
return this.evaluate(input, output, samplingRatio);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns the AI Config used by this judge.
|
|
83
|
-
*/
|
|
84
|
-
getAIConfig() {
|
|
85
|
-
return this._aiConfig;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Returns the tracker associated with this judge.
|
|
89
|
-
*/
|
|
90
|
-
getTracker() {
|
|
91
|
-
return this._aiConfigTracker;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns the AI provider used by this judge.
|
|
95
|
-
*/
|
|
96
|
-
getProvider() {
|
|
97
|
-
return this._aiProvider;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Constructs evaluation messages by combining judge's config messages with input/output.
|
|
101
|
-
*/
|
|
102
|
-
_constructEvaluationMessages(input, output) {
|
|
103
|
-
const messages = this._aiConfig.messages.map((msg) => (Object.assign(Object.assign({}, msg), { content: this._interpolateMessage(msg.content, {
|
|
104
|
-
message_history: input,
|
|
105
|
-
response_to_evaluate: output,
|
|
106
|
-
}) })));
|
|
107
|
-
return messages;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Interpolates message content with variables using Mustache templating.
|
|
111
|
-
*/
|
|
112
|
-
_interpolateMessage(content, variables) {
|
|
113
|
-
return Mustache.render(content, variables, undefined, { escape: (item) => item });
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Parses the structured evaluation response from the AI provider.
|
|
117
|
-
*/
|
|
118
|
-
_parseEvaluationResponse(data) {
|
|
119
|
-
var _a;
|
|
120
|
-
const evaluations = data.evaluations;
|
|
121
|
-
const results = {};
|
|
122
|
-
if (!data.evaluations || typeof data.evaluations !== 'object') {
|
|
123
|
-
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.warn('Invalid response: missing or invalid evaluations object');
|
|
124
|
-
return results;
|
|
125
|
-
}
|
|
126
|
-
this._aiConfig.evaluationMetricKeys.forEach((metricKey) => {
|
|
127
|
-
var _a, _b, _c;
|
|
128
|
-
const evaluation = evaluations[metricKey];
|
|
129
|
-
if (!evaluation || typeof evaluation !== 'object') {
|
|
130
|
-
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.warn(`Missing evaluation for metric key: ${metricKey}`, this._aiConfigTracker.getTrackData());
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const evalData = evaluation;
|
|
134
|
-
if (typeof evalData.score !== 'number' || evalData.score < 0 || evalData.score > 1) {
|
|
135
|
-
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.warn(`Invalid score evaluated for ${metricKey}: ${evalData.score}. Score must be a number between 0 and 1 inclusive`, this._aiConfigTracker.getTrackData());
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (typeof evalData.reasoning !== 'string') {
|
|
139
|
-
(_c = this._logger) === null || _c === void 0 ? void 0 : _c.warn(`Invalid reasoning evaluated for ${metricKey}: ${evalData.reasoning}. Reasoning must be a string`, this._aiConfigTracker.getTrackData());
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
results[metricKey] = {
|
|
143
|
-
score: evalData.score,
|
|
144
|
-
reasoning: evalData.reasoning,
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
return results;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.Judge = Judge;
|
|
151
|
-
//# sourceMappingURL=Judge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Judge.js","sourceRoot":"","sources":["../../../../src/api/judge/Judge.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAQrC,uEAAoE;AAGpE;;;;;GAKG;AACH,MAAa,KAAK;IAIhB,YACmB,SAA0B,EAC1B,gBAAmC,EACnC,WAAuB,EACxC,MAAiB;QAHA,cAAS,GAAT,SAAS,CAAiB;QAC1B,qBAAgB,GAAhB,gBAAgB,CAAmB;QACnC,gBAAW,GAAX,WAAW,CAAY;QAGxC,IAAI,CAAC,OAAO,GAAG,MAAM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C"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Judge = void 0;
|
|
4
|
-
var Judge_1 = require("./Judge");
|
|
5
|
-
Object.defineProperty(exports, "Judge", { enumerable: true, get: function () { return Judge_1.Judge; } });
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/api/judge/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { LDAIMetrics } from '../metrics/LDAIMetrics';
|
|
2
|
-
/**
|
|
3
|
-
* Structured response from AI models.
|
|
4
|
-
*/
|
|
5
|
-
export interface StructuredResponse {
|
|
6
|
-
/** The structured data returned by the model */
|
|
7
|
-
data: Record<string, unknown>;
|
|
8
|
-
/** The raw response from the model */
|
|
9
|
-
rawResponse: string;
|
|
10
|
-
/**
|
|
11
|
-
* Metrics information including success status and token usage.
|
|
12
|
-
*/
|
|
13
|
-
metrics: LDAIMetrics;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Score and reasoning for a single evaluation metric.
|
|
17
|
-
*/
|
|
18
|
-
export interface EvalScore {
|
|
19
|
-
/** Score between 0.0 and 1.0 indicating the evaluation result for this metric */
|
|
20
|
-
score: number;
|
|
21
|
-
/** Reasoning behind the provided score for this metric */
|
|
22
|
-
reasoning: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Response from a judge evaluation containing scores and reasoning for multiple metrics.
|
|
26
|
-
*/
|
|
27
|
-
export interface JudgeResponse {
|
|
28
|
-
/** The key of the judge configuration that was used to generate this response */
|
|
29
|
-
judgeConfigKey?: string;
|
|
30
|
-
/** Dictionary where keys are metric names and values contain score and reasoning */
|
|
31
|
-
evals: Record<string, EvalScore>;
|
|
32
|
-
/** Whether the evaluation completed successfully */
|
|
33
|
-
success: boolean;
|
|
34
|
-
/** Error message if evaluation failed */
|
|
35
|
-
error?: string;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/api/judge/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9B,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACjC,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|