openlayer 0.1.6 → 0.1.8
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 +9 -7
- package/dist/index.js +22 -23
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ type OpenlayerClientConstructorProps = {
|
|
|
69
69
|
};
|
|
70
70
|
type OpenAIMonitorConstructorProps = OpenlayerClientConstructorProps & {
|
|
71
71
|
openAiApiKey: string;
|
|
72
|
+
openlayerInferencePipelineName?: string;
|
|
73
|
+
openlayerProjectName: string;
|
|
72
74
|
};
|
|
73
75
|
type OpenlayerInferencePipeline = {
|
|
74
76
|
dataVolumeGraphs?: OpenlayerSampleVolumeGraph;
|
|
@@ -127,11 +129,9 @@ type OpenlayerSampleVolumeGraph = {
|
|
|
127
129
|
type OpenlayerTaskType = 'llm-base' | 'tabular-classification' | 'tabular-regression' | 'text-classification';
|
|
128
130
|
declare class OpenlayerClient {
|
|
129
131
|
private openlayerApiKey?;
|
|
130
|
-
private openlayerProjectName?;
|
|
131
|
-
private openlayerInferencePipelineName?;
|
|
132
132
|
private openlayerServerUrl;
|
|
133
133
|
private version;
|
|
134
|
-
constructor({ openlayerApiKey,
|
|
134
|
+
constructor({ openlayerApiKey, openlayerServerUrl, }: OpenlayerClientConstructorProps);
|
|
135
135
|
private resolvedQuery;
|
|
136
136
|
private uploadToInferencePipeline;
|
|
137
137
|
/**
|
|
@@ -142,7 +142,7 @@ declare class OpenlayerClient {
|
|
|
142
142
|
* @throws Throws an error if Openlayer API key or project name are not set.
|
|
143
143
|
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
144
144
|
*/
|
|
145
|
-
uploadDataToOpenlayer: (data: ChatCompletionData, config: ChatCompletionConfig) => Promise<void>;
|
|
145
|
+
uploadDataToOpenlayer: (data: ChatCompletionData, config: ChatCompletionConfig, projectName: string, inferencePipelineName?: string) => Promise<void>;
|
|
146
146
|
/**
|
|
147
147
|
* Creates a new inference pipeline in Openlayer, or loads an existing one if it already exists.
|
|
148
148
|
* @param name The name of the inference pipeline.
|
|
@@ -150,7 +150,7 @@ declare class OpenlayerClient {
|
|
|
150
150
|
* @throws Throws an error if the inference pipeline cannot be created or found.
|
|
151
151
|
* @returns A promise that resolves to an OpenlayerInferencePipeline object.
|
|
152
152
|
*/
|
|
153
|
-
createInferencePipeline: (
|
|
153
|
+
createInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
|
|
154
154
|
/**
|
|
155
155
|
* Creates a new project in Openlayer, or loads an existing one if it already exists.
|
|
156
156
|
* @param name The name of the project.
|
|
@@ -167,15 +167,17 @@ declare class OpenlayerClient {
|
|
|
167
167
|
* @throws Throws an error if the inference pipeline is not found.
|
|
168
168
|
* @returns A promise that resolves to an OpenlayerInferencePipeline object.
|
|
169
169
|
*/
|
|
170
|
-
loadInferencePipeline: (
|
|
170
|
+
loadInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
|
|
171
171
|
loadProject: (name: string) => Promise<OpenlayerProject>;
|
|
172
172
|
}
|
|
173
173
|
export declare class OpenAIMonitor {
|
|
174
174
|
private openlayerClient;
|
|
175
175
|
private openAIClient;
|
|
176
176
|
private openlayerDefaultDataConfig;
|
|
177
|
+
private openlayerProjectName;
|
|
178
|
+
private openlayerInferencePipelineName;
|
|
177
179
|
private monitoringOn;
|
|
178
|
-
constructor({ openAiApiKey, openlayerApiKey,
|
|
180
|
+
constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineName, openlayerServerUrl, }: OpenAIMonitorConstructorProps);
|
|
179
181
|
private formatChatCompletionInput;
|
|
180
182
|
/**
|
|
181
183
|
* Creates a new ChatCompletion instance. If monitoring is not active, an error is thrown.
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ 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
|
-
constructor({ openlayerApiKey,
|
|
24
|
+
constructor({ openlayerApiKey, openlayerServerUrl, }) {
|
|
25
25
|
this.openlayerServerUrl = 'https://api.openlayer.com/v1';
|
|
26
26
|
this.version = '0.1.0a16';
|
|
27
27
|
this.resolvedQuery = (endpoint, args = {}) => (0, request_1.resolvedQuery)(this.openlayerServerUrl, endpoint, args);
|
|
@@ -56,13 +56,13 @@ class OpenlayerClient {
|
|
|
56
56
|
* @throws Throws an error if Openlayer API key or project name are not set.
|
|
57
57
|
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
58
58
|
*/
|
|
59
|
-
this.uploadDataToOpenlayer = (data, config) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
if (!this.openlayerApiKey
|
|
61
|
-
throw new Error('Openlayer API key
|
|
59
|
+
this.uploadDataToOpenlayer = (data, config, projectName, inferencePipelineName = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!this.openlayerApiKey) {
|
|
61
|
+
throw new Error('Openlayer API key are required for publishing.');
|
|
62
62
|
}
|
|
63
63
|
try {
|
|
64
|
-
const project = yield this.createProject(
|
|
65
|
-
const inferencePipeline = yield this.createInferencePipeline(
|
|
64
|
+
const project = yield this.createProject(projectName, 'llm-base');
|
|
65
|
+
const inferencePipeline = yield this.createInferencePipeline(inferencePipelineName, project.id);
|
|
66
66
|
yield this.uploadToInferencePipeline(inferencePipeline.id, data, config);
|
|
67
67
|
}
|
|
68
68
|
catch (error) {
|
|
@@ -77,7 +77,7 @@ class OpenlayerClient {
|
|
|
77
77
|
* @throws Throws an error if the inference pipeline cannot be created or found.
|
|
78
78
|
* @returns A promise that resolves to an OpenlayerInferencePipeline object.
|
|
79
79
|
*/
|
|
80
|
-
this.createInferencePipeline = (
|
|
80
|
+
this.createInferencePipeline = (projectId, name = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
81
81
|
try {
|
|
82
82
|
return yield this.loadInferencePipeline(name, projectId);
|
|
83
83
|
}
|
|
@@ -87,9 +87,7 @@ class OpenlayerClient {
|
|
|
87
87
|
const createInferencePipelineResponse = yield fetch(createInferencePipelineQuery, {
|
|
88
88
|
body: JSON.stringify({
|
|
89
89
|
description: '',
|
|
90
|
-
name
|
|
91
|
-
? 'production'
|
|
92
|
-
: this.openlayerInferencePipelineName,
|
|
90
|
+
name,
|
|
93
91
|
}),
|
|
94
92
|
headers: {
|
|
95
93
|
Authorization: `Bearer ${this.openlayerApiKey}`,
|
|
@@ -149,10 +147,10 @@ class OpenlayerClient {
|
|
|
149
147
|
* @throws Throws an error if the inference pipeline is not found.
|
|
150
148
|
* @returns A promise that resolves to an OpenlayerInferencePipeline object.
|
|
151
149
|
*/
|
|
152
|
-
this.loadInferencePipeline = (
|
|
150
|
+
this.loadInferencePipeline = (projectId, name = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
153
151
|
const inferencePipelineEndpoint = `/projects/${projectId}/inference-pipelines`;
|
|
154
152
|
const inferencePipelineQueryParameters = {
|
|
155
|
-
name
|
|
153
|
+
name,
|
|
156
154
|
version: this.version,
|
|
157
155
|
};
|
|
158
156
|
const inferencePipelineQuery = this.resolvedQuery(inferencePipelineEndpoint, inferencePipelineQueryParameters);
|
|
@@ -197,18 +195,16 @@ class OpenlayerClient {
|
|
|
197
195
|
return project;
|
|
198
196
|
});
|
|
199
197
|
this.openlayerApiKey = openlayerApiKey;
|
|
200
|
-
this.openlayerInferencePipelineName = openlayerInferencePipelineName;
|
|
201
|
-
this.openlayerProjectName = openlayerProjectName;
|
|
202
198
|
if (openlayerServerUrl) {
|
|
203
199
|
this.openlayerServerUrl = openlayerServerUrl;
|
|
204
200
|
}
|
|
205
|
-
if (!this.openlayerApiKey
|
|
206
|
-
throw new Error('Openlayer API key
|
|
201
|
+
if (!this.openlayerApiKey) {
|
|
202
|
+
throw new Error('Openlayer API key are required for publishing.');
|
|
207
203
|
}
|
|
208
204
|
}
|
|
209
205
|
}
|
|
210
206
|
class OpenAIMonitor {
|
|
211
|
-
constructor({ openAiApiKey, openlayerApiKey,
|
|
207
|
+
constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineName, openlayerServerUrl, }) {
|
|
212
208
|
this.openlayerDefaultDataConfig = {
|
|
213
209
|
groundTruthColumnName: null,
|
|
214
210
|
inferenceIdColumnName: 'id',
|
|
@@ -218,6 +214,7 @@ class OpenAIMonitor {
|
|
|
218
214
|
outputColumnName: 'output',
|
|
219
215
|
timestampColumnName: 'timestamp',
|
|
220
216
|
};
|
|
217
|
+
this.openlayerInferencePipelineName = 'production';
|
|
221
218
|
this.monitoringOn = false;
|
|
222
219
|
this.formatChatCompletionInput = (messages) => messages
|
|
223
220
|
.filter(({ role }) => role === 'user')
|
|
@@ -268,7 +265,7 @@ class OpenAIMonitor {
|
|
|
268
265
|
latency,
|
|
269
266
|
output: outputData,
|
|
270
267
|
timestamp: startTime,
|
|
271
|
-
}, this.openlayerDefaultDataConfig);
|
|
268
|
+
}, this.openlayerDefaultDataConfig, this.openlayerProjectName, this.openlayerInferencePipelineName);
|
|
272
269
|
}
|
|
273
270
|
else {
|
|
274
271
|
const nonStreamedResponse = response;
|
|
@@ -285,7 +282,7 @@ class OpenAIMonitor {
|
|
|
285
282
|
output,
|
|
286
283
|
timestamp: startTime,
|
|
287
284
|
tokens: (_e = (_d = nonStreamedResponse.usage) === null || _d === void 0 ? void 0 : _d.total_tokens) !== null && _e !== void 0 ? _e : 0,
|
|
288
|
-
}, this.openlayerDefaultDataConfig);
|
|
285
|
+
}, this.openlayerDefaultDataConfig, this.openlayerProjectName, this.openlayerInferencePipelineName);
|
|
289
286
|
}
|
|
290
287
|
return response;
|
|
291
288
|
});
|
|
@@ -339,7 +336,7 @@ class OpenAIMonitor {
|
|
|
339
336
|
output: outputData,
|
|
340
337
|
timestamp: startTime,
|
|
341
338
|
tokens: tokensData,
|
|
342
|
-
}, this.openlayerDefaultDataConfig);
|
|
339
|
+
}, this.openlayerDefaultDataConfig, this.openlayerProjectName, this.openlayerInferencePipelineName);
|
|
343
340
|
}
|
|
344
341
|
else {
|
|
345
342
|
const nonStreamedResponse = response;
|
|
@@ -352,14 +349,16 @@ class OpenAIMonitor {
|
|
|
352
349
|
output: nonStreamedResponse.choices[0].text,
|
|
353
350
|
timestamp: startTime,
|
|
354
351
|
tokens: (_o = (_m = nonStreamedResponse.usage) === null || _m === void 0 ? void 0 : _m.total_tokens) !== null && _o !== void 0 ? _o : 0,
|
|
355
|
-
}, this.openlayerDefaultDataConfig);
|
|
352
|
+
}, this.openlayerDefaultDataConfig, this.openlayerProjectName, this.openlayerInferencePipelineName);
|
|
356
353
|
}
|
|
357
354
|
return response;
|
|
358
355
|
});
|
|
356
|
+
this.openlayerProjectName = openlayerProjectName;
|
|
357
|
+
if (openlayerInferencePipelineName) {
|
|
358
|
+
this.openlayerInferencePipelineName = openlayerInferencePipelineName;
|
|
359
|
+
}
|
|
359
360
|
this.openlayerClient = new OpenlayerClient({
|
|
360
361
|
openlayerApiKey,
|
|
361
|
-
openlayerInferencePipelineName,
|
|
362
|
-
openlayerProjectName,
|
|
363
362
|
openlayerServerUrl,
|
|
364
363
|
});
|
|
365
364
|
this.openAIClient = new openai_1.default({
|