Docs Navigation +

Node.js SDK

fuzzy.ai has an official library for  Node.js. It's available under the Apache Public License 2.0.and should be usable in commercial and Open Source projects.

Installation

The fuzzy.ai package on npm has the latest version of the code:

https://www.npmjs.com/package/fuzzy.ai

You can use npm to install:

npm install fuzzy.ai

… or add it to your package.json file.

You can also fork the repository on Github.

https://github.com/fuzzy-ai/nodejs

… or download the latest release:

https://github.com/fuzzy-ai/nodejs/releases

Overview

var FuzzyAIClient = require('fuzzy.ai');

var apiKey = 'API key from fuzzy.ai';

var client = new FuzzyAIClient(apiKey);

var agentID = 'ID from fuzzy.ai';

var inputs = {temperature: 87};

client.evaluate(agentID, inputs, function(err, outputs) {
if (err) {
console.error(err);
} else {
console.log("Fan speed is " + outputs.fanSpeed);
}
});

FuzzyAIClient

This is the main class; it's what's returned from the require().

FuzzyAIClient(apiKey, apiRoot) You have to get an apiKey from http://fuzzy.ai/ . Keep this secret, by the way. serverRoot is the root of the API server. It has the correct default 'https://api.fuzzy.ai' but if you're doing some testing with a mock, it can be useful.

This is the main method you need to use:

evaluate(agentID, inputs, callback) Does a single inference. agentID is on the main page for the agent on http://fuzzy.ai/ . The inputs is an object, mapping input names to numeric values. callback is a function with the signature function(err, outputs), where outputs is an object mapping output names to numeric values.

These might be useful but you normally don't need to mess with them.

  • getAgents(callback) userID is the user ID, not the API key. callback is a function with the signature function(err, agents), where agents is an array of objects with id and name properties, one for each agent the user has.
  • newAgent(agent, callback) userID is the user ID. agent is an agent object with at least properties inputs, outputs, rules. callback is a function with the signature function(err, agent) which returns the fully-realized agent with all its properties like timestamps and IDs.
  • getAgent(agentID, callback) Gets a single agent by ID. callback is a function with the signature function(err, agent).
  • putAgent(agentID, agent, callback) Updates an agent. callback has the signature function(err, agent) which will return the updated version.