scorecard-ai 0.4.0 → 0.5.3
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/Client.d.ts +2 -0
- package/api/resources/prompt/client/Client.d.ts +2 -0
- package/api/resources/prompt/client/Client.js +25 -20
- package/api/resources/run/client/Client.d.ts +2 -0
- package/api/resources/run/client/Client.js +15 -12
- package/api/resources/runMetric/client/Client.d.ts +2 -0
- package/api/resources/runMetric/client/Client.js +5 -4
- package/api/resources/score/client/Client.d.ts +2 -0
- package/api/resources/score/client/Client.js +10 -8
- package/api/resources/testcase/client/Client.d.ts +2 -0
- package/api/resources/testcase/client/Client.js +15 -12
- package/api/resources/testrecord/client/Client.d.ts +2 -0
- package/api/resources/testrecord/client/Client.js +10 -8
- package/api/resources/testset/client/Client.d.ts +2 -0
- package/api/resources/testset/client/Client.js +25 -20
- package/api/resources/traces/client/Client.d.ts +2 -0
- package/api/resources/traces/client/Client.js +5 -4
- package/core/fetcher/Fetcher.d.ts +1 -0
- package/core/fetcher/Fetcher.js +58 -7
- package/dist/Client.d.ts +2 -0
- package/dist/api/resources/prompt/client/Client.d.ts +2 -0
- package/dist/api/resources/prompt/client/Client.js +25 -20
- package/dist/api/resources/run/client/Client.d.ts +2 -0
- package/dist/api/resources/run/client/Client.js +15 -12
- package/dist/api/resources/runMetric/client/Client.d.ts +2 -0
- package/dist/api/resources/runMetric/client/Client.js +5 -4
- package/dist/api/resources/score/client/Client.d.ts +2 -0
- package/dist/api/resources/score/client/Client.js +10 -8
- package/dist/api/resources/testcase/client/Client.d.ts +2 -0
- package/dist/api/resources/testcase/client/Client.js +15 -12
- package/dist/api/resources/testrecord/client/Client.d.ts +2 -0
- package/dist/api/resources/testrecord/client/Client.js +10 -8
- package/dist/api/resources/testset/client/Client.d.ts +2 -0
- package/dist/api/resources/testset/client/Client.js +25 -20
- package/dist/api/resources/traces/client/Client.d.ts +2 -0
- package/dist/api/resources/traces/client/Client.js +5 -4
- package/dist/core/fetcher/Fetcher.d.ts +1 -0
- package/dist/core/fetcher/Fetcher.js +58 -7
- package/dist/telemetry.d.ts +6 -0
- package/dist/telemetry.js +65 -0
- package/dist/wrapper/ScorecardClient.d.ts +1 -8
- package/dist/wrapper/ScorecardClient.js +0 -12
- package/package.json +56 -2
- package/telemetry.d.ts +6 -0
- package/telemetry.js +65 -0
- package/wrapper/ScorecardClient.d.ts +1 -8
- package/wrapper/ScorecardClient.js +0 -12
|
@@ -64,15 +64,16 @@ class Testset {
|
|
|
64
64
|
* await scorecard.testset.get(1)
|
|
65
65
|
*/
|
|
66
66
|
get(testsetId, requestOptions) {
|
|
67
|
-
var _a;
|
|
67
|
+
var _a, _b;
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const _response = yield core.fetcher({
|
|
70
|
-
url: (0, url_join_1.default)((
|
|
69
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
70
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, `v1/testset/${encodeURIComponent(testsetId)}`),
|
|
71
71
|
method: "GET",
|
|
72
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
72
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
73
73
|
contentType: "application/json",
|
|
74
74
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
75
75
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
76
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
76
77
|
});
|
|
77
78
|
if (_response.ok) {
|
|
78
79
|
return yield serializers.Testset.parseOrThrow(_response.body, {
|
|
@@ -154,15 +155,16 @@ class Testset {
|
|
|
154
155
|
* await scorecard.testset.delete(1)
|
|
155
156
|
*/
|
|
156
157
|
delete(testsetId, requestOptions) {
|
|
157
|
-
var _a;
|
|
158
|
+
var _a, _b;
|
|
158
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const _response = yield core.fetcher({
|
|
160
|
-
url: (0, url_join_1.default)((
|
|
160
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
161
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, `v1/testset/${encodeURIComponent(testsetId)}`),
|
|
161
162
|
method: "DELETE",
|
|
162
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
163
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
163
164
|
contentType: "application/json",
|
|
164
165
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
165
166
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
167
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
166
168
|
});
|
|
167
169
|
if (_response.ok) {
|
|
168
170
|
return yield serializers.Testset.parseOrThrow(_response.body, {
|
|
@@ -246,16 +248,17 @@ class Testset {
|
|
|
246
248
|
* })
|
|
247
249
|
*/
|
|
248
250
|
create(request, requestOptions) {
|
|
249
|
-
var _a;
|
|
251
|
+
var _a, _b;
|
|
250
252
|
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
const _response = yield core.fetcher({
|
|
252
|
-
url: (0, url_join_1.default)((
|
|
253
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
254
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, "v1/testset"),
|
|
253
255
|
method: "POST",
|
|
254
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
256
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
255
257
|
contentType: "application/json",
|
|
256
258
|
body: yield serializers.TestsetCreateParams.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
|
|
257
259
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
258
260
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
261
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
259
262
|
});
|
|
260
263
|
if (_response.ok) {
|
|
261
264
|
return yield serializers.Testset.parseOrThrow(_response.body, {
|
|
@@ -337,15 +340,16 @@ class Testset {
|
|
|
337
340
|
* await scorecard.testset.readSchema(1)
|
|
338
341
|
*/
|
|
339
342
|
readSchema(testsetId, requestOptions) {
|
|
340
|
-
var _a;
|
|
343
|
+
var _a, _b;
|
|
341
344
|
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
-
const _response = yield core.fetcher({
|
|
343
|
-
url: (0, url_join_1.default)((
|
|
345
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
346
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, `v1/testset/${encodeURIComponent(testsetId)}/schema`),
|
|
344
347
|
method: "GET",
|
|
345
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
348
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
346
349
|
contentType: "application/json",
|
|
347
350
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
348
351
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
352
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
349
353
|
});
|
|
350
354
|
if (_response.ok) {
|
|
351
355
|
return yield serializers.CustomSchema.parseOrThrow(_response.body, {
|
|
@@ -428,7 +432,7 @@ class Testset {
|
|
|
428
432
|
* await scorecard.testset.getTestcases(1)
|
|
429
433
|
*/
|
|
430
434
|
getTestcases(testsetId, request = {}, requestOptions) {
|
|
431
|
-
var _a;
|
|
435
|
+
var _a, _b;
|
|
432
436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
433
437
|
const { offset, limit } = request;
|
|
434
438
|
const _queryParams = {};
|
|
@@ -438,14 +442,15 @@ class Testset {
|
|
|
438
442
|
if (limit != null) {
|
|
439
443
|
_queryParams["limit"] = limit.toString();
|
|
440
444
|
}
|
|
441
|
-
const _response = yield core.fetcher({
|
|
442
|
-
url: (0, url_join_1.default)((
|
|
445
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
446
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, `v1/testset/${encodeURIComponent(testsetId)}/testcase`),
|
|
443
447
|
method: "GET",
|
|
444
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
448
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
445
449
|
contentType: "application/json",
|
|
446
450
|
queryParameters: _queryParams,
|
|
447
451
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
448
452
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
453
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
449
454
|
});
|
|
450
455
|
if (_response.ok) {
|
|
451
456
|
return yield serializers.PaginatedTestcaseResponse.parseOrThrow(_response.body, {
|
|
@@ -8,10 +8,12 @@ export declare namespace Traces {
|
|
|
8
8
|
interface Options {
|
|
9
9
|
environment?: core.Supplier<environments.ScorecardEnvironment | string>;
|
|
10
10
|
apiKey: core.Supplier<string>;
|
|
11
|
+
fetcher?: core.FetchFunction;
|
|
11
12
|
}
|
|
12
13
|
interface RequestOptions {
|
|
13
14
|
timeoutInSeconds?: number;
|
|
14
15
|
maxRetries?: number;
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
export declare class Traces {
|
|
@@ -64,15 +64,16 @@ class Traces {
|
|
|
64
64
|
* await scorecard.traces.get("trace_id")
|
|
65
65
|
*/
|
|
66
66
|
get(traceId, requestOptions) {
|
|
67
|
-
var _a;
|
|
67
|
+
var _a, _b;
|
|
68
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const _response = yield core.fetcher({
|
|
70
|
-
url: (0, url_join_1.default)((
|
|
69
|
+
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
70
|
+
url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.ScorecardEnvironment.Default, `v1/traces/${encodeURIComponent(traceId)}/spans`),
|
|
71
71
|
method: "GET",
|
|
72
|
-
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.
|
|
72
|
+
headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "scorecard-ai", "X-Fern-SDK-Version": "0.5.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, (yield this._getCustomAuthorizationHeaders())),
|
|
73
73
|
contentType: "application/json",
|
|
74
74
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
75
75
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
76
|
+
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
76
77
|
});
|
|
77
78
|
if (_response.ok) {
|
|
78
79
|
return yield serializers.traces.get.Response.parseOrThrow(_response.body, {
|
|
@@ -11,6 +11,7 @@ export declare namespace Fetcher {
|
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
maxRetries?: number;
|
|
13
13
|
withCredentials?: boolean;
|
|
14
|
+
abortSignal?: AbortSignal;
|
|
14
15
|
responseType?: "json" | "blob" | "streaming" | "text";
|
|
15
16
|
}
|
|
16
17
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
@@ -63,6 +63,9 @@ function fetcherImpl(args) {
|
|
|
63
63
|
if (body instanceof Uint8Array) {
|
|
64
64
|
return body;
|
|
65
65
|
}
|
|
66
|
+
else if (args.contentType === "application/x-www-form-urlencoded" && typeof args.body === "string") {
|
|
67
|
+
return args.body;
|
|
68
|
+
}
|
|
66
69
|
else {
|
|
67
70
|
return JSON.stringify(body);
|
|
68
71
|
}
|
|
@@ -96,20 +99,27 @@ function fetcherImpl(args) {
|
|
|
96
99
|
? fetch
|
|
97
100
|
: (yield Promise.resolve().then(() => __importStar(require("node-fetch")))).default;
|
|
98
101
|
const makeRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const
|
|
100
|
-
|
|
102
|
+
const signals = [];
|
|
103
|
+
// Add timeout signal
|
|
104
|
+
let timeoutAbortId = undefined;
|
|
101
105
|
if (args.timeoutMs != null) {
|
|
102
|
-
abortId =
|
|
106
|
+
const { signal, abortId } = getTimeoutSignal(args.timeoutMs);
|
|
107
|
+
timeoutAbortId = abortId;
|
|
108
|
+
signals.push(signal);
|
|
109
|
+
}
|
|
110
|
+
// Add arbitrary signal
|
|
111
|
+
if (args.abortSignal != null) {
|
|
112
|
+
signals.push(args.abortSignal);
|
|
103
113
|
}
|
|
104
114
|
const response = yield fetchFn(url, {
|
|
105
115
|
method: args.method,
|
|
106
116
|
headers,
|
|
107
117
|
body,
|
|
108
|
-
signal:
|
|
118
|
+
signal: anySignal(signals),
|
|
109
119
|
credentials: args.withCredentials ? "include" : undefined,
|
|
110
120
|
});
|
|
111
|
-
if (
|
|
112
|
-
clearTimeout(
|
|
121
|
+
if (timeoutAbortId != null) {
|
|
122
|
+
clearTimeout(timeoutAbortId);
|
|
113
123
|
}
|
|
114
124
|
return response;
|
|
115
125
|
});
|
|
@@ -175,7 +185,16 @@ function fetcherImpl(args) {
|
|
|
175
185
|
}
|
|
176
186
|
}
|
|
177
187
|
catch (error) {
|
|
178
|
-
if (
|
|
188
|
+
if (args.abortSignal != null && args.abortSignal.aborted) {
|
|
189
|
+
return {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: {
|
|
192
|
+
reason: "unknown",
|
|
193
|
+
errorMessage: "The user aborted a request",
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
else if (error instanceof Error && error.name === "AbortError") {
|
|
179
198
|
return {
|
|
180
199
|
ok: false,
|
|
181
200
|
error: {
|
|
@@ -202,4 +221,36 @@ function fetcherImpl(args) {
|
|
|
202
221
|
}
|
|
203
222
|
});
|
|
204
223
|
}
|
|
224
|
+
const TIMEOUT = "timeout";
|
|
225
|
+
function getTimeoutSignal(timeoutMs) {
|
|
226
|
+
const controller = new AbortController();
|
|
227
|
+
const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
|
|
228
|
+
return { signal: controller.signal, abortId };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Returns an abort signal that is getting aborted when
|
|
232
|
+
* at least one of the specified abort signals is aborted.
|
|
233
|
+
*
|
|
234
|
+
* Requires at least node.js 18.
|
|
235
|
+
*/
|
|
236
|
+
function anySignal(...args) {
|
|
237
|
+
// Allowing signals to be passed either as array
|
|
238
|
+
// of signals or as multiple arguments.
|
|
239
|
+
const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
|
|
240
|
+
const controller = new AbortController();
|
|
241
|
+
for (const signal of signals) {
|
|
242
|
+
if (signal.aborted) {
|
|
243
|
+
// Exiting early if one of the signals
|
|
244
|
+
// is already aborted.
|
|
245
|
+
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
// Listening for signals and removing the listeners
|
|
249
|
+
// when at least one symbol is aborted.
|
|
250
|
+
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
251
|
+
signal: controller.signal,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return controller.signal;
|
|
255
|
+
}
|
|
205
256
|
exports.fetcher = fetcherImpl;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const trace: any;
|
|
2
|
+
declare const OTLPTraceExporter: any;
|
|
3
|
+
declare const Resource: any;
|
|
4
|
+
declare const BatchSpanProcessor: any, ConsoleSpanExporter: any, NodeTracerProvider: any;
|
|
5
|
+
declare const SEMRESATTRS_SERVICE_NAME: any;
|
|
6
|
+
declare function checkInstalled(...modules: string[]): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
const { trace } = require('@opentelemetry/api');
|
|
12
|
+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
|
|
13
|
+
const { Resource } = require('@opentelemetry/resources');
|
|
14
|
+
const { BatchSpanProcessor, ConsoleSpanExporter, NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
|
|
15
|
+
const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
|
|
16
|
+
function checkInstalled(...modules) {
|
|
17
|
+
for (let i = 0; i < modules.length; i++) {
|
|
18
|
+
let module = modules[i];
|
|
19
|
+
try {
|
|
20
|
+
require.resolve(module);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
module.exports = {
|
|
29
|
+
setup(name, scorecardConfig, debug = false) {
|
|
30
|
+
const resource = Resource.default().merge(new Resource({
|
|
31
|
+
[SEMRESATTRS_SERVICE_NAME]: name,
|
|
32
|
+
}));
|
|
33
|
+
const provider = new NodeTracerProvider({
|
|
34
|
+
resource,
|
|
35
|
+
});
|
|
36
|
+
if (debug) {
|
|
37
|
+
const consoleExporter = new ConsoleSpanExporter();
|
|
38
|
+
const processor = new BatchSpanProcessor(consoleExporter);
|
|
39
|
+
provider.addSpanProcessor(processor);
|
|
40
|
+
}
|
|
41
|
+
const url = scorecardConfig.telemetryUrl ? scorecardConfig.telemetryUrl : 'https://telemetry.getscorecard.ai';
|
|
42
|
+
const otlpExporter = new OTLPTraceExporter({
|
|
43
|
+
url: `${url}/v1/traces`,
|
|
44
|
+
headers: {
|
|
45
|
+
'Authorization': `Bearer ${scorecardConfig.telemetryKey}`
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const processor = new BatchSpanProcessor(otlpExporter);
|
|
49
|
+
provider.addSpanProcessor(processor);
|
|
50
|
+
provider.register();
|
|
51
|
+
if (checkInstalled('@langchain/core')) {
|
|
52
|
+
const { LangChainInstrumentation } = require('@arizeai/openinference-instrumentation-langchain');
|
|
53
|
+
new LangChainInstrumentation().manuallyInstrument(require('@langchain/core/callbacks/manager'));
|
|
54
|
+
}
|
|
55
|
+
if (checkInstalled('openai')) {
|
|
56
|
+
const { OpenAIInstrumentation } = require('@arizeai/openinference-instrumentation-openai');
|
|
57
|
+
new OpenAIInstrumentation().manuallyInstrument(require('openai'));
|
|
58
|
+
}
|
|
59
|
+
const tracer = trace.getTracer();
|
|
60
|
+
process.on('beforeExit', () => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield provider.shutdown();
|
|
62
|
+
}));
|
|
63
|
+
return tracer;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { ScorecardClient as FernClient } from "../Client";
|
|
2
|
-
import * as core from "../core";
|
|
3
2
|
export declare namespace ScorecardClient {
|
|
4
|
-
interface
|
|
5
|
-
/**
|
|
6
|
-
* Your Scorecard API Key. Defaults to the environment
|
|
7
|
-
* variable SCORECARD_API_KEY.
|
|
8
|
-
*/
|
|
9
|
-
apiKey?: core.Supplier<string>;
|
|
3
|
+
interface RequestOptions extends FernClient.RequestOptions {
|
|
10
4
|
}
|
|
11
5
|
interface RunTestArgs {
|
|
12
6
|
/**
|
|
@@ -24,7 +18,6 @@ export declare namespace ScorecardClient {
|
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
export declare class ScorecardClient extends FernClient {
|
|
27
|
-
constructor(options?: ScorecardClient.Options);
|
|
28
21
|
/**
|
|
29
22
|
* Runs all tests within a testset
|
|
30
23
|
*/
|
|
@@ -36,18 +36,6 @@ exports.ScorecardClient = void 0;
|
|
|
36
36
|
const Client_1 = require("../Client");
|
|
37
37
|
const errors = __importStar(require("../errors"));
|
|
38
38
|
class ScorecardClient extends Client_1.ScorecardClient {
|
|
39
|
-
constructor(options = {}) {
|
|
40
|
-
var _a;
|
|
41
|
-
const apiKey = (_a = options.apiKey) !== null && _a !== void 0 ? _a : process.env["SCORECARD_API_KEY"];
|
|
42
|
-
if (apiKey == null) {
|
|
43
|
-
throw new errors.ScorecardError({
|
|
44
|
-
message: "Please pass in your Scorecard API Key or export SCORECARD_API_KEY in your environment.",
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
super({
|
|
48
|
-
apiKey,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
39
|
/**
|
|
52
40
|
* Runs all tests within a testset
|
|
53
41
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scorecard-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "https://github.com/scorecard-ai/scorecard-node",
|
|
6
6
|
"license": "See LICENSE",
|
|
@@ -19,6 +19,50 @@
|
|
|
19
19
|
"node-fetch": "2.7.0",
|
|
20
20
|
"qs": "6.11.2"
|
|
21
21
|
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@arizeai/openinference-instrumentation-langchain": "^0.0.5",
|
|
24
|
+
"@arizeai/openinference-instrumentation-openai": "^0.2.0",
|
|
25
|
+
"@langchain/core": "^0.1.63",
|
|
26
|
+
"@opentelemetry/api": "*",
|
|
27
|
+
"@opentelemetry/exporter-trace-otlp-http": "*",
|
|
28
|
+
"@opentelemetry/instrumentation": ">=0.40.0",
|
|
29
|
+
"@opentelemetry/resources": "*",
|
|
30
|
+
"@opentelemetry/sdk-trace-node": "*",
|
|
31
|
+
"@opentelemetry/semantic-conventions": "*",
|
|
32
|
+
"openai": "^4.47.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@arizeai/openinference-instrumentation-langchain": {
|
|
36
|
+
"optional": false
|
|
37
|
+
},
|
|
38
|
+
"@arizeai/openinference-instrumentation-openai": {
|
|
39
|
+
"optional": false
|
|
40
|
+
},
|
|
41
|
+
"@langchain/core": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@opentelemetry/api": {
|
|
45
|
+
"optional": false
|
|
46
|
+
},
|
|
47
|
+
"@opentelemetry/exporter-trace-otlp-http": {
|
|
48
|
+
"optional": false
|
|
49
|
+
},
|
|
50
|
+
"@opentelemetry/instrumentation": {
|
|
51
|
+
"optional": false
|
|
52
|
+
},
|
|
53
|
+
"@opentelemetry/resources": {
|
|
54
|
+
"optional": false
|
|
55
|
+
},
|
|
56
|
+
"@opentelemetry/sdk-trace-node": {
|
|
57
|
+
"optional": false
|
|
58
|
+
},
|
|
59
|
+
"@opentelemetry/semantic-conventions": {
|
|
60
|
+
"optional": false
|
|
61
|
+
},
|
|
62
|
+
"openai": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
22
66
|
"devDependencies": {
|
|
23
67
|
"@types/url-join": "4.0.1",
|
|
24
68
|
"@types/qs": "6.9.8",
|
|
@@ -29,6 +73,16 @@
|
|
|
29
73
|
"jest-environment-jsdom": "29.7.0",
|
|
30
74
|
"@types/node": "17.0.33",
|
|
31
75
|
"prettier": "2.7.1",
|
|
32
|
-
"typescript": "4.6.4"
|
|
76
|
+
"typescript": "4.6.4",
|
|
77
|
+
"@arizeai/openinference-instrumentation-langchain": "^0.0.5",
|
|
78
|
+
"@arizeai/openinference-instrumentation-openai": "^0.2.0",
|
|
79
|
+
"@langchain/core": "^0.1.63",
|
|
80
|
+
"@opentelemetry/api": "latest",
|
|
81
|
+
"@opentelemetry/exporter-trace-otlp-http": "latest",
|
|
82
|
+
"@opentelemetry/instrumentation": "latest",
|
|
83
|
+
"@opentelemetry/resources": "latest",
|
|
84
|
+
"@opentelemetry/sdk-trace-node": "latest",
|
|
85
|
+
"@opentelemetry/semantic-conventions": "latest",
|
|
86
|
+
"openai": "^4.47.1"
|
|
33
87
|
}
|
|
34
88
|
}
|
package/telemetry.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const trace: any;
|
|
2
|
+
declare const OTLPTraceExporter: any;
|
|
3
|
+
declare const Resource: any;
|
|
4
|
+
declare const BatchSpanProcessor: any, ConsoleSpanExporter: any, NodeTracerProvider: any;
|
|
5
|
+
declare const SEMRESATTRS_SERVICE_NAME: any;
|
|
6
|
+
declare function checkInstalled(...modules: string[]): boolean;
|
package/telemetry.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
const { trace } = require('@opentelemetry/api');
|
|
12
|
+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
|
|
13
|
+
const { Resource } = require('@opentelemetry/resources');
|
|
14
|
+
const { BatchSpanProcessor, ConsoleSpanExporter, NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
|
|
15
|
+
const { SEMRESATTRS_SERVICE_NAME } = require('@opentelemetry/semantic-conventions');
|
|
16
|
+
function checkInstalled(...modules) {
|
|
17
|
+
for (let i = 0; i < modules.length; i++) {
|
|
18
|
+
let module = modules[i];
|
|
19
|
+
try {
|
|
20
|
+
require.resolve(module);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
module.exports = {
|
|
29
|
+
setup(name, scorecardConfig, debug = false) {
|
|
30
|
+
const resource = Resource.default().merge(new Resource({
|
|
31
|
+
[SEMRESATTRS_SERVICE_NAME]: name,
|
|
32
|
+
}));
|
|
33
|
+
const provider = new NodeTracerProvider({
|
|
34
|
+
resource,
|
|
35
|
+
});
|
|
36
|
+
if (debug) {
|
|
37
|
+
const consoleExporter = new ConsoleSpanExporter();
|
|
38
|
+
const processor = new BatchSpanProcessor(consoleExporter);
|
|
39
|
+
provider.addSpanProcessor(processor);
|
|
40
|
+
}
|
|
41
|
+
const url = scorecardConfig.telemetryUrl ? scorecardConfig.telemetryUrl : 'https://telemetry.getscorecard.ai';
|
|
42
|
+
const otlpExporter = new OTLPTraceExporter({
|
|
43
|
+
url: `${url}/v1/traces`,
|
|
44
|
+
headers: {
|
|
45
|
+
'Authorization': `Bearer ${scorecardConfig.telemetryKey}`
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const processor = new BatchSpanProcessor(otlpExporter);
|
|
49
|
+
provider.addSpanProcessor(processor);
|
|
50
|
+
provider.register();
|
|
51
|
+
if (checkInstalled('@langchain/core')) {
|
|
52
|
+
const { LangChainInstrumentation } = require('@arizeai/openinference-instrumentation-langchain');
|
|
53
|
+
new LangChainInstrumentation().manuallyInstrument(require('@langchain/core/callbacks/manager'));
|
|
54
|
+
}
|
|
55
|
+
if (checkInstalled('openai')) {
|
|
56
|
+
const { OpenAIInstrumentation } = require('@arizeai/openinference-instrumentation-openai');
|
|
57
|
+
new OpenAIInstrumentation().manuallyInstrument(require('openai'));
|
|
58
|
+
}
|
|
59
|
+
const tracer = trace.getTracer();
|
|
60
|
+
process.on('beforeExit', () => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield provider.shutdown();
|
|
62
|
+
}));
|
|
63
|
+
return tracer;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { ScorecardClient as FernClient } from "../Client";
|
|
2
|
-
import * as core from "../core";
|
|
3
2
|
export declare namespace ScorecardClient {
|
|
4
|
-
interface
|
|
5
|
-
/**
|
|
6
|
-
* Your Scorecard API Key. Defaults to the environment
|
|
7
|
-
* variable SCORECARD_API_KEY.
|
|
8
|
-
*/
|
|
9
|
-
apiKey?: core.Supplier<string>;
|
|
3
|
+
interface RequestOptions extends FernClient.RequestOptions {
|
|
10
4
|
}
|
|
11
5
|
interface RunTestArgs {
|
|
12
6
|
/**
|
|
@@ -24,7 +18,6 @@ export declare namespace ScorecardClient {
|
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
export declare class ScorecardClient extends FernClient {
|
|
27
|
-
constructor(options?: ScorecardClient.Options);
|
|
28
21
|
/**
|
|
29
22
|
* Runs all tests within a testset
|
|
30
23
|
*/
|
|
@@ -36,18 +36,6 @@ exports.ScorecardClient = void 0;
|
|
|
36
36
|
const Client_1 = require("../Client");
|
|
37
37
|
const errors = __importStar(require("../errors"));
|
|
38
38
|
class ScorecardClient extends Client_1.ScorecardClient {
|
|
39
|
-
constructor(options = {}) {
|
|
40
|
-
var _a;
|
|
41
|
-
const apiKey = (_a = options.apiKey) !== null && _a !== void 0 ? _a : process.env["SCORECARD_API_KEY"];
|
|
42
|
-
if (apiKey == null) {
|
|
43
|
-
throw new errors.ScorecardError({
|
|
44
|
-
message: "Please pass in your Scorecard API Key or export SCORECARD_API_KEY in your environment.",
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
super({
|
|
48
|
-
apiKey,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
39
|
/**
|
|
52
40
|
* Runs all tests within a testset
|
|
53
41
|
*/
|