UNPKG

portkey-ai

Version:
71 lines 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChatCompletionsMessages = exports.Chat = void 0; const apiResource_1 = require("../apiResource.js"); const constants_1 = require("../constants.js"); const utils_1 = require("../utils.js"); const createHeaders_1 = require("./createHeaders.js"); class Chat extends apiResource_1.ApiResource { constructor() { super(...arguments); this.completions = new ChatCompletions(this.client); } } exports.Chat = Chat; class ChatCompletions extends apiResource_1.ApiResource { constructor() { super(...arguments); this.messages = new ChatCompletionsMessages(this.client); } create(_body, params, opts) { var _a; const body = _body; // If config is present then override it. 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 stream = (_a = _body.stream) !== null && _a !== void 0 ? _a : false; return this.post(constants_1.CHAT_COMPLETE_API, Object.assign(Object.assign({ body }, opts), { stream })); } retrieve(completionId, params, opts) { 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 }))); } return this.getMethod(`${constants_1.CHAT_COMPLETE_API}/${completionId}`, Object.assign({}, opts)); } update(completionId, _body, params, opts) { 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 }))); } return this.post(`${constants_1.CHAT_COMPLETE_API}/${completionId}`, Object.assign({ body }, opts)); } list(query, params, opts) { 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 }))); } return this.getMethod(`${constants_1.CHAT_COMPLETE_API}`, Object.assign(Object.assign({}, opts), query)); } del(completionId, params, opts) { 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 }))); } return this.deleteMethod(`${constants_1.CHAT_COMPLETE_API}/${completionId}`, Object.assign({}, opts)); } } class ChatCompletionsMessages extends apiResource_1.ApiResource { list(completionId, query, params, opts) { 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 }))); } return this.getMethod(`${constants_1.CHAT_COMPLETE_API}/${completionId}/messages`, Object.assign(Object.assign({}, opts), query)); } } exports.ChatCompletionsMessages = ChatCompletionsMessages; //# sourceMappingURL=chatCompletions.js.map