I am working on putting together a plugin for Indico that will access there custom data set feature. I have all of the calls working to add data, train the collection and tag text from it. Now the problem, I don’t know anything about JS and I believe writing an action to define the object as a variable that I can write to a table is what I need to do.
Results are returned as an object and its probability of being a match like this
Here is an actual return from a test data set I trained with a few cars and motorcycles just to test. I expect my actual dataset to have 100+ possible objects that may change at any given time so hardcoding them is not an option.
I can have the API only return the best match but the way that the data is structured I only get access to the probability when what I need is the object name. Ideally I would like to have access to both the object name and the probability so that if there are multiple high probability objects I could classify something as both and weight it on the probability.
I’m not expecting somebody to write this for me but if someone could point me in the right direction that would be great. I have no intention of becoming a master at JS but I am certainly willing to learn enough to get by. The problem is I don’t even know where to start and I can’t seem to find any examples that seem close to what I want to do and to be honest I’m not quite sure where to start. Also I will release this with dynamic options so other can define their own custom collections and make use of it.
If you want to access an API differently than the API connector or the API endpoints, you can do your own in javascript, for examples look up GET / POST via ajax … then put it into a HTML element or an element plugin. It will be limited to client-side only, as in the API is called from the browser rather than the server.
An alternative is to have the data in a different form, where your “field names” are on the data side, like: { "result list": [{ "name": "Automobile", "probability": 0.6667 }, { "name": "Motorcycle", "probability": 0.3332 } ] }
If you can’t change how the data is sent, you could use an intermediate server to alter the structure.
Thanks for the suggestions. I don’t think that doing it through an HTML element will accomplish what I need, It seems like it would be better to be able to run some of the Actions on the server and I also need to keep my key hidden(I believe, I really am learning all of this as I go).
I like the different data format idea, there is nothing in their documentation about changing the format of their responses so I sent them an email. I would like to stay away from putting an intermediary in to reformat, just seems like another piece to break. I will follow up with what they say.
I finally got a response from Indico, they do not offer a way to change the output. Data can be manipulated through JS in a plugin action though correct? I am pretty sure that reformatting the response with JS is pretty simple, I have found a couple of different examples of how I think I can do it, I am still trying to get enough of a grasp on JS to incorporate them into a plugin though. I have been taking some JS courses at Codecademy and am starting to get a lot better understanding of how things really work. If anybody has any suggestions on other places I should be looking for content more specifically relevant to working with Bubble I would love to hear from you. I am having trouble figuring out what data or functions I have access to inside the plugin and how to pass data back out of it.
Thank you @mishav! I really appreciate the help, this really helps with understanding what I should be learning, Thanks again!
If you, or anyone else, don’t mind can you tell me if this sounds like I am on the right path.
I have started to writing most of the code that I need in my browser console with manually defined variables and console.log outputs to test it? Then once it works I should be able to move it into Bubble where I can change my test data to dynamic data from bubble and change my console.log operations to actually send data either to the screen or directly to the database?
Sending to the screen involves building up HTML that gets displayed in the element, as per the example: div = $('<div></div>'); instance.canvas.append(div);
The way to get data into the database is indirect:
Define an “exposed state” and then in the code use the function instance.publishState.
Use the element’s published values in a workflow action.