UNPKG

portkey-ai

Version:
93 lines 4.76 kB
"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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.speech = exports.translations = exports.transcriptions = exports.Audio = void 0; const apiResource_1 = require("../apiResource.js"); const utils_1 = require("../utils.js"); const createHeaders_1 = require("./createHeaders.js"); const constants_1 = require("../constants.js"); const getAudioDuration_1 = __importDefault(require("../getAudioDuration.js")); class Audio extends apiResource_1.ApiResource { constructor(client) { super(client); this.transcriptions = new transcriptions(client); this.translations = new translations(client); this.speech = new speech(client); } } exports.Audio = Audio; class transcriptions extends apiResource_1.ApiResource { create(body, params, opts) { var _a; return __awaiter(this, void 0, void 0, function* () { // @ts-ignore const path = (_a = body.file) === null || _a === void 0 ? void 0 : _a.path; if (path && this.client.calculateAudioDuration) { const duration = yield (0, getAudioDuration_1.default)(path); if (duration) { params = Object.assign(Object.assign({}, params), { [constants_1.AUDIO_FILE_DURATION_HEADER]: duration }); } } 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 response = OAIclient.audio.transcriptions.create(body, opts); return response; }); } } exports.transcriptions = transcriptions; class translations extends apiResource_1.ApiResource { create(_body, params, opts) { var _a; return __awaiter(this, void 0, void 0, function* () { const body = _body; const path = (_a = body.file) === null || _a === void 0 ? void 0 : _a.path; if (path && this.client.calculateAudioDuration) { const duration = yield (0, getAudioDuration_1.default)(path); if (duration) { params = Object.assign(Object.assign({}, params), { [constants_1.AUDIO_FILE_DURATION_HEADER]: duration }); } } 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 response = yield OAIclient.audio.translations .create(body, opts) .withResponse(); return (0, utils_1.finalResponse)(response); }); } } exports.translations = translations; class speech extends apiResource_1.ApiResource { 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); const response = yield OAIclient.audio.speech.create(body, opts); return response; }); } } exports.speech = speech; //# sourceMappingURL=audio.js.map