openlayer 0.1.11 → 0.1.12
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 +45 -66
- package/dist/index.js +45 -33
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28,39 +28,6 @@ export interface ChatCompletionData {
|
|
|
28
28
|
*/
|
|
29
29
|
tokens?: number;
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Configuration settings for uploading chat completion data to Openlayer.
|
|
33
|
-
*/
|
|
34
|
-
export interface ChatCompletionConfig {
|
|
35
|
-
/**
|
|
36
|
-
* The name of the column that stores the ground truth data. Can be null.
|
|
37
|
-
*/
|
|
38
|
-
groundTruthColumnName: string | null;
|
|
39
|
-
/**
|
|
40
|
-
* The name of the column that stores inference IDs. Can be null.
|
|
41
|
-
*/
|
|
42
|
-
inferenceIdColumnName: string | null;
|
|
43
|
-
/**
|
|
44
|
-
* An array of names for input variable columns. Can be null.
|
|
45
|
-
*/
|
|
46
|
-
inputVariableNames: string[] | null;
|
|
47
|
-
/**
|
|
48
|
-
* The name of the column that stores latency data. Can be null.
|
|
49
|
-
*/
|
|
50
|
-
latencyColumnName: string | null;
|
|
51
|
-
/**
|
|
52
|
-
* The name of the column that stores the number of tokens. Can be null.
|
|
53
|
-
*/
|
|
54
|
-
numOfTokenColumnName: string | null;
|
|
55
|
-
/**
|
|
56
|
-
* The name of the column that stores output data. Can be null.
|
|
57
|
-
*/
|
|
58
|
-
outputColumnName: string | null;
|
|
59
|
-
/**
|
|
60
|
-
* The name of the column that stores timestamp data. Can be null.
|
|
61
|
-
*/
|
|
62
|
-
timestampColumnName: string | null;
|
|
63
|
-
}
|
|
64
31
|
type OpenlayerClientConstructorProps = {
|
|
65
32
|
openlayerApiKey?: string;
|
|
66
33
|
openlayerInferencePipelineName?: string;
|
|
@@ -132,42 +99,52 @@ export declare class OpenlayerClient {
|
|
|
132
99
|
private openlayerDefaultDataConfig;
|
|
133
100
|
private openlayerServerUrl;
|
|
134
101
|
private version;
|
|
102
|
+
/**
|
|
103
|
+
* Constructs an OpenlayerClient instance.
|
|
104
|
+
* @param {OpenlayerClientConstructorProps} props - The config for the Openlayer client. The API key is required.
|
|
105
|
+
* @throws {Error} Throws an error if the Openlayer API key is not provided.
|
|
106
|
+
*/
|
|
135
107
|
constructor({ openlayerApiKey, openlayerServerUrl, }: OpenlayerClientConstructorProps);
|
|
136
108
|
private resolvedQuery;
|
|
137
109
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @param
|
|
141
|
-
* @
|
|
142
|
-
* @throws Throws an error if Openlayer API key or
|
|
143
|
-
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
110
|
+
* Streams data to the Openlayer inference pipeline.
|
|
111
|
+
* @param {ChatCompletionData} data - The chat completion data to be streamed.
|
|
112
|
+
* @param {string} inferencePipelineId - The ID of the Openlayer inference pipeline to which data is streamed.
|
|
113
|
+
* @returns {Promise<void>} A promise that resolves when the data has been successfully streamed.
|
|
114
|
+
* @throws {Error} Throws an error if the Openlayer API key is not set or an error occurs in the streaming process.
|
|
144
115
|
*/
|
|
145
116
|
streamData: (data: ChatCompletionData, inferencePipelineId: string) => Promise<void>;
|
|
146
117
|
/**
|
|
147
|
-
* Creates a new inference pipeline in Openlayer
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
150
|
-
* @
|
|
151
|
-
* @
|
|
118
|
+
* Creates a new inference pipeline in Openlayer or loads an existing one.
|
|
119
|
+
* @param {string} projectId - The ID of the project containing the inference pipeline.
|
|
120
|
+
* @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
|
|
121
|
+
* @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
|
|
122
|
+
* @throws {Error} Throws an error if the inference pipeline cannot be created or found.
|
|
152
123
|
*/
|
|
153
124
|
createInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
|
|
154
125
|
/**
|
|
155
|
-
* Creates a new project in Openlayer
|
|
156
|
-
* @param name The name of the project.
|
|
157
|
-
* @param taskType The type of task associated with the project.
|
|
158
|
-
* @param description Optional description of the project.
|
|
159
|
-
* @
|
|
160
|
-
* @
|
|
126
|
+
* Creates a new project in Openlayer or loads an existing one.
|
|
127
|
+
* @param {string} name - The name of the project.
|
|
128
|
+
* @param {OpenlayerTaskType} taskType - The type of task associated with the project.
|
|
129
|
+
* @param {string} [description] - Optional description of the project.
|
|
130
|
+
* @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
|
|
131
|
+
* @throws {Error} Throws an error if the project cannot be created or found.
|
|
161
132
|
*/
|
|
162
133
|
createProject: (name: string, taskType: OpenlayerTaskType, description?: string) => Promise<OpenlayerProject>;
|
|
163
134
|
/**
|
|
164
135
|
* Loads an existing inference pipeline from Openlayer based on its name and project ID.
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
167
|
-
* @
|
|
168
|
-
* @
|
|
136
|
+
* @param {string} projectId - The ID of the project containing the inference pipeline.
|
|
137
|
+
* @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
|
|
138
|
+
* @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
|
|
139
|
+
* @throws {Error} Throws an error if the inference pipeline is not found.
|
|
169
140
|
*/
|
|
170
141
|
loadInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
|
|
142
|
+
/**
|
|
143
|
+
* Loads an existing project from Openlayer based on its name.
|
|
144
|
+
* @param {string} name - The name of the project.
|
|
145
|
+
* @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
|
|
146
|
+
* @throws {Error} Throws an error if the project is not found.
|
|
147
|
+
*/
|
|
171
148
|
loadProject: (name: string) => Promise<OpenlayerProject>;
|
|
172
149
|
}
|
|
173
150
|
export declare class OpenAIMonitor {
|
|
@@ -176,24 +153,26 @@ export declare class OpenAIMonitor {
|
|
|
176
153
|
private openlayerProjectName;
|
|
177
154
|
private openlayerInferencePipelineName;
|
|
178
155
|
private monitoringOn;
|
|
156
|
+
/**
|
|
157
|
+
* Constructs an OpenAIMonitor instance.
|
|
158
|
+
* @param {OpenAIMonitorConstructorProps} props - The configuration properties for the OpenAI and Openlayer clients.
|
|
159
|
+
*/
|
|
179
160
|
constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineName, openlayerServerUrl, }: OpenAIMonitorConstructorProps);
|
|
180
161
|
private formatChatCompletionInput;
|
|
181
162
|
/**
|
|
182
|
-
* Creates a
|
|
183
|
-
*
|
|
184
|
-
* @param
|
|
185
|
-
* @
|
|
186
|
-
* @throws Throws an error if monitoring is not active or if
|
|
187
|
-
* @returns A promise that resolves to a ChatCompletion or a Stream of ChatCompletionChunks.
|
|
163
|
+
* Creates a chat completion using the OpenAI client and streams the result to Openlayer.
|
|
164
|
+
* @param {ChatCompletionCreateParams} body - The parameters for creating a chat completion.
|
|
165
|
+
* @param {RequestOptions} [options] - Optional request options.
|
|
166
|
+
* @returns {Promise<ChatCompletion | Stream<ChatCompletionChunk>>} Promise of a ChatCompletion or a Stream
|
|
167
|
+
* @throws {Error} Throws an error if monitoring is not active or if no output is received from OpenAI.
|
|
188
168
|
*/
|
|
189
169
|
createChatCompletion: (body: ChatCompletionCreateParams, options?: RequestOptions) => Promise<ChatCompletion | Stream<ChatCompletionChunk>>;
|
|
190
170
|
/**
|
|
191
|
-
* Creates a
|
|
192
|
-
*
|
|
193
|
-
* @param
|
|
194
|
-
* @
|
|
195
|
-
* @throws Throws an error if monitoring is not active or if no prompt is provided.
|
|
196
|
-
* @returns A promise that resolves to a Completion or a Stream of Completions.
|
|
171
|
+
* Creates a completion using the OpenAI client and streams the result to Openlayer.
|
|
172
|
+
* @param {CompletionCreateParams} body - The parameters for creating a completion.
|
|
173
|
+
* @param {RequestOptions} [options] - Optional request options.
|
|
174
|
+
* @returns {Promise<Completion | Stream<Completion>>} Promise that resolves to a Completion or a Stream.
|
|
175
|
+
* @throws {Error} Throws an error if monitoring is not active or if no prompt is provided.
|
|
197
176
|
*/
|
|
198
177
|
createCompletion: (body: CompletionCreateParams, options?: RequestOptions) => Promise<Completion | Stream<Completion>>;
|
|
199
178
|
/**
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,11 @@ 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
|
+
/**
|
|
25
|
+
* Constructs an OpenlayerClient instance.
|
|
26
|
+
* @param {OpenlayerClientConstructorProps} props - The config for the Openlayer client. The API key is required.
|
|
27
|
+
* @throws {Error} Throws an error if the Openlayer API key is not provided.
|
|
28
|
+
*/
|
|
24
29
|
constructor({ openlayerApiKey, openlayerServerUrl, }) {
|
|
25
30
|
this.openlayerDefaultDataConfig = {
|
|
26
31
|
groundTruthColumnName: null,
|
|
@@ -35,12 +40,11 @@ class OpenlayerClient {
|
|
|
35
40
|
this.version = '0.1.0a16';
|
|
36
41
|
this.resolvedQuery = (endpoint, args = {}) => (0, request_1.resolvedQuery)(this.openlayerServerUrl, endpoint, args);
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param
|
|
41
|
-
* @
|
|
42
|
-
* @throws Throws an error if Openlayer API key or
|
|
43
|
-
* @returns A promise that resolves when the data has been successfully uploaded.
|
|
43
|
+
* Streams data to the Openlayer inference pipeline.
|
|
44
|
+
* @param {ChatCompletionData} data - The chat completion data to be streamed.
|
|
45
|
+
* @param {string} inferencePipelineId - The ID of the Openlayer inference pipeline to which data is streamed.
|
|
46
|
+
* @returns {Promise<void>} A promise that resolves when the data has been successfully streamed.
|
|
47
|
+
* @throws {Error} Throws an error if the Openlayer API key is not set or an error occurs in the streaming process.
|
|
44
48
|
*/
|
|
45
49
|
this.streamData = (data, inferencePipelineId) => __awaiter(this, void 0, void 0, function* () {
|
|
46
50
|
var _a;
|
|
@@ -75,11 +79,11 @@ class OpenlayerClient {
|
|
|
75
79
|
}
|
|
76
80
|
});
|
|
77
81
|
/**
|
|
78
|
-
* Creates a new inference pipeline in Openlayer
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
81
|
-
* @
|
|
82
|
-
* @
|
|
82
|
+
* Creates a new inference pipeline in Openlayer or loads an existing one.
|
|
83
|
+
* @param {string} projectId - The ID of the project containing the inference pipeline.
|
|
84
|
+
* @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
|
|
85
|
+
* @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
|
|
86
|
+
* @throws {Error} Throws an error if the inference pipeline cannot be created or found.
|
|
83
87
|
*/
|
|
84
88
|
this.createInferencePipeline = (projectId, name = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
85
89
|
try {
|
|
@@ -107,12 +111,12 @@ class OpenlayerClient {
|
|
|
107
111
|
}
|
|
108
112
|
});
|
|
109
113
|
/**
|
|
110
|
-
* Creates a new project in Openlayer
|
|
111
|
-
* @param name The name of the project.
|
|
112
|
-
* @param taskType The type of task associated with the project.
|
|
113
|
-
* @param description Optional description of the project.
|
|
114
|
-
* @
|
|
115
|
-
* @
|
|
114
|
+
* Creates a new project in Openlayer or loads an existing one.
|
|
115
|
+
* @param {string} name - The name of the project.
|
|
116
|
+
* @param {OpenlayerTaskType} taskType - The type of task associated with the project.
|
|
117
|
+
* @param {string} [description] - Optional description of the project.
|
|
118
|
+
* @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
|
|
119
|
+
* @throws {Error} Throws an error if the project cannot be created or found.
|
|
116
120
|
*/
|
|
117
121
|
this.createProject = (name, taskType, description) => __awaiter(this, void 0, void 0, function* () {
|
|
118
122
|
try {
|
|
@@ -146,10 +150,10 @@ class OpenlayerClient {
|
|
|
146
150
|
});
|
|
147
151
|
/**
|
|
148
152
|
* Loads an existing inference pipeline from Openlayer based on its name and project ID.
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @
|
|
152
|
-
* @
|
|
153
|
+
* @param {string} projectId - The ID of the project containing the inference pipeline.
|
|
154
|
+
* @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
|
|
155
|
+
* @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
|
|
156
|
+
* @throws {Error} Throws an error if the inference pipeline is not found.
|
|
153
157
|
*/
|
|
154
158
|
this.loadInferencePipeline = (projectId, name = 'production') => __awaiter(this, void 0, void 0, function* () {
|
|
155
159
|
const inferencePipelineEndpoint = `/projects/${projectId}/inference-pipelines`;
|
|
@@ -174,6 +178,12 @@ class OpenlayerClient {
|
|
|
174
178
|
}
|
|
175
179
|
return inferencePipeline;
|
|
176
180
|
});
|
|
181
|
+
/**
|
|
182
|
+
* Loads an existing project from Openlayer based on its name.
|
|
183
|
+
* @param {string} name - The name of the project.
|
|
184
|
+
* @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
|
|
185
|
+
* @throws {Error} Throws an error if the project is not found.
|
|
186
|
+
*/
|
|
177
187
|
this.loadProject = (name) => __awaiter(this, void 0, void 0, function* () {
|
|
178
188
|
const projectsEndpoint = '/projects';
|
|
179
189
|
const projectsQueryParameters = {
|
|
@@ -209,6 +219,10 @@ class OpenlayerClient {
|
|
|
209
219
|
}
|
|
210
220
|
exports.OpenlayerClient = OpenlayerClient;
|
|
211
221
|
class OpenAIMonitor {
|
|
222
|
+
/**
|
|
223
|
+
* Constructs an OpenAIMonitor instance.
|
|
224
|
+
* @param {OpenAIMonitorConstructorProps} props - The configuration properties for the OpenAI and Openlayer clients.
|
|
225
|
+
*/
|
|
212
226
|
constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineName, openlayerServerUrl, }) {
|
|
213
227
|
this.openlayerInferencePipelineName = 'production';
|
|
214
228
|
this.monitoringOn = false;
|
|
@@ -218,12 +232,11 @@ class OpenAIMonitor {
|
|
|
218
232
|
.join('\n')
|
|
219
233
|
.trim();
|
|
220
234
|
/**
|
|
221
|
-
* Creates a
|
|
222
|
-
*
|
|
223
|
-
* @param
|
|
224
|
-
* @
|
|
225
|
-
* @throws Throws an error if monitoring is not active or if
|
|
226
|
-
* @returns A promise that resolves to a ChatCompletion or a Stream of ChatCompletionChunks.
|
|
235
|
+
* Creates a chat completion using the OpenAI client and streams the result to Openlayer.
|
|
236
|
+
* @param {ChatCompletionCreateParams} body - The parameters for creating a chat completion.
|
|
237
|
+
* @param {RequestOptions} [options] - Optional request options.
|
|
238
|
+
* @returns {Promise<ChatCompletion | Stream<ChatCompletionChunk>>} Promise of a ChatCompletion or a Stream
|
|
239
|
+
* @throws {Error} Throws an error if monitoring is not active or if no output is received from OpenAI.
|
|
227
240
|
*/
|
|
228
241
|
this.createChatCompletion = (body, options) => __awaiter(this, void 0, void 0, function* () {
|
|
229
242
|
var _a, e_1, _b, _c;
|
|
@@ -285,12 +298,11 @@ class OpenAIMonitor {
|
|
|
285
298
|
return response;
|
|
286
299
|
});
|
|
287
300
|
/**
|
|
288
|
-
* Creates a
|
|
289
|
-
*
|
|
290
|
-
* @param
|
|
291
|
-
* @
|
|
292
|
-
* @throws Throws an error if monitoring is not active or if no prompt is provided.
|
|
293
|
-
* @returns A promise that resolves to a Completion or a Stream of Completions.
|
|
301
|
+
* Creates a completion using the OpenAI client and streams the result to Openlayer.
|
|
302
|
+
* @param {CompletionCreateParams} body - The parameters for creating a completion.
|
|
303
|
+
* @param {RequestOptions} [options] - Optional request options.
|
|
304
|
+
* @returns {Promise<Completion | Stream<Completion>>} Promise that resolves to a Completion or a Stream.
|
|
305
|
+
* @throws {Error} Throws an error if monitoring is not active or if no prompt is provided.
|
|
294
306
|
*/
|
|
295
307
|
this.createCompletion = (body, options) => __awaiter(this, void 0, void 0, function* () {
|
|
296
308
|
var _g, e_2, _h, _j;
|