File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,26 @@ describe('Models', () => {
165165 . catch ( errorHandler . bind ( done ) ) ;
166166 } ) ;
167167
168+ it ( 'Call predict with a declared input id' , done => {
169+ app . models . predict ( Clarifai . GENERAL_MODEL , [
170+ {
171+ id : 'test-id-1' ,
172+ url : sampleImages [ 7 ]
173+ } ,
174+ {
175+ id : 'test-id-2' ,
176+ url : sampleImages [ 8 ]
177+ }
178+ ] )
179+ . then ( response => {
180+ expect ( response . outputs ) . toBeDefined ( ) ;
181+ expect ( response . outputs [ 0 ] . input . id ) . toBe ( 'test-id-1' ) ;
182+ expect ( response . outputs [ 1 ] . input . id ) . toBe ( 'test-id-2' ) ;
183+ done ( ) ;
184+ } )
185+ . catch ( errorHandler . bind ( done ) ) ;
186+ } ) ;
187+
168188 it ( 'Call predict on video inputs' , done => {
169189 app . models . predict ( Clarifai . GENERAL_MODEL , sampleVideos [ 0 ] , { video : true } )
170190 . then ( response => {
Original file line number Diff line number Diff line change @@ -84,9 +84,9 @@ module.exports = {
8484 return formatted ;
8585 } ,
8686 formatMediaPredict : ( data , type = 'image' ) => {
87- let media = data ;
87+ let media ;
8888 if ( checkType ( / S t r i n g / , data ) ) {
89- if ( URL_REGEX . test ( media ) === true ) {
89+ if ( URL_REGEX . test ( data ) === true ) {
9090 media = {
9191 url : data
9292 } ;
@@ -95,12 +95,28 @@ module.exports = {
9595 base64 : data
9696 } ;
9797 }
98+ } else {
99+ media = Object . assign ( { } , data ) ;
100+ }
101+
102+ // Users can specify their own id to distinguish batch results
103+ let id ;
104+ if ( media . id ) {
105+ id = media . id ;
106+ delete media . id ;
98107 }
99- return {
108+
109+ let object = {
100110 data : {
101111 [ type ] : media
102112 }
103113 } ;
114+
115+ if ( id ) {
116+ object . id = id ;
117+ }
118+
119+ return object ;
104120 } ,
105121 formatImagesSearch : ( image ) => {
106122 let imageQuery ;
You can’t perform that action at this time.
0 commit comments