@arizeai/phoenix-client 1.1.0 → 1.2.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/dist/esm/__generated__/api/v1.d.ts +375 -0
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.d.ts +48 -13
- package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.js +139 -36
- package/dist/esm/experiments/runExperiment.js.map +1 -1
- package/dist/esm/spans/addSpanAnnotation.d.ts +39 -0
- package/dist/esm/spans/addSpanAnnotation.d.ts.map +1 -0
- package/dist/esm/spans/addSpanAnnotation.js +44 -0
- package/dist/esm/spans/addSpanAnnotation.js.map +1 -0
- package/dist/esm/spans/index.d.ts +3 -0
- package/dist/esm/spans/index.d.ts.map +1 -0
- package/dist/esm/spans/index.js +3 -0
- package/dist/esm/spans/index.js.map +1 -0
- package/dist/esm/spans/logSpanAnnotations.d.ts +51 -0
- package/dist/esm/spans/logSpanAnnotations.d.ts.map +1 -0
- package/dist/esm/spans/logSpanAnnotations.js +53 -0
- package/dist/esm/spans/logSpanAnnotations.js.map +1 -0
- package/dist/esm/spans/types.d.ts +43 -0
- package/dist/esm/spans/types.d.ts.map +1 -0
- package/dist/esm/spans/types.js +18 -0
- package/dist/esm/spans/types.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types/annotations.d.ts +2 -1
- package/dist/esm/types/annotations.d.ts.map +1 -1
- package/dist/esm/types/experiments.d.ts +1 -7
- package/dist/esm/types/experiments.d.ts.map +1 -1
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/src/__generated__/api/v1.d.ts +375 -0
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.d.ts +48 -13
- package/dist/src/experiments/runExperiment.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.js +138 -36
- package/dist/src/experiments/runExperiment.js.map +1 -1
- package/dist/src/spans/addSpanAnnotation.d.ts +39 -0
- package/dist/src/spans/addSpanAnnotation.d.ts.map +1 -0
- package/dist/src/spans/addSpanAnnotation.js +59 -0
- package/dist/src/spans/addSpanAnnotation.js.map +1 -0
- package/dist/src/spans/index.d.ts +3 -0
- package/dist/src/spans/index.d.ts.map +1 -0
- package/dist/src/spans/index.js +19 -0
- package/dist/src/spans/index.js.map +1 -0
- package/dist/src/spans/logSpanAnnotations.d.ts +51 -0
- package/dist/src/spans/logSpanAnnotations.d.ts.map +1 -0
- package/dist/src/spans/logSpanAnnotations.js +68 -0
- package/dist/src/spans/logSpanAnnotations.js.map +1 -0
- package/dist/src/spans/types.d.ts +43 -0
- package/dist/src/spans/types.d.ts.map +1 -0
- package/dist/src/spans/types.js +22 -0
- package/dist/src/spans/types.js.map +1 -0
- package/dist/src/types/annotations.d.ts +2 -1
- package/dist/src/types/annotations.d.ts.map +1 -1
- package/dist/src/types/experiments.d.ts +1 -7
- package/dist/src/types/experiments.d.ts.map +1 -1
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -1
- package/src/__generated__/api/v1.ts +375 -0
- package/src/experiments/runExperiment.ts +211 -74
- package/src/spans/addSpanAnnotation.ts +59 -0
- package/src/spans/index.ts +2 -0
- package/src/spans/logSpanAnnotations.ts +71 -0
- package/src/spans/types.ts +60 -0
- package/src/types/annotations.ts +4 -1
- package/src/types/experiments.ts +1 -7
|
@@ -16,45 +16,85 @@ exports.runExperiment = runExperiment;
|
|
|
16
16
|
exports.evaluateExperiment = evaluateExperiment;
|
|
17
17
|
exports.asEvaluator = asEvaluator;
|
|
18
18
|
exports.id = id;
|
|
19
|
-
const
|
|
20
|
-
const promisifyResult_1 = require("../utils/promisifyResult");
|
|
19
|
+
const async_1 = require("async");
|
|
21
20
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
22
|
-
const
|
|
21
|
+
const client_1 = require("../client");
|
|
23
22
|
const getDatasetBySelector_1 = require("../utils/getDatasetBySelector");
|
|
23
|
+
const pluralize_1 = require("../utils/pluralize");
|
|
24
|
+
const promisifyResult_1 = require("../utils/promisifyResult");
|
|
24
25
|
/**
|
|
25
26
|
* Run an experiment.
|
|
26
27
|
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { asEvaluator, runExperiment } from "@phoenix/client/experiments";
|
|
31
|
+
*
|
|
32
|
+
* const experiment = await runExperiment({
|
|
33
|
+
* dataset: "my-dataset",
|
|
34
|
+
* task: async (example) => example.input,
|
|
35
|
+
* evaluators: [
|
|
36
|
+
* asEvaluator("my-evaluator", "CODE", async (params) => params.output),
|
|
37
|
+
* ],
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
27
41
|
* @experimental This feature is not complete, and will change in the future.
|
|
28
|
-
* @deprecated This function will be un-marked as deprecated once the experimental feature flag is removed.
|
|
29
42
|
*/
|
|
30
43
|
function runExperiment(_a) {
|
|
31
|
-
return __awaiter(this, arguments, void 0, function* ({ experimentName: _experimentName, client: _client, dataset: _dataset, task, evaluators,
|
|
44
|
+
return __awaiter(this, arguments, void 0, function* ({ experimentName: _experimentName, experimentDescription, experimentMetadata, client: _client, dataset: _dataset, task, evaluators, projectName = "default", logger = console, record = true, concurrency = 5, dryRun = false, }) {
|
|
32
45
|
var _b, _c;
|
|
46
|
+
const isDryRun = typeof dryRun === "number" || dryRun === true;
|
|
33
47
|
const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)();
|
|
34
48
|
const dataset = yield (0, getDatasetBySelector_1.getDatasetBySelector)({ dataset: _dataset, client });
|
|
35
49
|
(0, tiny_invariant_1.default)(dataset, `Dataset not found`);
|
|
36
50
|
(0, tiny_invariant_1.default)(dataset.examples.length > 0, `Dataset has no examples`);
|
|
51
|
+
const nExamples = typeof dryRun === "number"
|
|
52
|
+
? Math.max(dryRun, dataset.examples.length)
|
|
53
|
+
: dataset.examples.length;
|
|
37
54
|
const experimentName = _experimentName !== null && _experimentName !== void 0 ? _experimentName : `${dataset.name}-${new Date().toISOString()}`;
|
|
38
55
|
const experimentParams = {
|
|
39
|
-
|
|
40
|
-
// TODO: Make configurable?
|
|
41
|
-
nExamples: dataset.examples.length,
|
|
42
|
-
};
|
|
43
|
-
const experiment = {
|
|
44
|
-
id: id(),
|
|
45
|
-
datasetId: dataset.id,
|
|
46
|
-
datasetVersionId: dataset.versionId,
|
|
47
|
-
repetitions,
|
|
48
|
-
projectName,
|
|
56
|
+
nExamples,
|
|
49
57
|
};
|
|
58
|
+
let experiment;
|
|
59
|
+
if (isDryRun) {
|
|
60
|
+
experiment = {
|
|
61
|
+
id: id(),
|
|
62
|
+
datasetId: dataset.id,
|
|
63
|
+
datasetVersionId: dataset.versionId,
|
|
64
|
+
projectName,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const experimentResponse = yield client
|
|
69
|
+
.POST("/v1/datasets/{dataset_id}/experiments", {
|
|
70
|
+
params: {
|
|
71
|
+
path: {
|
|
72
|
+
dataset_id: dataset.id,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
body: {
|
|
76
|
+
name: experimentName,
|
|
77
|
+
description: experimentDescription,
|
|
78
|
+
metadata: experimentMetadata,
|
|
79
|
+
project_name: projectName,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
.then((res) => { var _a; return (_a = res.data) === null || _a === void 0 ? void 0 : _a.data; });
|
|
83
|
+
(0, tiny_invariant_1.default)(experimentResponse, `Failed to create experiment`);
|
|
84
|
+
experiment = {
|
|
85
|
+
id: experimentResponse.id,
|
|
86
|
+
datasetId: dataset.id,
|
|
87
|
+
datasetVersionId: dataset.versionId,
|
|
88
|
+
projectName,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
50
91
|
if (!record) {
|
|
51
92
|
logger.info(`🔧 Running experiment in readonly mode. Results will not be recorded.`);
|
|
52
93
|
}
|
|
53
|
-
logger.info(`🧪 Starting experiment "${experimentName}" on dataset "${dataset.id}" with task "${task.name}" and ${(_b = evaluators === null || evaluators === void 0 ? void 0 : evaluators.length) !== null && _b !== void 0 ? _b : 0} ${(0, pluralize_1.pluralize)("evaluator", (_c = evaluators === null || evaluators === void 0 ? void 0 : evaluators.length) !== null && _c !== void 0 ? _c : 0)}`);
|
|
54
|
-
logger.info(`🔁 Running ${repetitions} ${(0, pluralize_1.pluralize)("repetition", repetitions)} of task "${task.name}"`);
|
|
94
|
+
logger.info(`🧪 Starting experiment "${experimentName}" on dataset "${dataset.id}" with task "${task.name}" and ${(_b = evaluators === null || evaluators === void 0 ? void 0 : evaluators.length) !== null && _b !== void 0 ? _b : 0} ${(0, pluralize_1.pluralize)("evaluator", (_c = evaluators === null || evaluators === void 0 ? void 0 : evaluators.length) !== null && _c !== void 0 ? _c : 0)} and ${concurrency} concurrent runs`);
|
|
55
95
|
const runs = {};
|
|
56
|
-
yield
|
|
57
|
-
|
|
96
|
+
yield runTask({
|
|
97
|
+
client,
|
|
58
98
|
experimentId: experiment.id,
|
|
59
99
|
task,
|
|
60
100
|
dataset,
|
|
@@ -62,7 +102,10 @@ function runExperiment(_a) {
|
|
|
62
102
|
onComplete: (run) => {
|
|
63
103
|
runs[run.id] = run;
|
|
64
104
|
},
|
|
65
|
-
|
|
105
|
+
concurrency,
|
|
106
|
+
isDryRun,
|
|
107
|
+
nExamples,
|
|
108
|
+
});
|
|
66
109
|
logger.info(`✅ Task runs completed`);
|
|
67
110
|
const ranExperiment = Object.assign(Object.assign({}, experiment), { params: experimentParams, runs });
|
|
68
111
|
const { evaluationRuns } = yield evaluateExperiment({
|
|
@@ -70,6 +113,8 @@ function runExperiment(_a) {
|
|
|
70
113
|
evaluators: evaluators !== null && evaluators !== void 0 ? evaluators : [],
|
|
71
114
|
client,
|
|
72
115
|
logger,
|
|
116
|
+
concurrency,
|
|
117
|
+
dryRun,
|
|
73
118
|
});
|
|
74
119
|
ranExperiment.evaluationRuns = evaluationRuns;
|
|
75
120
|
logger.info(`✅ Experiment ${experiment.id} completed`);
|
|
@@ -77,18 +122,19 @@ function runExperiment(_a) {
|
|
|
77
122
|
});
|
|
78
123
|
}
|
|
79
124
|
/**
|
|
80
|
-
* Run a task against
|
|
125
|
+
* Run a task against n examples in a dataset.
|
|
81
126
|
*/
|
|
82
|
-
function runTask({ experimentId, task, dataset,
|
|
83
|
-
logger.info(`🔧
|
|
127
|
+
function runTask({ client, experimentId, task, dataset, onComplete, logger, concurrency = 5, isDryRun, nExamples, }) {
|
|
128
|
+
logger.info(`🔧 Running task "${task.name}" on dataset "${dataset.id}"`);
|
|
84
129
|
const run = (example) => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
logger.info(`🔧 Running task "${task.name}" on example "${example.id} of dataset "${dataset.id}"`);
|
|
85
132
|
const thisRun = {
|
|
86
133
|
id: id(),
|
|
87
|
-
traceId:
|
|
134
|
+
traceId: null, // TODO: fill this in once we trace experiments
|
|
88
135
|
experimentId,
|
|
89
136
|
datasetExampleId: example.id,
|
|
90
137
|
startTime: new Date(),
|
|
91
|
-
repetitionNumber: repetition,
|
|
92
138
|
endTime: new Date(), // will get replaced with actual end time
|
|
93
139
|
output: null,
|
|
94
140
|
error: null,
|
|
@@ -105,19 +151,48 @@ function runTask({ experimentId, task, dataset, repetition, onComplete, logger,
|
|
|
105
151
|
thisRun.error = error instanceof Error ? error.message : "Unknown error";
|
|
106
152
|
}
|
|
107
153
|
thisRun.endTime = new Date();
|
|
154
|
+
if (!isDryRun) {
|
|
155
|
+
// Log the run to the server
|
|
156
|
+
// We log this without awaiting (e.g. best effort)
|
|
157
|
+
const res = yield client.POST("/v1/experiments/{experiment_id}/runs", {
|
|
158
|
+
params: {
|
|
159
|
+
path: {
|
|
160
|
+
experiment_id: experimentId,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
body: {
|
|
164
|
+
dataset_example_id: example.id,
|
|
165
|
+
output: thisRun.output,
|
|
166
|
+
repetition_number: 0,
|
|
167
|
+
start_time: thisRun.startTime.toISOString(),
|
|
168
|
+
end_time: thisRun.endTime.toISOString(),
|
|
169
|
+
trace_id: thisRun.traceId,
|
|
170
|
+
error: thisRun.error,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
// replace the local run id with the server-assigned id
|
|
174
|
+
thisRun.id = (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.data.id) !== null && _b !== void 0 ? _b : thisRun.id;
|
|
175
|
+
}
|
|
108
176
|
onComplete(thisRun);
|
|
177
|
+
return thisRun;
|
|
109
178
|
});
|
|
110
|
-
|
|
179
|
+
const q = (0, async_1.queue)(run, concurrency);
|
|
180
|
+
const examplesToUse = dataset.examples.slice(0, nExamples);
|
|
181
|
+
examplesToUse.forEach((example) => q.push(example));
|
|
182
|
+
return q.drain();
|
|
111
183
|
}
|
|
112
184
|
/**
|
|
113
185
|
* Evaluate an experiment.
|
|
114
186
|
*
|
|
115
187
|
* @experimental This feature is not complete, and will change in the future.
|
|
116
|
-
* @deprecated This function will be un-marked as deprecated once the experimental feature flag is removed.
|
|
117
188
|
*/
|
|
118
189
|
function evaluateExperiment(_a) {
|
|
119
|
-
return __awaiter(this, arguments, void 0, function* ({ experiment, evaluators, client: _client, logger, }) {
|
|
190
|
+
return __awaiter(this, arguments, void 0, function* ({ experiment, evaluators, client: _client, logger, concurrency = 5, dryRun = false, }) {
|
|
120
191
|
var _b, _c;
|
|
192
|
+
const isDryRun = typeof dryRun === "number" || dryRun === true;
|
|
193
|
+
const nRuns = typeof dryRun === "number"
|
|
194
|
+
? Math.max(dryRun, Object.keys(experiment.runs).length)
|
|
195
|
+
: Object.keys(experiment.runs).length;
|
|
121
196
|
const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)();
|
|
122
197
|
const dataset = yield (0, getDatasetBySelector_1.getDatasetBySelector)({
|
|
123
198
|
dataset: experiment.datasetId,
|
|
@@ -126,6 +201,7 @@ function evaluateExperiment(_a) {
|
|
|
126
201
|
(0, tiny_invariant_1.default)(dataset, `Dataset "${experiment.datasetId}" not found`);
|
|
127
202
|
(0, tiny_invariant_1.default)(dataset.examples.length > 0, `Dataset "${experiment.datasetId}" has no examples`);
|
|
128
203
|
(0, tiny_invariant_1.default)(experiment.runs, `Experiment "${experiment.id}" has no runs`);
|
|
204
|
+
const runsToEvaluate = Object.values(experiment.runs).slice(0, nRuns);
|
|
129
205
|
if ((evaluators === null || evaluators === void 0 ? void 0 : evaluators.length) === 0) {
|
|
130
206
|
return Object.assign(Object.assign({}, experiment), { evaluationRuns: [] });
|
|
131
207
|
}
|
|
@@ -139,12 +215,38 @@ function evaluateExperiment(_a) {
|
|
|
139
215
|
evaluationRuns[run.id] = run;
|
|
140
216
|
};
|
|
141
217
|
// Run evaluators against all runs
|
|
142
|
-
|
|
218
|
+
// Flat list of evaluator + run tuples
|
|
219
|
+
const evaluatorsAndRuns = evaluators.flatMap((evaluator) => runsToEvaluate.map((run) => ({
|
|
143
220
|
evaluator,
|
|
144
221
|
run,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
222
|
+
})));
|
|
223
|
+
const evaluatorsQueue = (0, async_1.queue)((evaluatorAndRun) => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const evalResult = yield runEvaluator({
|
|
225
|
+
evaluator: evaluatorAndRun.evaluator,
|
|
226
|
+
run: evaluatorAndRun.run,
|
|
227
|
+
exampleCache: examplesById,
|
|
228
|
+
onComplete: onEvaluationComplete,
|
|
229
|
+
});
|
|
230
|
+
if (!isDryRun) {
|
|
231
|
+
logger.info(`📝 Logging evaluation ${evalResult.id}`);
|
|
232
|
+
// Log the evaluation to the server
|
|
233
|
+
// We log this without awaiting (e.g. best effort)
|
|
234
|
+
client.POST("/v1/experiment_evaluations", {
|
|
235
|
+
body: {
|
|
236
|
+
experiment_run_id: evaluatorAndRun.run.id,
|
|
237
|
+
name: evaluatorAndRun.evaluator.name,
|
|
238
|
+
annotator_kind: evaluatorAndRun.evaluator.kind,
|
|
239
|
+
start_time: evalResult.startTime.toISOString(),
|
|
240
|
+
end_time: evalResult.endTime.toISOString(),
|
|
241
|
+
result: Object.assign({}, evalResult.result),
|
|
242
|
+
error: evalResult.error,
|
|
243
|
+
trace_id: evalResult.traceId,
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}), concurrency);
|
|
248
|
+
evaluatorsAndRuns.forEach((evaluatorAndRun) => evaluatorsQueue.push(evaluatorAndRun));
|
|
249
|
+
yield evaluatorsQueue.drain();
|
|
148
250
|
logger.info(`✅ Evaluation runs completed`);
|
|
149
251
|
return Object.assign(Object.assign({}, experiment), { evaluationRuns: Object.values(evaluationRuns) });
|
|
150
252
|
});
|
|
@@ -153,7 +255,6 @@ function evaluateExperiment(_a) {
|
|
|
153
255
|
* Run an evaluator against a run.
|
|
154
256
|
*
|
|
155
257
|
* @experimental This feature is not complete, and will change in the future.
|
|
156
|
-
* @deprecated This function will be un-marked as deprecated once the experimental feature flag is removed.
|
|
157
258
|
*/
|
|
158
259
|
function runEvaluator(_a) {
|
|
159
260
|
return __awaiter(this, arguments, void 0, function* ({ evaluator, run, exampleCache, onComplete, }) {
|
|
@@ -163,7 +264,7 @@ function runEvaluator(_a) {
|
|
|
163
264
|
var _a;
|
|
164
265
|
const thisEval = {
|
|
165
266
|
id: id(),
|
|
166
|
-
traceId:
|
|
267
|
+
traceId: null, // TODO: fill this in once we trace experiments
|
|
167
268
|
experimentRunId: run.id,
|
|
168
269
|
startTime: new Date(),
|
|
169
270
|
endTime: new Date(), // will get replaced with actual end time
|
|
@@ -186,6 +287,7 @@ function runEvaluator(_a) {
|
|
|
186
287
|
}
|
|
187
288
|
thisEval.endTime = new Date();
|
|
188
289
|
onComplete(thisEval);
|
|
290
|
+
return thisEval;
|
|
189
291
|
});
|
|
190
292
|
return evaluate();
|
|
191
293
|
});
|
|
@@ -194,15 +296,15 @@ function runEvaluator(_a) {
|
|
|
194
296
|
* Wrap an evaluator function in an object with a name property.
|
|
195
297
|
*
|
|
196
298
|
* @experimental This feature is not complete, and will change in the future.
|
|
197
|
-
* @deprecated This function will be un-marked as deprecated once the experimental feature flag is removed.
|
|
198
299
|
*
|
|
199
300
|
* @param name - The name of the evaluator.
|
|
200
301
|
* @param evaluate - The evaluator function.
|
|
201
302
|
* @returns The evaluator object.
|
|
202
303
|
*/
|
|
203
|
-
function asEvaluator(name, evaluate) {
|
|
304
|
+
function asEvaluator({ name, kind, evaluate, }) {
|
|
204
305
|
return {
|
|
205
306
|
name,
|
|
307
|
+
kind,
|
|
206
308
|
evaluate,
|
|
207
309
|
};
|
|
208
310
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runExperiment.js","sourceRoot":"","sources":["../../../src/experiments/runExperiment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"runExperiment.js","sourceRoot":"","sources":["../../../src/experiments/runExperiment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AA4FA,sCAgHC;AAiGD,gDAwHC;AA4DD,kCAcC;AAUD,gBAKC;AA9fD,iCAA8B;AAC9B,oEAAuC;AACvC,sCAA6D;AAa7D,wEAAqE;AACrE,kDAA+C;AAC/C,8DAA2D;AAyD3D;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAsB,aAAa;yDAAC,EAClC,cAAc,EAAE,eAAe,EAC/B,qBAAqB,EACrB,kBAAkB,EAClB,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,QAAQ,EACjB,IAAI,EACJ,UAAU,EACV,WAAW,GAAG,SAAS,EACvB,MAAM,GAAG,OAAO,EAChB,MAAM,GAAG,IAAI,EACb,WAAW,GAAG,CAAC,EACf,MAAM,GAAG,KAAK,GACM;;QACpB,MAAM,QAAQ,GAAG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,GAKT;IACC,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,IAAI,GAAG,GAAG,IAAI,CAAC;AAEf;;;;;GAKG;AACH,SAAgB,EAAE;IAChB,OAAO,CAAC,GAAG,EAAE;QACX,GAAG,EAAE,CAAC;QACN,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC,CAAC,EAAE,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ClientFn } from "../types/core";
|
|
2
|
+
import { SpanAnnotation } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Parameters to add a span annotation
|
|
5
|
+
*/
|
|
6
|
+
interface AddSpanAnnotationParams extends ClientFn {
|
|
7
|
+
spanAnnotation: SpanAnnotation;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Add an annotation to a span.
|
|
11
|
+
*
|
|
12
|
+
* The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
|
|
13
|
+
* If an identifier is provided and an annotation with that identifier already exists, it will be updated.
|
|
14
|
+
*
|
|
15
|
+
* @param params - The parameters to add a span annotation
|
|
16
|
+
* @returns The ID of the created or updated annotation
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const result = await addSpanAnnotation({
|
|
21
|
+
* spanAnnotation: {
|
|
22
|
+
* spanId: "123abc",
|
|
23
|
+
* name: "quality_score",
|
|
24
|
+
* label: "good",
|
|
25
|
+
* score: 0.95,
|
|
26
|
+
* annotatorKind: "LLM",
|
|
27
|
+
* identifier: "custom_id_123",
|
|
28
|
+
* metadata: {
|
|
29
|
+
* model: "gpt-4"
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function addSpanAnnotation({ client: _client, spanAnnotation, }: AddSpanAnnotationParams): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
}>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=addSpanAnnotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addSpanAnnotation.d.ts","sourceRoot":"","sources":["../../../src/spans/addSpanAnnotation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,UAAU,uBAAwB,SAAQ,QAAQ;IAChD,cAAc,EAAE,cAAc,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,MAAM,EAAE,OAAO,EACf,cAAc,GACf,EAAE,uBAAuB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAkBnD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addSpanAnnotation = addSpanAnnotation;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
const types_1 = require("./types");
|
|
15
|
+
/**
|
|
16
|
+
* Add an annotation to a span.
|
|
17
|
+
*
|
|
18
|
+
* The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
|
|
19
|
+
* If an identifier is provided and an annotation with that identifier already exists, it will be updated.
|
|
20
|
+
*
|
|
21
|
+
* @param params - The parameters to add a span annotation
|
|
22
|
+
* @returns The ID of the created or updated annotation
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result = await addSpanAnnotation({
|
|
27
|
+
* spanAnnotation: {
|
|
28
|
+
* spanId: "123abc",
|
|
29
|
+
* name: "quality_score",
|
|
30
|
+
* label: "good",
|
|
31
|
+
* score: 0.95,
|
|
32
|
+
* annotatorKind: "LLM",
|
|
33
|
+
* identifier: "custom_id_123",
|
|
34
|
+
* metadata: {
|
|
35
|
+
* model: "gpt-4"
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function addSpanAnnotation(_a) {
|
|
42
|
+
return __awaiter(this, arguments, void 0, function* ({ client: _client, spanAnnotation, }) {
|
|
43
|
+
var _b, _c;
|
|
44
|
+
const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)();
|
|
45
|
+
const { data, error } = yield client.POST("/v1/span_annotations", {
|
|
46
|
+
body: {
|
|
47
|
+
data: [(0, types_1.toSpanAnnotationData)(spanAnnotation)],
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
if (error) {
|
|
51
|
+
throw new Error(`Failed to add span annotation: ${error}`);
|
|
52
|
+
}
|
|
53
|
+
if (!((_c = (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id)) {
|
|
54
|
+
throw new Error("No annotation ID returned from server");
|
|
55
|
+
}
|
|
56
|
+
return data.data[0];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=addSpanAnnotation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addSpanAnnotation.js","sourceRoot":"","sources":["../../../src/spans/addSpanAnnotation.ts"],"names":[],"mappings":";;;;;;;;;;;AAqCA,8CAqBC;AA1DD,sCAAyC;AAEzC,mCAA+D;AAS/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAsB,iBAAiB;yDAAC,EACtC,MAAM,EAAE,OAAO,EACf,cAAc,GACU;;QACxB,MAAM,MAAM,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAA,qBAAY,GAAE,CAAC;QAEzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;YAChE,IAAI,EAAE;gBACJ,IAAI,EAAE,CAAC,IAAA,4BAAoB,EAAC,cAAc,CAAC,CAAC;aAC7C;SACF,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,CAAA,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,0CAAG,CAAC,CAAC,0CAAE,EAAE,CAAA,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spans/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./addSpanAnnotation"), exports);
|
|
18
|
+
__exportStar(require("./logSpanAnnotations"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/spans/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,uDAAqC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ClientFn } from "../types/core";
|
|
2
|
+
import { SpanAnnotation } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Parameters to log multiple span annotations
|
|
5
|
+
*/
|
|
6
|
+
interface LogSpanAnnotationsParams extends ClientFn {
|
|
7
|
+
/**
|
|
8
|
+
* The span annotations to log
|
|
9
|
+
*/
|
|
10
|
+
spanAnnotations: SpanAnnotation[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Log multiple span annotations in a single request.
|
|
14
|
+
*
|
|
15
|
+
* Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
|
|
16
|
+
* If an identifier is provided and an annotation with that identifier already exists, it will be updated.
|
|
17
|
+
*
|
|
18
|
+
* @param params - The parameters to log span annotations
|
|
19
|
+
* @returns The IDs of the created or updated annotations
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const results = await logSpanAnnotations({
|
|
24
|
+
* spanAnnotations: [
|
|
25
|
+
* {
|
|
26
|
+
* spanId: "123abc",
|
|
27
|
+
* name: "quality_score",
|
|
28
|
+
* label: "good",
|
|
29
|
+
* score: 0.95,
|
|
30
|
+
* annotatorKind: "LLM",
|
|
31
|
+
* identifier: "custom_id_123",
|
|
32
|
+
* metadata: {
|
|
33
|
+
* model: "gpt-4"
|
|
34
|
+
* }
|
|
35
|
+
* },
|
|
36
|
+
* {
|
|
37
|
+
* spanId: "456def",
|
|
38
|
+
* name: "sentiment",
|
|
39
|
+
* label: "positive",
|
|
40
|
+
* score: 0.8,
|
|
41
|
+
* annotatorKind: "CODE"
|
|
42
|
+
* }
|
|
43
|
+
* ]
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function logSpanAnnotations({ client: _client, spanAnnotations, }: LogSpanAnnotationsParams): Promise<{
|
|
48
|
+
id: string;
|
|
49
|
+
}[]>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=logSpanAnnotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logSpanAnnotations.d.ts","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,UAAU,wBAAyB,SAAQ,QAAQ;IACjD;;OAEG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GAChB,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAkBtD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.logSpanAnnotations = logSpanAnnotations;
|
|
13
|
+
const client_1 = require("../client");
|
|
14
|
+
const types_1 = require("./types");
|
|
15
|
+
/**
|
|
16
|
+
* Log multiple span annotations in a single request.
|
|
17
|
+
*
|
|
18
|
+
* Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
|
|
19
|
+
* If an identifier is provided and an annotation with that identifier already exists, it will be updated.
|
|
20
|
+
*
|
|
21
|
+
* @param params - The parameters to log span annotations
|
|
22
|
+
* @returns The IDs of the created or updated annotations
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const results = await logSpanAnnotations({
|
|
27
|
+
* spanAnnotations: [
|
|
28
|
+
* {
|
|
29
|
+
* spanId: "123abc",
|
|
30
|
+
* name: "quality_score",
|
|
31
|
+
* label: "good",
|
|
32
|
+
* score: 0.95,
|
|
33
|
+
* annotatorKind: "LLM",
|
|
34
|
+
* identifier: "custom_id_123",
|
|
35
|
+
* metadata: {
|
|
36
|
+
* model: "gpt-4"
|
|
37
|
+
* }
|
|
38
|
+
* },
|
|
39
|
+
* {
|
|
40
|
+
* spanId: "456def",
|
|
41
|
+
* name: "sentiment",
|
|
42
|
+
* label: "positive",
|
|
43
|
+
* score: 0.8,
|
|
44
|
+
* annotatorKind: "CODE"
|
|
45
|
+
* }
|
|
46
|
+
* ]
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function logSpanAnnotations(_a) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* ({ client: _client, spanAnnotations, }) {
|
|
52
|
+
var _b;
|
|
53
|
+
const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)();
|
|
54
|
+
const { data, error } = yield client.POST("/v1/span_annotations", {
|
|
55
|
+
body: {
|
|
56
|
+
data: spanAnnotations.map(types_1.toSpanAnnotationData),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (error) {
|
|
60
|
+
throw new Error(`Failed to log span annotations: ${error}`);
|
|
61
|
+
}
|
|
62
|
+
if (!((_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
63
|
+
throw new Error("No annotation IDs returned from server");
|
|
64
|
+
}
|
|
65
|
+
return data.data;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=logSpanAnnotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logSpanAnnotations.js","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":";;;;;;;;;;;AAiDA,gDAqBC;AAtED,sCAAyC;AAEzC,mCAA+D;AAY/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAsB,kBAAkB;yDAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GACU;;QACzB,MAAM,MAAM,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAA,qBAAY,GAAE,CAAC;QAEzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;YAChE,IAAI,EAAE;gBACJ,IAAI,EAAE,eAAe,CAAC,GAAG,CAAC,4BAAoB,CAAC;aAChD;SACF,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAC;QAC9D,CAAC;QAED,IAAI,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,0CAAE,MAAM,CAAA,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { paths } from "../__generated__/api/v1";
|
|
2
|
+
type SpanAnnotationData = paths["/v1/span_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for a single span annotation
|
|
5
|
+
*/
|
|
6
|
+
export interface SpanAnnotation {
|
|
7
|
+
/**
|
|
8
|
+
* The OpenTelemetry Span ID (hex format without 0x prefix)
|
|
9
|
+
*/
|
|
10
|
+
spanId: string;
|
|
11
|
+
/**
|
|
12
|
+
* The name of the annotation
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
/**
|
|
16
|
+
* The label assigned by the annotation
|
|
17
|
+
*/
|
|
18
|
+
label?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The score assigned by the annotation
|
|
21
|
+
*/
|
|
22
|
+
score?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The identifier of the annotation. If provided, the annotation will be updated if it already exists.
|
|
25
|
+
*/
|
|
26
|
+
identifier?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Metadata for the annotation
|
|
29
|
+
*/
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* The kind of annotator used for the annotation
|
|
33
|
+
* Can be "HUMAN", "LLM", or "CODE"
|
|
34
|
+
* @default "HUMAN"
|
|
35
|
+
*/
|
|
36
|
+
annotatorKind?: SpanAnnotationData["annotator_kind"];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert a SpanAnnotation to the API format
|
|
40
|
+
*/
|
|
41
|
+
export declare function toSpanAnnotationData(annotation: SpanAnnotation): SpanAnnotationData;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,KAAK,kBAAkB,GACrB,KAAK,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,GACzB,kBAAkB,CAapB"}
|