UNPKG

twilio

Version:
175 lines (174 loc) 6.04 kB
"use strict"; /* * This code was generated by * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ * * Twilio Knowledge API * APIs for managing knowledge bases and knowledge content for AI-powered applications. * * NOTE: This class is auto generated by OpenAPI Generator. * https://openapi-generator.tech * Do not edit the class manually. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchInstance = exports.SearchContextImpl = exports.KnowledgeSearch = exports.KnowledgeChunkResult = void 0; exports.SearchListInstance = SearchListInstance; const util_1 = require("util"); const deserialize = require("../../../base/deserialize"); const serialize = require("../../../base/serialize"); const utility_1 = require("../../../base/utility"); class KnowledgeChunkResult { constructor(payload) { this.content = payload["content"]; this.createdAt = payload["createdAt"]; this.score = payload["score"]; this.knowledgeId = payload["knowledgeId"]; } } exports.KnowledgeChunkResult = KnowledgeChunkResult; /** * Request payload for performing semantic search across knowledge sources within the knowledge base.. Allows querying with natural language text and filtering by specific knowledge sources to find the most relevant content chunks. */ class KnowledgeSearch { constructor(payload) { this.query = payload["query"]; this.top = payload["top"]; this.knowledgeIds = payload["knowledgeIds"]; } } exports.KnowledgeSearch = KnowledgeSearch; class SearchContextImpl { constructor(_version, kbId) { this._version = _version; if (!(0, utility_1.isValidPathParam)(kbId)) { throw new Error("Parameter 'kbId' is not valid."); } this._solution = { kbId }; this._uri = `/KnowledgeBases/${kbId}/Search`; } create(params, headers, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers, }); operationPromise = operationPromise.then((payload) => new SearchInstance(operationVersion, payload, instance._solution.kbId)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } createWithHttpInfo(params, headers, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; data = params; if (headers === null || headers === undefined) { headers = {}; } headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .createWithResponseInfo({ uri: instance._uri, method: "post", data, headers, }) .then((response) => ({ ...response, body: new SearchInstance(operationVersion, response.body, instance._solution.kbId), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return this._solution; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.SearchContextImpl = SearchContextImpl; class SearchInstance { constructor(_version, _payload, kbId) { this._version = _version; const payload = _payload; this.chunks = payload.chunks !== null && payload.chunks !== undefined ? payload.chunks.map((payload) => new KnowledgeChunkResult(payload)) : null; this._solution = { kbId: kbId }; } get _proxy() { this._context = this._context || new SearchContextImpl(this._version, this._solution.kbId); return this._context; } create(params, callback) { return this._proxy.create(params, callback); } createWithHttpInfo(params, callback) { return this._proxy.createWithHttpInfo(params, callback); } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return { chunks: this.chunks, }; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.SearchInstance = SearchInstance; function SearchListInstance(version) { const instance = ((kbId) => instance.get(kbId)); instance.get = function get(kbId) { return new SearchContextImpl(version, kbId); }; instance._version = version; instance._solution = {}; instance._uri = ``; instance.toJSON = function toJSON() { return instance._solution; }; instance[util_1.inspect.custom] = function inspectImpl(_depth, options) { return (0, util_1.inspect)(instance.toJSON(), options); }; return instance; }