portkey-ai
Version:
Node client library for the Portkey API
403 lines • 21.7 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.Steps = exports.Runs = exports.Messages = exports.Threads = void 0;
const apiResource_1 = require("../apiResource.js");
const utils_1 = require("../utils.js");
const createHeaders_1 = require("./createHeaders.js");
class Threads extends apiResource_1.ApiResource {
constructor(client) {
super(client);
this.messages = new Messages(client);
this.runs = new Runs(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.beta.threads
.create(body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(threadId, 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.beta.threads
.retrieve(threadId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
update(threadId, _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.beta.threads
.update(threadId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
del(threadId, 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.beta.threads
.del(threadId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
createAndRun(_body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
const { stream } = 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);
if (stream === true) {
const streamResponse = yield OAIclient.beta.threads.createAndRunStream(body, opts);
return streamResponse;
}
else {
const result = yield OAIclient.beta.threads
.createAndRun(body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
}
});
}
createAndRunPoll(_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.beta.threads.createAndRunPoll(body, opts);
return result;
});
}
createAndRunStream(_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.beta.threads.createAndRunStream(body, opts);
return result;
});
}
}
exports.Threads = Threads;
class Messages extends apiResource_1.ApiResource {
create(threadId, _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.beta.threads.messages
.create(threadId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
list(threadId, _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.beta.threads.messages
.list(threadId, query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(threadId, messageId, 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.beta.threads.messages
.retrieve(threadId, messageId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
update(threadId, messageId, _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.beta.threads.messages
.update(threadId, messageId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
del(threadId, messageId, 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.beta.threads.messages
.del(threadId, messageId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
}
exports.Messages = Messages;
class Runs extends apiResource_1.ApiResource {
constructor(client) {
super(client);
this.steps = new Steps(client);
}
create(threadId, _body, params, opts) {
return __awaiter(this, void 0, void 0, function* () {
const body = _body;
const { stream } = 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);
if (stream === true) {
const streamResponse = yield OAIclient.beta.threads.runs.stream(threadId, body, opts);
return streamResponse;
}
else {
const result = yield OAIclient.beta.threads.runs
.create(threadId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
}
});
}
list(threadId, _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.beta.threads.runs
.list(threadId, query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(threadId, runId, 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.beta.threads.runs
.retrieve(threadId, runId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
update(threadId, runId, _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.beta.threads.runs
.update(threadId, runId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
submitToolOutputs(threadId, runId, _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.beta.threads.runs
.submitToolOutputs(threadId, runId, body, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
submitToolOutputsAndPoll(threadId, runId, _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.beta.threads.runs.submitToolOutputsAndPoll(threadId, runId, body, opts);
return result;
});
}
submitToolOutputsStream(threadId, runId, _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.beta.threads.runs.submitToolOutputsStream(threadId, runId, body, opts);
return result;
});
}
cancel(threadId, runId, 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.beta.threads.runs
.cancel(threadId, runId, options)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
createAndPoll(threadId, _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.beta.threads.runs.createAndPoll(threadId, body, opts);
return result;
});
}
createAndStream(threadId, _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.beta.threads.runs.createAndStream(threadId, body, opts);
return result;
});
}
poll(threadId, runId, 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.beta.threads.runs.poll(threadId, runId, opts);
return result;
});
}
stream(threadId, _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.beta.threads.runs.stream(threadId, body, opts);
return result;
});
}
}
exports.Runs = Runs;
class Steps extends apiResource_1.ApiResource {
list(threadId, runId, _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.beta.threads.runs.steps
.list(threadId, runId, query, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
retrieve(threadId, runId, stepId, 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.beta.threads.runs.steps
.retrieve(threadId, runId, stepId, opts)
.withResponse();
return (0, utils_1.finalResponse)(result);
});
}
}
exports.Steps = Steps;
//# sourceMappingURL=threads.js.map