Comparing version 0.1.0 to 0.1.1
@@ -78,3 +78,3 @@ /** | ||
*/ | ||
'startTime': number; | ||
'requestedAt': number; | ||
/** | ||
@@ -106,3 +106,3 @@ * JSON-encoded request payload | ||
*/ | ||
'startTime': number; | ||
'requestedAt': number; | ||
/** | ||
@@ -113,3 +113,3 @@ * Unix timestamp in milliseconds | ||
*/ | ||
'endTime': number; | ||
'receivedAt': number; | ||
/** | ||
@@ -132,3 +132,3 @@ * JSON-encoded request payload | ||
*/ | ||
'respStatus'?: number; | ||
'statusCode'?: number; | ||
/** | ||
@@ -139,3 +139,3 @@ * User-friendly error message | ||
*/ | ||
'error'?: string; | ||
'errorMessage'?: string; | ||
/** | ||
@@ -142,0 +142,0 @@ * Extra tags to attach to the call for filtering. Eg { \"userId\": \"123\", \"promptId\": \"populate-title\" } |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* tslint:disable */ | ||
@@ -15,19 +14,8 @@ /* eslint-disable */ | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DefaultApi = exports.DefaultApiFactory = exports.DefaultApiFp = exports.DefaultApiAxiosParamCreator = void 0; | ||
const axios_1 = require("axios"); | ||
import globalAxios from 'axios'; | ||
// Some imports not used depending on template conditions | ||
// @ts-ignore | ||
const common_1 = require("./common"); | ||
import { DUMMY_BASE_URL, assertParamExists, setBearerAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common'; | ||
// @ts-ignore | ||
const base_1 = require("./base"); | ||
import { BASE_PATH, BaseAPI } from './base'; | ||
/** | ||
@@ -37,3 +25,3 @@ * DefaultApi - axios parameter creator | ||
*/ | ||
const DefaultApiAxiosParamCreator = function (configuration) { | ||
export const DefaultApiAxiosParamCreator = function (configuration) { | ||
return { | ||
@@ -46,8 +34,8 @@ /** | ||
*/ | ||
externalApiCheckCache: (externalApiCheckCacheRequest, options = {}) => __awaiter(this, void 0, void 0, function* () { | ||
externalApiCheckCache: async (externalApiCheckCacheRequest, options = {}) => { | ||
// verify required parameter 'externalApiCheckCacheRequest' is not null or undefined | ||
(0, common_1.assertParamExists)('externalApiCheckCache', 'externalApiCheckCacheRequest', externalApiCheckCacheRequest); | ||
assertParamExists('externalApiCheckCache', 'externalApiCheckCacheRequest', externalApiCheckCacheRequest); | ||
const localVarPath = `/v1/check-cache`; | ||
// use dummy base URL string because the URL constructor only accepts absolute URLs. | ||
const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL); | ||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); | ||
let baseOptions; | ||
@@ -60,12 +48,15 @@ if (configuration) { | ||
const localVarQueryParameter = {}; | ||
// authentication Authorization required | ||
// http bearer authentication required | ||
await setBearerAuthToObject(localVarHeaderParameter, configuration); | ||
localVarHeaderParameter['Content-Type'] = 'application/json'; | ||
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter); | ||
setSearchParams(localVarUrlObj, localVarQueryParameter); | ||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; | ||
localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers); | ||
localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(externalApiCheckCacheRequest, localVarRequestOptions, configuration); | ||
localVarRequestOptions.data = serializeDataIfNeeded(externalApiCheckCacheRequest, localVarRequestOptions, configuration); | ||
return { | ||
url: (0, common_1.toPathString)(localVarUrlObj), | ||
url: toPathString(localVarUrlObj), | ||
options: localVarRequestOptions, | ||
}; | ||
}), | ||
}, | ||
/** | ||
@@ -77,8 +68,8 @@ * Report an API call | ||
*/ | ||
externalApiReport: (externalApiReportRequest, options = {}) => __awaiter(this, void 0, void 0, function* () { | ||
externalApiReport: async (externalApiReportRequest, options = {}) => { | ||
// verify required parameter 'externalApiReportRequest' is not null or undefined | ||
(0, common_1.assertParamExists)('externalApiReport', 'externalApiReportRequest', externalApiReportRequest); | ||
assertParamExists('externalApiReport', 'externalApiReportRequest', externalApiReportRequest); | ||
const localVarPath = `/v1/report`; | ||
// use dummy base URL string because the URL constructor only accepts absolute URLs. | ||
const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL); | ||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); | ||
let baseOptions; | ||
@@ -91,15 +82,17 @@ if (configuration) { | ||
const localVarQueryParameter = {}; | ||
// authentication Authorization required | ||
// http bearer authentication required | ||
await setBearerAuthToObject(localVarHeaderParameter, configuration); | ||
localVarHeaderParameter['Content-Type'] = 'application/json'; | ||
(0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter); | ||
setSearchParams(localVarUrlObj, localVarQueryParameter); | ||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; | ||
localVarRequestOptions.headers = Object.assign(Object.assign(Object.assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers); | ||
localVarRequestOptions.data = (0, common_1.serializeDataIfNeeded)(externalApiReportRequest, localVarRequestOptions, configuration); | ||
localVarRequestOptions.data = serializeDataIfNeeded(externalApiReportRequest, localVarRequestOptions, configuration); | ||
return { | ||
url: (0, common_1.toPathString)(localVarUrlObj), | ||
url: toPathString(localVarUrlObj), | ||
options: localVarRequestOptions, | ||
}; | ||
}), | ||
}, | ||
}; | ||
}; | ||
exports.DefaultApiAxiosParamCreator = DefaultApiAxiosParamCreator; | ||
/** | ||
@@ -109,4 +102,4 @@ * DefaultApi - functional programming interface | ||
*/ | ||
const DefaultApiFp = function (configuration) { | ||
const localVarAxiosParamCreator = (0, exports.DefaultApiAxiosParamCreator)(configuration); | ||
export const DefaultApiFp = function (configuration) { | ||
const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration); | ||
return { | ||
@@ -119,7 +112,5 @@ /** | ||
*/ | ||
externalApiCheckCache(externalApiCheckCacheRequest, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const localVarAxiosArgs = yield localVarAxiosParamCreator.externalApiCheckCache(externalApiCheckCacheRequest, options); | ||
return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration); | ||
}); | ||
async externalApiCheckCache(externalApiCheckCacheRequest, options) { | ||
const localVarAxiosArgs = await localVarAxiosParamCreator.externalApiCheckCache(externalApiCheckCacheRequest, options); | ||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); | ||
}, | ||
@@ -132,11 +123,8 @@ /** | ||
*/ | ||
externalApiReport(externalApiReportRequest, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const localVarAxiosArgs = yield localVarAxiosParamCreator.externalApiReport(externalApiReportRequest, options); | ||
return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration); | ||
}); | ||
async externalApiReport(externalApiReportRequest, options) { | ||
const localVarAxiosArgs = await localVarAxiosParamCreator.externalApiReport(externalApiReportRequest, options); | ||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); | ||
}, | ||
}; | ||
}; | ||
exports.DefaultApiFp = DefaultApiFp; | ||
/** | ||
@@ -146,4 +134,4 @@ * DefaultApi - factory interface | ||
*/ | ||
const DefaultApiFactory = function (configuration, basePath, axios) { | ||
const localVarFp = (0, exports.DefaultApiFp)(configuration); | ||
export const DefaultApiFactory = function (configuration, basePath, axios) { | ||
const localVarFp = DefaultApiFp(configuration); | ||
return { | ||
@@ -170,3 +158,2 @@ /** | ||
}; | ||
exports.DefaultApiFactory = DefaultApiFactory; | ||
/** | ||
@@ -178,3 +165,3 @@ * DefaultApi - object-oriented interface | ||
*/ | ||
class DefaultApi extends base_1.BaseAPI { | ||
export class DefaultApi extends BaseAPI { | ||
/** | ||
@@ -188,3 +175,3 @@ * Check if a prompt is cached | ||
externalApiCheckCache(externalApiCheckCacheRequest, options) { | ||
return (0, exports.DefaultApiFp)(this.configuration).externalApiCheckCache(externalApiCheckCacheRequest, options).then((request) => request(this.axios, this.basePath)); | ||
return DefaultApiFp(this.configuration).externalApiCheckCache(externalApiCheckCacheRequest, options).then((request) => request(this.axios, this.basePath)); | ||
} | ||
@@ -199,5 +186,4 @@ /** | ||
externalApiReport(externalApiReportRequest, options) { | ||
return (0, exports.DefaultApiFp)(this.configuration).externalApiReport(externalApiReportRequest, options).then((request) => request(this.axios, this.basePath)); | ||
return DefaultApiFp(this.configuration).externalApiReport(externalApiReportRequest, options).then((request) => request(this.axios, this.basePath)); | ||
} | ||
} | ||
exports.DefaultApi = DefaultApi; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* tslint:disable */ | ||
@@ -15,6 +14,4 @@ /* eslint-disable */ | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0; | ||
const axios_1 = require("axios"); | ||
exports.BASE_PATH = "https://app.openpipe.ai/api".replace(/\/+$/, ""); | ||
import globalAxios from 'axios'; | ||
export const BASE_PATH = "https://app.openpipe.ai/api".replace(/\/+$/, ""); | ||
/** | ||
@@ -24,3 +21,3 @@ * | ||
*/ | ||
exports.COLLECTION_FORMATS = { | ||
export const COLLECTION_FORMATS = { | ||
csv: ",", | ||
@@ -36,4 +33,4 @@ ssv: " ", | ||
*/ | ||
class BaseAPI { | ||
constructor(configuration, basePath = exports.BASE_PATH, axios = axios_1.default) { | ||
export class BaseAPI { | ||
constructor(configuration, basePath = BASE_PATH, axios = globalAxios) { | ||
this.basePath = basePath; | ||
@@ -47,3 +44,2 @@ this.axios = axios; | ||
} | ||
exports.BaseAPI = BaseAPI; | ||
; | ||
@@ -56,3 +52,3 @@ /** | ||
*/ | ||
class RequiredError extends Error { | ||
export class RequiredError extends Error { | ||
constructor(field, msg) { | ||
@@ -64,2 +60,1 @@ super(msg); | ||
} | ||
exports.RequiredError = RequiredError; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* tslint:disable */ | ||
@@ -15,14 +14,3 @@ /* eslint-disable */ | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRequestFunction = exports.toPathString = exports.serializeDataIfNeeded = exports.setSearchParams = exports.setOAuthToObject = exports.setBearerAuthToObject = exports.setBasicAuthToObject = exports.setApiKeyToObject = exports.assertParamExists = exports.DUMMY_BASE_URL = void 0; | ||
const base_1 = require("./base"); | ||
import { RequiredError } from "./base"; | ||
/** | ||
@@ -32,3 +20,3 @@ * | ||
*/ | ||
exports.DUMMY_BASE_URL = 'https://example.com'; | ||
export const DUMMY_BASE_URL = 'https://example.com'; | ||
/** | ||
@@ -39,8 +27,7 @@ * | ||
*/ | ||
const assertParamExists = function (functionName, paramName, paramValue) { | ||
export const assertParamExists = function (functionName, paramName, paramValue) { | ||
if (paramValue === null || paramValue === undefined) { | ||
throw new base_1.RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); | ||
throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); | ||
} | ||
}; | ||
exports.assertParamExists = assertParamExists; | ||
/** | ||
@@ -50,13 +37,10 @@ * | ||
*/ | ||
const setApiKeyToObject = function (object, keyParamName, configuration) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (configuration && configuration.apiKey) { | ||
const localVarApiKeyValue = typeof configuration.apiKey === 'function' | ||
? yield configuration.apiKey(keyParamName) | ||
: yield configuration.apiKey; | ||
object[keyParamName] = localVarApiKeyValue; | ||
} | ||
}); | ||
export const setApiKeyToObject = async function (object, keyParamName, configuration) { | ||
if (configuration && configuration.apiKey) { | ||
const localVarApiKeyValue = typeof configuration.apiKey === 'function' | ||
? await configuration.apiKey(keyParamName) | ||
: await configuration.apiKey; | ||
object[keyParamName] = localVarApiKeyValue; | ||
} | ||
}; | ||
exports.setApiKeyToObject = setApiKeyToObject; | ||
/** | ||
@@ -66,3 +50,3 @@ * | ||
*/ | ||
const setBasicAuthToObject = function (object, configuration) { | ||
export const setBasicAuthToObject = function (object, configuration) { | ||
if (configuration && (configuration.username || configuration.password)) { | ||
@@ -72,3 +56,2 @@ object["auth"] = { username: configuration.username, password: configuration.password }; | ||
}; | ||
exports.setBasicAuthToObject = setBasicAuthToObject; | ||
/** | ||
@@ -78,13 +61,10 @@ * | ||
*/ | ||
const setBearerAuthToObject = function (object, configuration) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (configuration && configuration.accessToken) { | ||
const accessToken = typeof configuration.accessToken === 'function' | ||
? yield configuration.accessToken() | ||
: yield configuration.accessToken; | ||
object["Authorization"] = "Bearer " + accessToken; | ||
} | ||
}); | ||
export const setBearerAuthToObject = async function (object, configuration) { | ||
if (configuration && configuration.accessToken) { | ||
const accessToken = typeof configuration.accessToken === 'function' | ||
? await configuration.accessToken() | ||
: await configuration.accessToken; | ||
object["Authorization"] = "Bearer " + accessToken; | ||
} | ||
}; | ||
exports.setBearerAuthToObject = setBearerAuthToObject; | ||
/** | ||
@@ -94,13 +74,10 @@ * | ||
*/ | ||
const setOAuthToObject = function (object, name, scopes, configuration) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (configuration && configuration.accessToken) { | ||
const localVarAccessTokenValue = typeof configuration.accessToken === 'function' | ||
? yield configuration.accessToken(name, scopes) | ||
: yield configuration.accessToken; | ||
object["Authorization"] = "Bearer " + localVarAccessTokenValue; | ||
} | ||
}); | ||
export const setOAuthToObject = async function (object, name, scopes, configuration) { | ||
if (configuration && configuration.accessToken) { | ||
const localVarAccessTokenValue = typeof configuration.accessToken === 'function' | ||
? await configuration.accessToken(name, scopes) | ||
: await configuration.accessToken; | ||
object["Authorization"] = "Bearer " + localVarAccessTokenValue; | ||
} | ||
}; | ||
exports.setOAuthToObject = setOAuthToObject; | ||
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") { | ||
@@ -130,3 +107,3 @@ if (parameter == null) | ||
*/ | ||
const setSearchParams = function (url, ...objects) { | ||
export const setSearchParams = function (url, ...objects) { | ||
const searchParams = new URLSearchParams(url.search); | ||
@@ -136,3 +113,2 @@ setFlattenedQueryParams(searchParams, objects); | ||
}; | ||
exports.setSearchParams = setSearchParams; | ||
/** | ||
@@ -142,3 +118,3 @@ * | ||
*/ | ||
const serializeDataIfNeeded = function (value, requestOptions, configuration) { | ||
export const serializeDataIfNeeded = function (value, requestOptions, configuration) { | ||
const nonString = typeof value !== 'string'; | ||
@@ -152,3 +128,2 @@ const needsSerialization = nonString && configuration && configuration.isJsonMime | ||
}; | ||
exports.serializeDataIfNeeded = serializeDataIfNeeded; | ||
/** | ||
@@ -158,6 +133,5 @@ * | ||
*/ | ||
const toPathString = function (url) { | ||
export const toPathString = function (url) { | ||
return url.pathname + url.search + url.hash; | ||
}; | ||
exports.toPathString = toPathString; | ||
/** | ||
@@ -167,3 +141,3 @@ * | ||
*/ | ||
const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) { | ||
export const createRequestFunction = function (axiosArgs, globalAxios, BASE_PATH, configuration) { | ||
return (axios = globalAxios, basePath = BASE_PATH) => { | ||
@@ -174,2 +148,1 @@ const axiosRequestArgs = Object.assign(Object.assign({}, axiosArgs.options), { url: ((configuration === null || configuration === void 0 ? void 0 : configuration.basePath) || basePath) + axiosArgs.url }); | ||
}; | ||
exports.createRequestFunction = createRequestFunction; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* tslint:disable */ | ||
@@ -15,5 +14,3 @@ /* eslint-disable */ | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Configuration = void 0; | ||
class Configuration { | ||
export class Configuration { | ||
constructor(param = {}) { | ||
@@ -43,2 +40,1 @@ this.apiKey = param.apiKey; | ||
} | ||
exports.Configuration = Configuration; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* tslint:disable */ | ||
@@ -15,18 +14,3 @@ /* eslint-disable */ | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./api"), exports); | ||
__exportStar(require("./configuration"), exports); | ||
export * from "./api"; | ||
export * from "./configuration"; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpenAIApi = exports.Configuration = exports.openAILegacy = void 0; | ||
const openPipeClient = require("../codegen"); | ||
const openai = require("openai-legacy"); | ||
const package_json_1 = require("../package.json"); | ||
// Anything we don't override we want to pass through to openai directly | ||
exports.openAILegacy = require("openai-legacy"); | ||
class Configuration extends openai.Configuration { | ||
constructor(config) { | ||
super(config); | ||
if (config.opParameters) { | ||
this.qkConfig = new openPipeClient.Configuration(config.opParameters); | ||
} | ||
} | ||
} | ||
exports.Configuration = Configuration; | ||
class OpenAIApi extends openai.OpenAIApi { | ||
constructor(config) { | ||
super(config); | ||
if (config.qkConfig) { | ||
this.openPipeApi = new openPipeClient.DefaultApi(config.qkConfig); | ||
} | ||
} | ||
createChatCompletion(createChatCompletionRequest, options) { | ||
const _super = Object.create(null, { | ||
createChatCompletion: { get: () => super.createChatCompletion } | ||
}); | ||
var _a, _b, _c, _d, _e, _f; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const startTime = Date.now(); | ||
let resp = null; | ||
let respPayload = null; | ||
let respStatus = undefined; | ||
let error; | ||
try { | ||
resp = yield _super.createChatCompletion.call(this, createChatCompletionRequest, options); | ||
respPayload = resp.data; | ||
respStatus = resp.status; | ||
} | ||
catch (err) { | ||
console.error("Error in createChatCompletion"); | ||
if ("isAxiosError" in err && err.isAxiosError) { | ||
error = (_c = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message; | ||
respPayload = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data; | ||
respStatus = (_e = err.response) === null || _e === void 0 ? void 0 : _e.status; | ||
} | ||
else if ("message" in err) { | ||
error = err.message.toString(); | ||
} | ||
throw err; | ||
} | ||
finally { | ||
(_f = this.openPipeApi) === null || _f === void 0 ? void 0 : _f.externalApiReport({ | ||
startTime, | ||
endTime: Date.now(), | ||
reqPayload: createChatCompletionRequest, | ||
respPayload: respPayload, | ||
respStatus: respStatus, | ||
error, | ||
tags: { | ||
client: "openai-js", | ||
clientVersion: package_json_1.version, | ||
}, | ||
}).catch((err) => { | ||
console.error("Error reporting to QK", err); | ||
}); | ||
} | ||
console.log("done"); | ||
return resp; | ||
}); | ||
} | ||
} | ||
exports.OpenAIApi = OpenAIApi; | ||
// import * as openPipeClient from "../codegen"; | ||
// import * as openai from "openai-legacy"; | ||
// import { version } from "../package.json"; | ||
// // Anything we don't override we want to pass through to openai directly | ||
// export * as openAILegacy from "openai-legacy"; | ||
// type OPConfigurationParameters = { | ||
// apiKey?: string; | ||
// basePath?: string; | ||
// }; | ||
// export class Configuration extends openai.Configuration { | ||
// public qkConfig?: openPipeClient.Configuration; | ||
// constructor( | ||
// config: openai.ConfigurationParameters & { | ||
// opParameters?: OPConfigurationParameters; | ||
// } | ||
// ) { | ||
// super(config); | ||
// if (config.opParameters) { | ||
// this.qkConfig = new openPipeClient.Configuration(config.opParameters); | ||
// } | ||
// } | ||
// } | ||
// type CreateChatCompletion = InstanceType< | ||
// typeof openai.OpenAIApi | ||
// >["createChatCompletion"]; | ||
// export class OpenAIApi extends openai.OpenAIApi { | ||
// public openPipeApi?: openPipeClient.DefaultApi; | ||
// constructor(config: Configuration) { | ||
// super(config); | ||
// if (config.qkConfig) { | ||
// this.openPipeApi = new openPipeClient.DefaultApi(config.qkConfig); | ||
// } | ||
// } | ||
// public async createChatCompletion( | ||
// createChatCompletionRequest: Parameters<CreateChatCompletion>[0], | ||
// options?: Parameters<CreateChatCompletion>[1] | ||
// ): ReturnType<CreateChatCompletion> { | ||
// const requestedAt = Date.now(); | ||
// let resp: Awaited<ReturnType<CreateChatCompletion>> | null = null; | ||
// let respPayload: openai.CreateChatCompletionResponse | null = null; | ||
// let statusCode: number | undefined = undefined; | ||
// let errorMessage: string | undefined; | ||
// try { | ||
// resp = await super.createChatCompletion( | ||
// createChatCompletionRequest, | ||
// options | ||
// ); | ||
// respPayload = resp.data; | ||
// statusCode = resp.status; | ||
// } catch (err) { | ||
// console.error("Error in createChatCompletion"); | ||
// if ("isAxiosError" in err && err.isAxiosError) { | ||
// errorMessage = err.response?.data?.error?.message; | ||
// respPayload = err.response?.data; | ||
// statusCode = err.response?.status; | ||
// } else if ("message" in err) { | ||
// errorMessage = err.message.toString(); | ||
// } | ||
// throw err; | ||
// } finally { | ||
// this.openPipeApi | ||
// ?.externalApiReport({ | ||
// requestedAt, | ||
// receivedAt: Date.now(), | ||
// reqPayload: createChatCompletionRequest, | ||
// respPayload: respPayload, | ||
// statusCode: statusCode, | ||
// errorMessage, | ||
// tags: { | ||
// client: "openai-js", | ||
// clientVersion: version, | ||
// }, | ||
// }) | ||
// .catch((err) => { | ||
// console.error("Error reporting to OP", err); | ||
// }); | ||
// } | ||
// console.log("done"); | ||
// return resp; | ||
// } | ||
// } |
@@ -1,11 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
@@ -22,19 +12,16 @@ var t = {}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpenAI = exports.openai = void 0; | ||
const openai = require("openai-beta"); | ||
const core_1 = require("openai-beta/core"); | ||
const axios_1 = require("axios"); | ||
exports.openai = require("openai-beta"); | ||
const openPipeClient = require("../codegen"); | ||
class OpenAI extends openai.OpenAI { | ||
import * as openai from "openai-beta"; | ||
import { readEnv } from "openai-beta/core"; | ||
import axios from "axios"; | ||
import * as openPipeClient from "../codegen"; | ||
export default class OpenAI extends openai.OpenAI { | ||
constructor(_a) { | ||
var _b; | ||
var _c = _a === void 0 ? {} : _a, { openPipeApiKey = (0, core_1.readEnv)("OPENPIPE_API_KEY"), openPipeBaseUrl = (_b = (0, core_1.readEnv)("OPENPIPE_BASE_URL")) !== null && _b !== void 0 ? _b : `https://app.openpipe.ai/v1` } = _c, opts = __rest(_c, ["openPipeApiKey", "openPipeBaseUrl"]); | ||
var _c = _a === void 0 ? {} : _a, { openPipeApiKey = readEnv("OPENPIPE_API_KEY"), openPipeBaseUrl = (_b = readEnv("OPENPIPE_BASE_URL")) !== null && _b !== void 0 ? _b : `https://app.openpipe.ai/v1` } = _c, opts = __rest(_c, ["openPipeApiKey", "openPipeBaseUrl"]); | ||
super(Object.assign({}, opts)); | ||
if (openPipeApiKey) { | ||
const axiosInstance = axios_1.default.create({ | ||
const axiosInstance = axios.create({ | ||
baseURL: openPipeBaseUrl, | ||
headers: { | ||
'x-openpipe-api-key': openPipeApiKey, | ||
Authorization: `Bearer ${openPipeApiKey}`, | ||
}, | ||
@@ -54,3 +41,2 @@ }); | ||
} | ||
exports.OpenAI = OpenAI; | ||
class ExtendedChat extends openai.OpenAI.Chat { | ||
@@ -68,35 +54,29 @@ constructor(openaiInstance) { | ||
} | ||
create(params, options, tags) { | ||
const _super = Object.create(null, { | ||
create: { get: () => super.create } | ||
}); | ||
async create(params, options, tags) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Your pre API call logic here | ||
console.log("Doing pre API call..."); | ||
// Determine the type of request | ||
if (params.hasOwnProperty("stream") && params.stream === true) { | ||
const result = yield _super.create.call(this, params, options); | ||
// Your post API call logic here | ||
console.log("Doing post API call for Streaming..."); | ||
return result; | ||
} | ||
else { | ||
const startTime = Date.now(); | ||
const result = yield _super.create.call(this, params, options); | ||
yield ((_a = this.openaiInstance.openPipeApi) === null || _a === void 0 ? void 0 : _a.externalApiReport({ | ||
startTime, | ||
endTime: Date.now(), | ||
reqPayload: params, | ||
respPayload: result, | ||
respStatus: 200, | ||
error: undefined, | ||
tags, | ||
})); | ||
// Your post API call logic here | ||
console.log("Doing post API call for NonStreaming..."); | ||
return result; | ||
} | ||
}); | ||
// Your pre API call logic here | ||
console.log("Doing pre API call..."); | ||
// Determine the type of request | ||
if (params.hasOwnProperty("stream") && params.stream === true) { | ||
const result = await super.create(params, options); | ||
// Your post API call logic here | ||
console.log("Doing post API call for Streaming..."); | ||
return result; | ||
} | ||
else { | ||
const requestedAt = Date.now(); | ||
const result = await super.create(params, options); | ||
await ((_a = this.openaiInstance.openPipeApi) === null || _a === void 0 ? void 0 : _a.externalApiReport({ | ||
requestedAt, | ||
receivedAt: Date.now(), | ||
reqPayload: params, | ||
respPayload: result, | ||
statusCode: 200, | ||
errorMessage: undefined, | ||
tags, | ||
})); | ||
console.log("GOT RESULT", result); | ||
return result; | ||
} | ||
} | ||
} |
{ | ||
"name": "openpipe", | ||
"version": "0.1.0", | ||
"description": "Metrics and auto-evaluation for LLM calls", | ||
"version": "0.1.1", | ||
"type": "module", | ||
"description": "Automatically report your OpenAI calls to OpenPipe", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "tsc", | ||
"test": "vitest" | ||
}, | ||
@@ -12,5 +14,8 @@ "main": "dist/index.js", | ||
"author": "", | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"axios": "^0.26.0", | ||
"encoding": "^0.1.13", | ||
"form-data": "^4.0.0", | ||
"lodash-es": "^4.17.21", | ||
"node-fetch": "^2.6.12", | ||
"openai-beta": "npm:openai@4.0.0-beta.7", | ||
@@ -20,7 +25,10 @@ "openai-legacy": "npm:openai@3.3.0" | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.8", | ||
"@types/node": "^20.4.8", | ||
"@types/node-fetch": "^2.6.4", | ||
"dotenv": "^16.3.1", | ||
"tsx": "^3.12.7", | ||
"typescript": "^5.0.4" | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.33.0" | ||
} | ||
} |
// main.ts or index.ts at the root level | ||
export * as OpenAI from './openai'; | ||
export * as OpenAILegacy from './openai-legacy'; | ||
export * as OpenAI from "./src/openai"; | ||
export * as OpenAILegacy from "./src/openai-legacy"; |
{ | ||
"name": "openpipe", | ||
"version": "0.1.0", | ||
"description": "Metrics and auto-evaluation for LLM calls", | ||
"version": "0.1.1", | ||
"type": "module", | ||
"description": "Automatically report your OpenAI calls to OpenPipe", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "tsc", | ||
"test": "vitest" | ||
}, | ||
@@ -12,5 +14,8 @@ "main": "dist/index.js", | ||
"author": "", | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"axios": "^0.26.0", | ||
"encoding": "^0.1.13", | ||
"form-data": "^4.0.0", | ||
"lodash-es": "^4.17.21", | ||
"node-fetch": "^2.6.12", | ||
"openai-beta": "npm:openai@4.0.0-beta.7", | ||
@@ -20,7 +25,10 @@ "openai-legacy": "npm:openai@3.3.0" | ||
"devDependencies": { | ||
"@types/lodash-es": "^4.17.8", | ||
"@types/node": "^20.4.8", | ||
"@types/node-fetch": "^2.6.4", | ||
"dotenv": "^16.3.1", | ||
"tsx": "^3.12.7", | ||
"typescript": "^5.0.4" | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.33.0" | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"target": "es6", | ||
"module": "commonjs", | ||
"noImplicitAny": true, | ||
"target": "es2017", | ||
"lib": ["esnext"], | ||
"allowJs": true, | ||
"checkJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"outDir": "dist", | ||
"rootDir": ".", | ||
"skipLibCheck": true | ||
"isolatedModules": true, | ||
"incremental": true, | ||
"noUncheckedIndexedAccess": true, | ||
"baseUrl": ".", | ||
"outDir": "dist" | ||
}, | ||
"exclude": ["dist", "node_modules"], | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
240014
59
3102
2
0
71
Yes
6
7
4
3
+ Addedencoding@^0.1.13
+ Addedform-data@^4.0.0
+ Addedlodash-es@^4.17.21
+ Addednode-fetch@^2.6.12
+ Addedencoding@0.1.13(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedlodash-es@4.17.21(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
- Removedaxios@^0.26.0