portkey-ai
Version:
Node client library for the Portkey API
291 lines • 16.2 kB
JavaScript
"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.FileBatches = exports.Files = exports.VectorStores = void 0;
const apiResource_1 = require("../apiResource.js");
const utils_1 = require("../utils.js");
const createHeaders_1 = require("./createHeaders.js");
class VectorStores extends apiResource_1.ApiResource {
constructor(client) {
super(client);
this.files = new Files(client);
this.fileBatches = new FileBatches(client);
}
create(_body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = yield OAIclient.vectorStores
.create(body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(vectorStoreId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores
.retrieve(vectorStoreId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
update(vectorStoreId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores
.update(vectorStoreId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
list(_query, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const query = _query;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores
.list(query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
del(vectorStoreId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores
.del(vectorStoreId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
}
exports.VectorStores = VectorStores;
class Files extends apiResource_1.ApiResource {
create(vectorStoreId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files
.create(vectorStoreId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(vectorStoreId, fileId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files
.retrieve(vectorStoreId, fileId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
list(vectorStoreId, _query, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const query = _query;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files
.list(vectorStoreId, query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
del(vectorStoreId, fileId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files
.del(vectorStoreId, fileId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
createAndPoll(vectorStoreId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files.createAndPoll(vectorStoreId, body, opts);
return result;
});
}
poll(vectorStoreId, fileId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files.poll(vectorStoreId, fileId, opts);
return result;
});
}
upload(vectorStoreId, file, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files.upload(vectorStoreId, file, opts);
return result;
});
}
uploadAndPoll(vectorStoreId, file, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.files.uploadAndPoll(vectorStoreId, file, opts);
return result;
});
}
}
exports.Files = Files;
class FileBatches extends apiResource_1.ApiResource {
create(vectorStoreId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.fileBatches
.create(vectorStoreId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(vectorStoreId, batchId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.fileBatches
.retrieve(vectorStoreId, batchId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
cancel(vectorStoreId, batchId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const body = {};
const options = Object.assign({ body }, opts);
const result = yield OAIclient.vectorStores.fileBatches
.cancel(vectorStoreId, batchId, options)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
createAndPoll(vectorStoreId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.fileBatches.createAndPoll(vectorStoreId, body, opts);
return result;
});
}
listFiles(vectorStoreId, batchId, _query, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const query = _query;
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = yield OAIclient.vectorStores.fileBatches
.listFiles(vectorStoreId, batchId, query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
poll(vectorStoreId, batchId, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.fileBatches.poll(vectorStoreId, batchId, opts);
return result;
});
}
uploadAndPoll(vectorStoreId, { files, fileIds = [] }, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
if (params) {
const config = (0, utils_1.overrideConfig)(this.client.config, params.config);
this.client.customHeaders = Object.assign(Object.assign({}, this.client.customHeaders), (0, createHeaders_1.createHeaders)(Object.assign(Object.assign({}, params), { config })));
}
const OAIclient = (0, utils_1.initOpenAIClient)(this.client);
const result = yield OAIclient.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, { files, fileIds }, opts);
return result;
});
}
}
exports.FileBatches = FileBatches;
//# sourceMappingURL=vectorStores.js.map