UNPKG

redisai-js

Version:

A high-performance Typescript client for RedisAI

112 lines 3.53 kB
"use strict"; /** * Direct mapping to RedisAI Script */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Script = void 0; var Script = /** @class */ (function () { /** * * @param device - the device that will execute the model. can be of CPU or GPU * @param script - a string containing TorchScript source code */ function Script(device, script) { this._device = device; this._script = script; this._tag = undefined; } Object.defineProperty(Script.prototype, "tag", { get: function () { return this._tag; }, /** * sets an optional string for tagging the model such as a version number or any arbitrary identifier * @param value */ set: function (value) { this._tag = value; }, enumerable: false, configurable: true }); Object.defineProperty(Script.prototype, "device", { get: function () { return this._device; }, set: function (value) { this._device = value; }, enumerable: false, configurable: true }); Object.defineProperty(Script.prototype, "script", { get: function () { return this._script; }, set: function (value) { this._script = value; }, enumerable: false, configurable: true }); Script.NewScriptFromScriptGetReply = function (reply) { var device = null; var tag = null; var source = null; for (var i = 0; i < reply.length; i += 2) { var key = reply[i]; var obj = reply[i + 1]; switch (key.toString()) { case 'device': // @ts-ignore device = obj.toString(); break; case 'tag': tag = obj.toString(); break; case 'source': source = obj.toString(); break; } } if (device == null || source == null) { var missingArr = []; if (device == null) { missingArr.push('device'); } if (source == null) { missingArr.push('source'); } throw Error('AI.SCRIPTGET reply did not had the full elements to build the Script. Missing ' + missingArr.join(',') + '.'); } var script = new Script(device, source); if (tag !== null) { script.tag = tag; } return script; }; Script.prototype.scriptSetFlatArgs = function (keyName) { var args = [keyName, this.device]; if (this.tag !== undefined) { args.push('TAG'); args.push(this.tag); } args.push('SOURCE'); args.push(this.script); return args; }; Script.scriptRunFlatArgs = function (scriptName, functionName, inputs, outputs) { var args = [scriptName, functionName, 'INPUTS']; inputs.forEach(function (value) { return args.push(value); }); args.push('OUTPUTS'); outputs.forEach(function (value) { return args.push(value); }); return args; }; Script.scriptGetFlatArgs = function (scriptName) { var args = [scriptName, 'META', 'SOURCE']; return args; }; return Script; }()); exports.Script = Script; //# sourceMappingURL=script.js.map