openlayer 0.0.1-alpha.0 → 0.0.1-alpha.1

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.
Files changed (43) hide show
  1. package/README.md +10 -6
  2. package/_shims/web-runtime.js +1 -1
  3. package/_shims/web-runtime.js.map +1 -1
  4. package/_shims/web-runtime.mjs +1 -1
  5. package/_shims/web-runtime.mjs.map +1 -1
  6. package/lib/core/cli.d.ts +15 -1
  7. package/lib/core/cli.d.ts.map +1 -1
  8. package/lib/core/cli.js +3 -4
  9. package/lib/core/cli.js.map +1 -1
  10. package/lib/core/cli.mjs +4 -3
  11. package/lib/core/cli.mjs.map +1 -1
  12. package/lib/core/openai-monitor.d.ts +54 -0
  13. package/lib/core/openai-monitor.d.ts.map +1 -0
  14. package/lib/core/openai-monitor.js +376 -0
  15. package/lib/core/openai-monitor.js.map +1 -0
  16. package/lib/core/openai-monitor.mjs +371 -0
  17. package/lib/core/openai-monitor.mjs.map +1 -0
  18. package/package.json +2 -2
  19. package/src/_shims/web-runtime.ts +1 -1
  20. package/src/lib/core/cli.ts +21 -5
  21. package/src/lib/core/index.d.ts +2 -0
  22. package/src/lib/core/openai-monitor.ts +470 -0
  23. package/src/lib/index.d.ts +1 -0
  24. package/src/version.ts +1 -1
  25. package/version.d.ts +1 -1
  26. package/version.js +1 -1
  27. package/version.js.map +1 -1
  28. package/version.mjs +1 -1
  29. package/version.mjs.map +1 -1
  30. package/lib/core/index.d.ts +0 -237
  31. package/lib/core/index.d.ts.map +0 -1
  32. package/lib/core/index.js +0 -635
  33. package/lib/core/index.js.map +0 -1
  34. package/lib/core/index.mjs +0 -627
  35. package/lib/core/index.mjs.map +0 -1
  36. package/lib/core/run.d.ts +0 -14
  37. package/lib/core/run.d.ts.map +0 -1
  38. package/lib/core/run.js +0 -3
  39. package/lib/core/run.js.map +0 -1
  40. package/lib/core/run.mjs +0 -2
  41. package/lib/core/run.mjs.map +0 -1
  42. package/src/lib/core/index.ts +0 -1067
  43. package/src/lib/core/run.ts +0 -14
