openlayer 0.1.31 → 0.1.33

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.js CHANGED
@@ -17,6 +17,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.OpenAIMonitor = exports.OpenlayerClient = void 0;
20
+ const node_fetch_1 = require("node-fetch");
20
21
  const openai_1 = require("openai");
21
22
  const uuid_1 = require("uuid");
22
23
  const request_1 = require("./utils/request");
@@ -126,7 +127,7 @@ class OpenlayerClient {
126
127
  catch (_a) { }
127
128
  const createInferencePipelineEndpoint = `/projects/${projectId}/inference-pipelines`;
128
129
  const createInferencePipelineQuery = this.resolvedQuery(createInferencePipelineEndpoint, { version: this.version });
129
- const createInferencePipelineResponse = yield fetch(createInferencePipelineQuery, {
130
+ const createInferencePipelineResponse = yield (0, node_fetch_1.default)(createInferencePipelineQuery, {
130
131
  body: JSON.stringify({
131
132
  description: '',
132
133
  name,
@@ -137,7 +138,7 @@ class OpenlayerClient {
137
138
  },
138
139
  method: 'POST',
139
140
  });
140
- const inferencePipeline = yield createInferencePipelineResponse.json();
141
+ const inferencePipeline = (yield createInferencePipelineResponse.json());
141
142
  if (!(inferencePipeline === null || inferencePipeline === void 0 ? void 0 : inferencePipeline.id)) {
142
143
  throw new Error('Error creating inference pipeline');
143
144
  }
@@ -158,7 +159,7 @@ class OpenlayerClient {
158
159
  catch (_b) { }
159
160
  const projectsEndpoint = '/projects';
160
161
  const projectsQuery = this.resolvedQuery(projectsEndpoint);
161
- const response = yield fetch(projectsQuery, {
162
+ const response = yield (0, node_fetch_1.default)(projectsQuery, {
162
163
  body: JSON.stringify({
163
164
  description,
164
165
  name,
@@ -170,7 +171,7 @@ class OpenlayerClient {
170
171
  },
171
172
  method: 'POST',
172
173
  });
173
- const data = yield response.json();
174
+ const data = (yield response.json());
174
175
  const { items: projects, error } = data;
175
176
  if (!Array.isArray(projects)) {
176
177
  throw new Error(typeof error === 'string' ? error : 'Invalid response from Openlayer');
@@ -195,14 +196,14 @@ class OpenlayerClient {
195
196
  version: this.version,
196
197
  };
197
198
  const inferencePipelineQuery = this.resolvedQuery(inferencePipelineEndpoint, inferencePipelineQueryParameters);
198
- const inferencePipelineResponse = yield fetch(inferencePipelineQuery, {
199
+ const inferencePipelineResponse = yield (0, node_fetch_1.default)(inferencePipelineQuery, {
199
200
  headers: {
200
201
  Authorization: `Bearer ${this.openlayerApiKey}`,
201
202
  'Content-Type': 'application/json',
202
203
  },
203
204
  method: 'GET',
204
205
  });
205
- const { items: inferencePipelines, error } = yield inferencePipelineResponse.json();
206
+ const { items: inferencePipelines, error } = (yield inferencePipelineResponse.json());
206
207
  const inferencePipeline = Array.isArray(inferencePipelines)
207
208
  ? inferencePipelines.find((p) => p.name === name)
208
209
  : undefined;
@@ -224,7 +225,7 @@ class OpenlayerClient {
224
225
  version: this.version,
225
226
  };
226
227
  const projectsQuery = this.resolvedQuery(projectsEndpoint, projectsQueryParameters);
227
- const response = yield fetch(projectsQuery, {
228
+ const response = yield (0, node_fetch_1.default)(projectsQuery, {
228
229
  headers: {
229
230
  Authorization: `Bearer ${this.openlayerApiKey}`,
230
231
  'Content-Type': 'application/json',
@@ -257,7 +258,7 @@ class OpenlayerClient {
257
258
  try {
258
259
  const dataStreamEndpoint = `/inference-pipelines/${inferencePipelineId}/data-stream`;
259
260
  const dataStreamQuery = this.resolvedQuery(dataStreamEndpoint);
260
- const response = yield fetch(dataStreamQuery, {
261
+ const response = yield (0, node_fetch_1.default)(dataStreamQuery, {
261
262
  body: JSON.stringify({
262
263
  config,
263
264
  rows: [
@@ -563,8 +564,8 @@ class OpenAIMonitor {
563
564
  : typeof output === 'undefined' || output === null
564
565
  ? ''
565
566
  : `${output}`;
566
- this.openlayerClient.streamData(Object.assign(Object.assign({ 'OpenAI Assistant ID': assistant_id, 'OpenAI Thread ID': thread_id, cost,
567
- latency, output: resolvedOutput, timestamp: run.created_at, tokens: total_tokens }, inputVariablesMap), additionalLogs), config, this.openlayerInferencePipelineId);
567
+ this.openlayerClient.streamData(Object.assign(Object.assign({ cost,
568
+ latency, openai_assistant_id: assistant_id, openai_thread_id: thread_id, output: resolvedOutput, timestamp: run.created_at, tokens: total_tokens }, inputVariablesMap), additionalLogs), config, this.openlayerInferencePipelineId);
568
569
  }
569
570
  catch (error) {
570
571
  console.error('Error logging thread run:', error);
@@ -6,19 +6,18 @@ import OpenAI from 'openai';
6
6
  import { OpenAIMonitor } from 'openlayer';
7
7
 
8
8
  const openai = new OpenAI({
9
- apiKey: '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',
9
+ apiKey: 'YOUR_OPENAI_API_KEY',
10
10
  });
11
11
 
12
12
  // Create monitor with your credentials
13
13
  const monitor = new OpenAIMonitor({
14
- openAiApiKey: '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',
15
- openlayerApiKey: 'UyKge0qbzrnAg_vehsTtw_e_mArrHHyT',
14
+ openAiApiKey: 'YOUR_OPENAI_API_KEY',
15
+ openlayerApiKey: 'YOUR_OPENLAYER_API_KEY',
16
16
  // EITHER specify an existing inference pipeline ID
17
- openlayerInferencePipelineId: 'ef604fd7-2237-419f-90a0-4a456020ecbb',
17
+ openlayerInferencePipelineId: 'YOUR_OPENLAYER_INFERENCE_PIPELINE_ID',
18
18
  // OR the project and inference pipeline names to create or load one
19
- // openlayerInferencePipelineName: 'production',
20
- // openlayerProjectName: 'Python QA5',
21
- openlayerServerUrl: 'http://localhost:8080/v1',
19
+ openlayerInferencePipelineName: 'production',
20
+ openlayerProjectName: 'YOUR_OPENLAYER_PROJECT_NAME',
22
21
  });
23
22
 
24
23
  await monitor.initialize();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openlayer",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "The Openlayer TypeScript client",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,6 @@
20
20
  "eslint-plugin-typescript-sort-keys": "^3.1.0",
21
21
  "node-fetch": "^3.3.2",
22
22
  "openai": "^4.19.0",
23
- "openlayer": "^0.1.30",
24
23
  "uuid": "^9.0.1"
25
24
  },
26
25
  "devDependencies": {