@@ -4,6 +4,9 @@ import {Tensor} from "../src/tensor";
44import { DType } from "../src/DType" ;
55import 'mocha' ;
66import { expect } from 'chai' ;
7+ import { Model } from "../src/Model" ;
8+ import * as fs from "fs" ;
9+ import { Backend } from "../src/Backend" ;
710
811const mochaAsync = ( fn : any ) => {
912 return ( done : any ) => {
@@ -86,3 +89,41 @@ it("ai.tensorget negative testing", mochaAsync(async () => {
8689} ) ) ;
8790
8891
92+ it ( "ai.modelset positive testing" , mochaAsync ( async ( ) => {
93+ const nativeClient = createClient ( ) ;
94+ const aiclient = new RedisaiClient ( nativeClient ) ;
95+ let model_blob : Buffer = fs . readFileSync ( "./tests/test_data/graph.pb" ) ;
96+ const model = new Model ( Backend . TF , "CPU" , [ "a" , "b" ] , [ "c" ] , model_blob ) ;
97+ const result = await aiclient . modelset ( "m1" , model ) ;
98+ expect ( result ) . to . equal ( 'OK' ) ;
99+ aiclient . end ( true ) ;
100+ } ) ) ;
101+
102+ it ( "ai.modelrun positive testing" , mochaAsync ( async ( ) => {
103+ const nativeClient = createClient ( ) ;
104+ const aiclient = new RedisaiClient ( nativeClient ) ;
105+
106+
107+ const tensorA = new Tensor ( DType . float32 , [ 1 , 2 ] , [ 2 , 3 ] ) ;
108+ const resultA = await aiclient . tensorset ( "tensorA" , tensorA ) ;
109+ expect ( resultA ) . to . equal ( 'OK' ) ;
110+
111+ const tensorB = new Tensor ( DType . float32 , [ 1 , 2 ] , [ 3 , 5 ] ) ;
112+ const resultB = await aiclient . tensorset ( "tensorB" , tensorB ) ;
113+ expect ( resultB ) . to . equal ( 'OK' ) ;
114+
115+
116+ let model_blob : Buffer = fs . readFileSync ( "./tests/test_data/graph.pb" ) ;
117+ const model = new Model ( Backend . TF , "CPU" , [ "a" , "b" ] , [ "c" ] , model_blob ) ;
118+ const resultModelSet = await aiclient . modelset ( "mymodel" , model ) ;
119+ expect ( resultModelSet ) . to . equal ( 'OK' ) ;
120+
121+ const resultModelRun = await aiclient . modelrun ( "mymodel" , [ "tensorA" , "tensorB" ] , [ "tensorC" ] ) ;
122+ expect ( resultModelRun ) . to . equal ( 'OK' ) ;
123+
124+ const tensorC = await aiclient . tensorget ( "tensorC" ) ;
125+ expect ( tensorC . data [ 0 ] ) . to . closeTo ( 6.0 , 0.1 ) ;
126+ expect ( tensorC . data [ 1 ] ) . to . closeTo ( 15.0 , 0.1 ) ;
127+
128+ aiclient . end ( true ) ;
129+ } ) ) ;
0 commit comments