@@ -1,237 +0,0 @@
1
- import { RequestOptions } from 'openai/core';
2
- import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, ChatCompletionMessageParam, Completion, CompletionCreateParams } from 'openai/resources';
3
- import { Run } from 'openai/resources/beta/threads/runs/runs';
4
- import { Stream } from 'openai/streaming';
5
- /**
6
- * Represents the data structure for a chat completion.
7
- * Object keys represent a column name and the values represent the column value.
8
- */
9
- export interface StreamingData {
10
- [columnName: string]: any;
11
- /**
12
- * The total estimated cost of the chat completion in USD. Optional.
13
- */
14
- cost?: number | undefined;
15
- /**
16
- * The latency of the chat completion in milliseconds. Optional.
17
- */
18
- latency?: number | undefined;
19
- /**
20
- * The output string generated by the chat completion.
21
- */
22
- output: string;
23
- /**
24
- * A timestamp representing when the chat completion occurred. Optional.
25
- */
26
- timestamp?: number | undefined;
27
- /**
28
- * The number of tokens used in the chat completion. Optional.
29
- */
30
- tokens?: number | undefined;
31
- }
32
- /**
33
- * Configuration settings for uploading chat completion data to Openlayer.
34
- */
35
- interface StreamingDataConfig {
36
- /**
37
- * The name of the column that stores the request cost data. Can be null.
38
- */
39
- costColumnName: string | null;
40
- /**
41
- * The name of the column that stores the ground truth data. Can be null.
42
- */
43
- groundTruthColumnName: string | null;
44
- /**
45
- * The name of the column that stores inference IDs. Can be null.
46
- */
47
- inferenceIdColumnName: string | null;
48
- /**
49
- * An array of names for input variable columns. Can be null.
50
- */
51
- inputVariableNames?: string[] | null;
52
- /**
53
- * The name of the column that stores latency data. Can be null.
54
- */
55
- latencyColumnName: string | null;
56
- /**
57
- * The name of the column that stores the number of tokens. Can be null.
58
- */
59
- numOfTokenColumnName: string | null;
60
- /**
61
- * The name of the column that stores output data. Can be null.
62
- */
63
- outputColumnName: string | null;
64
- /**
65
- * The full prompt history for the chat completion.
66
- */
67
- prompt?: ChatCompletionMessageParam[];
68
- /**
69
- * The name of the column that stores timestamp data. Can be null.
70
- */
71
- timestampColumnName: string | null;
72
- }
73
- type OpenlayerClientConstructorProps = {
74
- openlayerApiKey?: string | undefined;
75
- openlayerServerUrl?: string | undefined;
76
- };
77
- type OpenAIMonitorConstructorProps = OpenlayerClientConstructorProps & {
78
- openAiApiKey: string;
79
- openlayerInferencePipelineId?: string;
80
- openlayerInferencePipelineName?: string;
81
- openlayerProjectName?: string;
82
- };
83
- type OpenlayerInferencePipeline = {
84
- dataVolumeGraphs?: OpenlayerSampleVolumeGraph;
85
- dateCreated: string;
86
- dateLastEvaluated?: string;
87
- dateLastSampleReceived?: string;
88
- dateOfNextEvaluation?: string;
89
- dateUpdated: string;
90
- description?: string;
91
- failingGoalCount: number;
92
- id: string;
93
- name: string;
94
- passingGoalCount: number;
95
- projectId: string;
96
- status: OpenlayerInferencePipelineStatus;
97
- statusMessage?: string;
98
- totalGoalCount: number;
99
- };
100
- type OpenlayerInferencePipelineStatus = 'completed' | 'failed' | 'paused' | 'queued' | 'running' | 'unknown';
101
- type OpenlayerProject = {
102
- dateCreated: string;
103
- dateUpdated: string;
104
- description?: string;
105
- developmentGoalCount: number;
106
- goalCount: number;
107
- id: string;
108
- inferencePipelineCount: number;
109
- memberIds: string[];
110
- monitoringGoalCount: number;
111
- name: string;
112
- sample?: boolean;
113
- slackChannelId?: string;
114
- slackChannelName?: string;
115
- slackChannelNotificationsEnabled: boolean;
116
- taskType: OpenlayerTaskType;
117
- unreadNotificationCount: number;
118
- versionCount: number;
119
- };
120
- type OpenlayerSampleVolumeGraphBucket = {
121
- title: string;
122
- xAxis: {
123
- data: string[];
124
- title: string;
125
- };
126
- yAxis: {
127
- data: number[];
128
- title: string;
129
- };
130
- };
131
- type OpenlayerSampleVolumeGraph = {
132
- daily: OpenlayerSampleVolumeGraphBucket;
133
- hourly: OpenlayerSampleVolumeGraphBucket;
134
- monthly: OpenlayerSampleVolumeGraphBucket;
135
- weekly: OpenlayerSampleVolumeGraphBucket;
136
- };
137
- type OpenlayerTaskType = 'llm-base' | 'tabular-classification' | 'tabular-regression' | 'text-classification';
138
- export declare class OpenlayerClient {
139
- private openlayerApiKey?;
140
- defaultConfig: StreamingDataConfig;
141
- private openlayerServerUrl;
142
- private version;
143
- /**
144
- * Constructs an OpenlayerClient instance.
145
- * @param {OpenlayerClientConstructorProps} props - The config for the Openlayer client. The API key is required.
146
- */
147
- constructor({ openlayerApiKey, openlayerServerUrl, }: OpenlayerClientConstructorProps);
148
- private resolvedQuery;
149
- /**
150
- * Creates a new inference pipeline in Openlayer or loads an existing one.
151
- * @param {string} projectId - The ID of the project containing the inference pipeline.
152
- * @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
153
- * @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
154
- * @throws {Error} Throws an error if the inference pipeline cannot be created or found.
155
- */
156
- createInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
157
- /**
158
- * Creates a new project in Openlayer or loads an existing one.
159
- * @param {string} name - The name of the project.
160
- * @param {OpenlayerTaskType} taskType - The type of task associated with the project.
161
- * @param {string} [description] - Optional description of the project.
162
- * @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
163
- * @throws {Error} Throws an error if the project cannot be created or found.
164
- */
165
- createProject: (name: string, taskType: OpenlayerTaskType, description?: string) => Promise<OpenlayerProject>;
166
- /**
167
- * Loads an existing inference pipeline from Openlayer based on its name and project ID.
168
- * @param {string} projectId - The ID of the project containing the inference pipeline.
169
- * @param {string} [name='production'] - The name of the inference pipeline, defaults to 'production'.
170
- * @returns {Promise<OpenlayerInferencePipeline>} A promise that resolves to an OpenlayerInferencePipeline object.
171
- * @throws {Error} Throws an error if the inference pipeline is not found.
172
- */
173
- loadInferencePipeline: (projectId: string, name?: string) => Promise<OpenlayerInferencePipeline>;
174
- /**
175
- * Loads an existing project from Openlayer based on its name.
176
- * @param {string} name - The name of the project.
177
- * @returns {Promise<OpenlayerProject>} A promise that resolves to an OpenlayerProject object.
178
- * @throws {Error} Throws an error if the project is not found.
179
- */
180
- loadProject: (name: string) => Promise<OpenlayerProject>;
181
- /**
182
- * Streams data to the Openlayer inference pipeline.
183
- * @param {StreamingData} data - The chat completion data to be streamed.
184
- * @param {string} inferencePipelineId - The ID of the Openlayer inference pipeline to which data is streamed.
185
- * @returns {Promise<void>} A promise that resolves when the data has been successfully streamed.
186
- */
187
- streamData: (data: StreamingData, config: StreamingDataConfig, inferencePipelineId: string) => Promise<void>;
188
- }
189
- export declare class OpenAIMonitor {
190
- private openlayerClient;
191
- private openAIClient;
192
- private openlayerProjectName?;
193
- private openlayerInferencePipelineId?;
194
- private openlayerInferencePipelineName;
195
- /**
196
- * Constructs an OpenAIMonitor instance.
197
- * @param {OpenAIMonitorConstructorProps} props - The configuration properties for the OpenAI and Openlayer clients.
198
- */
199
- constructor({ openAiApiKey, openlayerApiKey, openlayerProjectName, openlayerInferencePipelineId, openlayerInferencePipelineName, openlayerServerUrl, }: OpenAIMonitorConstructorProps);
200
- private cost;
201
- private chatCompletionPrompt;
202
- private threadPrompt;
203
- private inputVariables;
204
- /**
205
- * Creates a chat completion using the OpenAI client and streams the result to Openlayer.
206
- * @param {ChatCompletionCreateParams} body - The parameters for creating a chat completion.
207
- * @param {RequestOptions} [options] - Optional request options.
208
- * @param {StreamingData} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
209
- * @returns {Promise<ChatCompletion | Stream<ChatCompletionChunk>>} Promise of a ChatCompletion or a Stream
210
- * @throws {Error} Throws errors from the OpenAI client.
211
- */
212
- createChatCompletion: (body: ChatCompletionCreateParams, options?: RequestOptions, additionalLogs?: StreamingData) => Promise<ChatCompletion | Stream<ChatCompletionChunk>>;
213
- /**
214
- * Creates a completion using the OpenAI client and streams the result to Openlayer.
215
- * @param {CompletionCreateParams} body - The parameters for creating a completion.
216
- * @param {RequestOptions} [options] - Optional request options.
217
- * @param {StreamingData} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
218
- * @returns {Promise<Completion | Stream<Completion>>} Promise that resolves to a Completion or a Stream.
219
- * @throws {Error} Throws errors from the OpenAI client.
220
- */
221
- createCompletion: (body: CompletionCreateParams, options?: RequestOptions, additionalLogs?: StreamingData) => Promise<Completion | Stream<Completion>>;
222
- /**
223
- * Monitor a run from an OpenAI assistant.
224
- * Once the run is completed, the thread data is published to Openlayer,
225
- * along with the latency, cost, and number of tokens used.
226
- * @param {Run} run - The run created by the OpenAI assistant.
227
- * @param {StreamingData} [additionalLogs] - Optional metadata logs to include with the request sent to Openlayer.
228
- * @returns {Promise<void>} A promise that resolves when the run data has been successfully published to Openlayer.
229
- */
230
- monitorThreadRun(run: Run, additionalLogs?: StreamingData): Promise<void>;
231
- /**
232
- * Starts monitoring for the OpenAI Monitor instance. If monitoring is already active, a warning is logged.
233
- */
234
- initialize(): Promise<void>;
235
- }
236
- export {};
237
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/core/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC1B,UAAU,EACV,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,yCAAyC,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAgD1C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC;IAE1B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B;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