Clarifai / clarifai-javascript

Official Clarifai JavaScript client for browsers and node.js
https://docs.clarifai.com
Other
351 stars 81 forks source link

app.inputs.create single object argument does not work correctly. #28

Closed ohpyupi closed 5 years ago

ohpyupi commented 5 years ago

Hello,

I was doing a POC work to use clarifai in my personal project. And found that if I pass a single object argument to app.inputs.create, then the concepts are not tied to the image correctly. However, when I tried array argument to the method, it worked perfectly. Below is my code sample.

// Image is uploaded, but concepts are missing.
app.inputs.create({
 url: 'url-for-image',
 concepts: [{
  id: 'cat',
  value: true,
 }],
});

// Image is uploaded with concepts as expected
app.inputs.create([
 {
  url: 'url-for-image',
  concepts: [{
   id: 'cat',
   value: true,
  }],
 }
]);
rok-povsic commented 5 years ago

Hello @ohpyupi ,

I've tested both samples on the latest Clarifai JS version 2.9.0 and it works fine for me. In both cases, the cat concept is added to the image.

Can you test this again to make sure you are testing it properly? The response you get back from in create contains the added concepts so you can inspect them and see how many there are, like this:

app.inputs.create({
    url: 'url-for-image',
    concepts: [{
        id: 'cat',
        value: true,
    }],
}).then(function(inputs) {
    console.log('Number of concepts: ' + inputs[0].concepts.length);
});

In the library source code, a single object argument argument is handled in the same way as a multi object argument, as it is converted to a list immediately at the beginning of the create method. You can see that here. So there really shouldn't be any difference in how single/multiple object arguments behave.

ohpyupi commented 5 years ago

@rok-povsic Hi Thank you for checking that out. I was able to see the concepts on the response. But somehow, I was not able to see the concepts on the dashboard, the UI where we can upload images by drag and drop. Were you also able to see those concepts on the dashboard?

rok-povsic commented 5 years ago

@ohpyupi Hi, yes I was. It's the same code that gets run, the same request gets sent to the API. I'd guess your browser cache may have had a part in this. :)