UNPKG

redisai-js

Version:

A high-performance Typescript client for RedisAI

106 lines (105 loc) 3.85 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", {value: true}); var Tensor_1 = require("./Tensor"); var util = __importStar(require("util")); var DType_1 = require("./DType"); var RedisaiClient = /** @class */ (function () { function RedisaiClient(client) { this._client = client; this._sendCommand = util.promisify(this._client.send_command).bind(this._client); } Object.defineProperty(RedisaiClient.prototype, "client", { get: function () { return this._client; }, enumerable: true, configurable: true }); RedisaiClient.prototype.end = function (flush) { this._client.end(flush); }; RedisaiClient.prototype.tensorset = function (keName, t) { var args = [keName, t.dtype]; t.shape.forEach(function (value) { return args.push(value.toString()); }); if (t.data != null) { args.push('VALUES'); t.data.forEach(function (value) { return args.push(value.toString()); }); } return this._sendCommand('ai.tensorset', args); }; RedisaiClient.prototype.tensorget = function (keName) { var args = [keName, 'META', 'VALUES']; return this._sendCommand('ai.tensorget', args) .then(function (reply) { var dt = null; var shape = null; var values = null; for (var i = 0; i < reply.length; i += 2) { var key = reply[i]; var obj = reply[i + 1]; switch (key.toString()) { case 'dtype': // @ts-ignore dt = DType_1.DTypeMap[obj.toString()]; break; case 'shape': shape = obj; break; case 'values': values = obj.map(Number); break; } } if (dt == null || shape == null || values == null) { throw Error('tensorget reply did not had the full elements to build the tensor'); } return new Tensor_1.Tensor(dt, shape, values); }) .catch(function (error) { throw error; }); }; RedisaiClient.prototype.modelset = function (keName, m) { var args = [keName, m.backend, m.device]; if (m.inputs.length > 0) { args.push('INPUTS'); m.inputs.forEach(function (value) { return args.push(value); }); } if (m.outputs.length > 0) { args.push('OUTPUTS'); m.outputs.forEach(function (value) { return args.push(value); }); } args.push('BLOB'); args.push(m.blob.toString()); return this._sendCommand('ai.modelset', args); }; RedisaiClient.prototype.modelrun = function (modelName, inputs, outputs) { var args = [modelName, 'INPUTS']; inputs.forEach(function (value) { return args.push(value); }); args.push('OUTPUTS'); outputs.forEach(function (value) { return args.push(value); }); return this._sendCommand('ai.modelrun', args); }; return RedisaiClient; }()); exports.RedisaiClient = RedisaiClient; //# sourceMappingURL=redisaiClient.js.map