UNPKG

redisai-js

Version:

A high-performance Typescript client for RedisAI

203 lines 6.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stats = void 0; /** * Statistics about model/script types */ var backend_1 = require("./backend"); var Stats = /** @class */ (function () { /** * * @param key - a String of the name of the key storing the model or script value * @param type - a String of the type of value (i.e. 'MODEL' or 'SCRIPT') * @param backend - a String of the type of backend (always 'TORCH' for 'SCRIPT' value type) * @param device - the device that will execute the model. can be of CPU or GPU */ function Stats(key, type, backend, device) { this._key = key; this._type = type; this._backend = backend; this._device = device; this._duration = 0; this._samples = 0; this._calls = 0; this._errors = 0; this._tag = undefined; } Object.defineProperty(Stats.prototype, "device", { get: function () { return this._device; }, set: function (value) { this._device = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "duration", { get: function () { return this._duration; }, set: function (value) { this._duration = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "samples", { get: function () { return this._samples; }, set: function (value) { this._samples = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "calls", { get: function () { return this._calls; }, set: function (value) { this._calls = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "errors", { get: function () { return this._errors; }, set: function (value) { this._errors = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "key", { get: function () { return this._key; }, set: function (value) { this._key = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "type", { get: function () { return this._type; }, set: function (value) { this._type = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "backend", { get: function () { return this._backend; }, set: function (value) { this._backend = value; }, enumerable: false, configurable: true }); Object.defineProperty(Stats.prototype, "tag", { get: function () { return this._tag; }, /** * sets an optional string for tagging the model/scrit such as a version number or any arbitrary identifier * @param value */ set: function (value) { this._tag = value; }, enumerable: false, configurable: true }); Stats.NewStatsFromInfoReply = function (reply) { var keystr = null; var type = null; var backend = null; var device = null; var tag = null; var duration = null; var samples = null; var calls = null; var errors = null; for (var i = 0; i < reply.length; i += 2) { var key = reply[i]; var obj = reply[i + 1]; switch (key.toString()) { case 'key': keystr = obj.toString(); break; case 'type': type = obj.toString(); break; case 'backend': // @ts-ignore backend = backend_1.BackendMap[obj.toString()]; break; case 'device': // @ts-ignore device = obj.toString(); break; case 'tag': tag = obj.toString(); break; case 'duration': duration = obj; break; case 'samples': samples = obj; break; case 'calls': calls = obj; break; case 'errors': errors = obj; break; } } if (keystr == null || type == null || backend == null || device == null) { var missingArr = []; if (keystr == null) { missingArr.push('key'); } if (type == null) { missingArr.push('type'); } if (backend == null) { missingArr.push('backend'); } if (device == null) { missingArr.push('device'); } throw Error('AI.INFO reply did not had the full elements to build the Stats. Missing ' + missingArr.join(',') + '.'); } var stat = new Stats(keystr, type, backend, device); if (tag !== null) { stat.tag = tag; } if (duration !== null) { stat.duration = duration; } if (samples !== null) { stat.samples = samples; } if (calls !== null) { stat.calls = calls; } if (errors !== null) { stat.errors = errors; } return stat; }; return Stats; }()); exports.Stats = Stats; //# sourceMappingURL=stats.js.map