UNPKG

portkey-ai

Version:
199 lines 11.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PromptCompletions = exports.PromptPartialsVersions = exports.Partials = exports.PromptVersions = exports.Prompt = exports.Generations = void 0; const constants_1 = require("../constants.js"); const apiResource_1 = require("../apiResource.js"); const utils_1 = require("../utils.js"); const createHeaders_1 = require("./createHeaders.js"); class Generations extends apiResource_1.ApiResource { create(_body, opts) { const warning = 'This API has been deprecated. Please use the Prompt API for the saved prompt.'; console.warn(warning); // eslint-disable-line no-console const body = { variables: _body.variables }; return this.post(`/v1/prompts/${_body.promptID}/generate`, Object.assign({ body }, opts)); } } exports.Generations = Generations; class Prompt extends apiResource_1.ApiResource { constructor(client) { super(client); this.completions = new PromptCompletions(client); this.versions = new PromptVersions(client); this.partials = new Partials(client); } render(_body, params, opts) { const body = _body; const promptId = _body.promptID; 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 response = this.post(`/prompts/${promptId}/render`, Object.assign({ body }, opts)); return response; } create(_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 }))); } const response = this.post(constants_1.PROMPTS_API, Object.assign({ body }, opts)); return response; } list(_query, params, opts) { const query = _query ? (0, utils_1.toQueryParams)(_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 response = this.getMethod(`${constants_1.PROMPTS_API}${query}`, Object.assign({}, opts)); return response; } retrieve(promptSlug, 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 }))); } const response = this.getMethod(`${constants_1.PROMPTS_API}/${promptSlug}`, Object.assign({}, opts)); return response; } update(promptSlug, _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 }))); } const response = this.put(`${constants_1.PROMPTS_API}/${promptSlug}`, Object.assign({ body }, opts)); return response; } delete(promptSlug, 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 }))); } const response = this.deleteMethod(`${constants_1.PROMPTS_API}/${promptSlug}`, Object.assign({}, opts)); return response; } publish(promptSlug, body, 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 }))); } const response = this.put(`${constants_1.PROMPTS_API}/${promptSlug}/makeDefault`, Object.assign({ body }, opts)); return response; } } exports.Prompt = Prompt; class PromptVersions extends apiResource_1.ApiResource { list(promptSlug, 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 }))); } const response = this.getMethod(`${constants_1.PROMPTS_API}/${promptSlug}/versions`, Object.assign({}, opts)); return response; } retrieve(promptSlug, versionId, 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 }))); } const response = this.getMethod(`${constants_1.PROMPTS_API}/${promptSlug}/versions/${versionId}`, Object.assign({}, opts)); return response; } update(promptSlug, versionId, body, 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 }))); } const response = this.put(`${constants_1.PROMPTS_API}/${promptSlug}/versions/${versionId}`, Object.assign({ body }, opts)); return response; } } exports.PromptVersions = PromptVersions; class Partials extends apiResource_1.ApiResource { constructor(client) { super(client); this.versions = new PromptPartialsVersions(client); } create(_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 }))); } const response = this.post(`${constants_1.PROMPT_PARTIALS_API}`, Object.assign({ body }, opts)); return response; } list(_query, params, opts) { const query = _query ? (0, utils_1.toQueryParams)(_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 response = this.getMethod(`${constants_1.PROMPT_PARTIALS_API}${query}`, Object.assign({}, opts)); return response; } retrieve(promptPartialSlug, 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 }))); } const response = this.getMethod(`${constants_1.PROMPT_PARTIALS_API}/${promptPartialSlug}`, Object.assign({}, opts)); return response; } update(promptPartialSlug, body, 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 }))); } const response = this.put(`${constants_1.PROMPT_PARTIALS_API}/${promptPartialSlug}`, Object.assign({ body }, opts)); return response; } delete(promptPartialSlug, 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 }))); } const response = this.deleteMethod(`${constants_1.PROMPT_PARTIALS_API}/${promptPartialSlug}`, Object.assign({}, opts)); return response; } publish(promptPartialSlug, body, 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 }))); } const response = this.put(`${constants_1.PROMPT_PARTIALS_API}/${promptPartialSlug}/makeDefault`, Object.assign({ body }, opts)); return response; } } exports.Partials = Partials; class PromptPartialsVersions extends apiResource_1.ApiResource { list(promptPartialSlug, 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 }))); } const response = this.getMethod(`${constants_1.PROMPT_PARTIALS_API}/${promptPartialSlug}/versions`, Object.assign({}, opts)); return response; } } exports.PromptPartialsVersions = PromptPartialsVersions; class PromptCompletions extends apiResource_1.ApiResource { create(_body, params, opts) { var _a; 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 promptId = _body.promptID; const body = _body; const stream = (_a = _body.stream) !== null && _a !== void 0 ? _a : false; delete body.promptID; body.stream = stream; const response = this.post(`/prompts/${promptId}/completions`, Object.assign(Object.assign({ body }, opts), { stream })); return response; } } exports.PromptCompletions = PromptCompletions; //# sourceMappingURL=generations.js.map