openlayer 0.1.9 → 0.1.11
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/index.d.ts +4 -4
- package/dist/index.js +18 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -127,8 +127,9 @@ type OpenlayerSampleVolumeGraph = {
|
|
|
127
127
|
weekly: OpenlayerSampleVolumeGraphBucket;
|
|
128
128
|
};
|
|
129
129
|
type OpenlayerTaskType = 'llm-base' | 'tabular-classification' | 'tabular-regression' | 'text-classification';
|
|
130
|
-
declare class OpenlayerClient {
|
|
130
|
+
export declare class OpenlayerClient {
|
|
131
131
|
private openlayerApiKey?;
|
|
132
|
+
private openlayerDefaultDataConfig;
|
|
132
133
|
private openlayerServerUrl;
|
|
133
134
|
private version;
|
|
134
135
|
constructor({ openlayerApiKey, openlayerServerUrl, }: OpenlayerClientConstructorProps);
|
|
@@ -141,7 +142,7 @@ declare class OpenlayerClient {
|
|
|
141
142
|
* @throws Throws an error if Openlayer API key or project name are not set.
|
|
142
143
|
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
143
144
|
*/
|
|
144
|
-
streamData: (data: ChatCompletionData,
|
|
145
|
+
streamData: (data: ChatCompletionData, inferencePipelineId: string) => Promise<void>;
|
|
145
146
|
/**
|
|
146
147
|
* Creates a new inference pipeline in Openlayer, or loads an existing one if it already exists.
|
|
147
148
|
* @param name The name of the inference pipeline.
|
|
@@ -172,7 +173,6 @@ declare class OpenlayerClient {
|
|
|
172
173
|
export declare class OpenAIMonitor {
|
|
173
174
|
private openlayerClient;
|
|
174
175
|
private openAIClient;
|
|
175
|
-
private openlayerDefaultDataConfig;
|
|
176
176
|
private openlayerProjectName;
|
|
177
177
|
private openlayerInferencePipelineName;
|
|
178
178
|
private monitoringOn;
|
|
@@ -205,4 +205,4 @@ export declare class OpenAIMonitor {
|
|
|
205
205
|
*/
|
|
206
206
|
stopMonitoring(): void;
|
|
207
207
|
}
|
|
208
|
-
export
|
|
208
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -16,12 +16,21 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
16
16
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.OpenAIMonitor = void 0;
|
|
19
|
+
exports.OpenAIMonitor = exports.OpenlayerClient = void 0;
|
|
20
20
|
const openai_1 = require("openai");
|
|
21
21
|
const uuid_1 = require("uuid");
|
|
22
22
|
const request_1 = require("./utils/request");
|
|
23
23
|
class OpenlayerClient {
|
|
24
24
|
constructor({ openlayerApiKey, openlayerServerUrl, }) {
|
|
25
|
+
this.openlayerDefaultDataConfig = {
|
|
26
|
+
groundTruthColumnName: null,
|
|
27
|
+
inferenceIdColumnName: 'id',
|
|
28
|
+
inputVariableNames: ['input'],
|
|
29
|
+
latencyColumnName: 'latency',
|
|
30
|
+
numOfTokenColumnName: 'tokens',
|
|
31
|
+
outputColumnName: 'output',
|
|
32
|
+
timestampColumnName: 'timestamp',
|
|
33
|
+
};
|
|
25
34
|
this.openlayerServerUrl = 'https://api.openlayer.com/v1';
|
|
26
35
|
this.version = '0.1.0a16';
|
|
27
36
|
this.resolvedQuery = (endpoint, args = {}) => (0, request_1.resolvedQuery)(this.openlayerServerUrl, endpoint, args);
|
|
@@ -33,7 +42,7 @@ class OpenlayerClient {
|
|
|
33
42
|
* @throws Throws an error if Openlayer API key or project name are not set.
|
|
34
43
|
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
35
44
|
*/
|
|
36
|
-
this.streamData = (data,
|
|
45
|
+
this.streamData = (data, inferencePipelineId) => __awaiter(this, void 0, void 0, function* () {
|
|
37
46
|
var _a;
|
|
38
47
|
if (!this.openlayerApiKey) {
|
|
39
48
|
throw new Error('Openlayer API key are required for streaming data.');
|
|
@@ -43,7 +52,7 @@ class OpenlayerClient {
|
|
|
43
52
|
const dataStreamQuery = this.resolvedQuery(dataStreamEndpoint);
|
|
44
53
|
const response = yield fetch(dataStreamQuery, {
|
|
45
54
|
body: JSON.stringify({
|
|
46
|
-
config,
|
|
55
|
+
config: this.openlayerDefaultDataConfig,
|
|
47
56
|
rows: [
|
|
48
57
|
Object.assign(Object.assign({}, data), { id: (0, uuid_1.v4)(), timestamp: Math.round(((_a = data.timestamp) !== null && _a !== void 0 ? _a : Date.now()) / 1000) }),
|
|
49
58
|
],
|
|
@@ -74,7 +83,7 @@ class OpenlayerClient {
|
|
|
74
83
|
*/
|
|
75
84
|
this.createInferencePipeline = (projectId, name = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
76
85
|
try {
|
|
77
|
-
return yield this.loadInferencePipeline(
|
|
86
|
+
return yield this.loadInferencePipeline(projectId, name);
|
|
78
87
|
}
|
|
79
88
|
catch (_b) {
|
|
80
89
|
const createInferencePipelineEndpoint = `/projects/${projectId}/inference-pipelines`;
|
|
@@ -198,17 +207,9 @@ class OpenlayerClient {
|
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
}
|
|
210
|
+
exports.OpenlayerClient = OpenlayerClient;
|
|
201
211
|
class OpenAIMonitor {
|
|
202
212
|
constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineName, openlayerServerUrl, }) {
|
|
203
|
-
this.openlayerDefaultDataConfig = {
|
|
204
|
-
groundTruthColumnName: null,
|
|
205
|
-
inferenceIdColumnName: 'id',
|
|
206
|
-
inputVariableNames: ['input'],
|
|
207
|
-
latencyColumnName: 'latency',
|
|
208
|
-
numOfTokenColumnName: 'tokens',
|
|
209
|
-
outputColumnName: 'output',
|
|
210
|
-
timestampColumnName: 'timestamp',
|
|
211
|
-
};
|
|
212
213
|
this.openlayerInferencePipelineName = 'production';
|
|
213
214
|
this.monitoringOn = false;
|
|
214
215
|
this.formatChatCompletionInput = (messages) => messages
|
|
@@ -262,7 +263,7 @@ class OpenAIMonitor {
|
|
|
262
263
|
latency,
|
|
263
264
|
output: outputData,
|
|
264
265
|
timestamp: startTime,
|
|
265
|
-
},
|
|
266
|
+
}, inferencePipeline.id);
|
|
266
267
|
}
|
|
267
268
|
else {
|
|
268
269
|
const nonStreamedResponse = response;
|
|
@@ -279,7 +280,7 @@ class OpenAIMonitor {
|
|
|
279
280
|
output,
|
|
280
281
|
timestamp: startTime,
|
|
281
282
|
tokens: (_e = (_d = nonStreamedResponse.usage) === null || _d === void 0 ? void 0 : _d.total_tokens) !== null && _e !== void 0 ? _e : 0,
|
|
282
|
-
},
|
|
283
|
+
}, inferencePipeline.id);
|
|
283
284
|
}
|
|
284
285
|
return response;
|
|
285
286
|
});
|
|
@@ -335,7 +336,7 @@ class OpenAIMonitor {
|
|
|
335
336
|
output: outputData,
|
|
336
337
|
timestamp: startTime,
|
|
337
338
|
tokens: tokensData,
|
|
338
|
-
},
|
|
339
|
+
}, inferencePipeline.id);
|
|
339
340
|
}
|
|
340
341
|
else {
|
|
341
342
|
const nonStreamedResponse = response;
|
|
@@ -348,7 +349,7 @@ class OpenAIMonitor {
|
|
|
348
349
|
output: nonStreamedResponse.choices[0].text,
|
|
349
350
|
timestamp: startTime,
|
|
350
351
|
tokens: (_o = (_m = nonStreamedResponse.usage) === null || _m === void 0 ? void 0 : _m.total_tokens) !== null && _o !== void 0 ? _o : 0,
|
|
351
|
-
},
|
|
352
|
+
}, inferencePipeline.id);
|
|
352
353
|
}
|
|
353
354
|
return response;
|
|
354
355
|
});
|
|
@@ -389,4 +390,3 @@ class OpenAIMonitor {
|
|
|
389
390
|
}
|
|
390
391
|
}
|
|
391
392
|
exports.OpenAIMonitor = OpenAIMonitor;
|
|
392
|
-
exports.default = OpenlayerClient;
|