The code in this directory defines a client library for use with the gRPC-based Test.ai classifier server.
npm install test-ai-classifier-client
This client exposes as the default export a ClassifierClient
class, which can be instantiated as follows:
const ClassifierClient = require('test-ai-classifier-client');
const client = new ClassifierClient({host, port})
(Where host
and port
refer to the address and port the server is running on).
The client exposes two instance methods:
-
classifyElements
takes an object parameter with 4 keys:labelHint
: the label you wish to find matching elements with (seelib/labels.js
in this repo).elementImages
: an object whose keys are ids, and whose values areBuffer
objects containing raw binary data of PNG images.confidenceThreshold
: (optional) the confidence below which not to return matches (0.0 - 1.0)allowWeakerMatches
: (optional) whether or not to return a match for elements that did match the label, but for whom another label had a higher confidence.
The return value of this method is an object whose keys are the same ids you sent in, and whose values are classification objects with the following keys:
label
: the matching labelconfidence
: the confidence for the matched labelconfidenceForLabel
: the confidence for the label given inlabelHint
-
findElementsMatchingLabel
is a helper function for use with Selenium tests (for Appium use the Appium plugin as described in the main README for this repo). It takes an object parameter with 4 keys: all of the same keys as inclassifyElements
except forelementImages
which is replaced by:driver
: the WebdriverIO driver object The return value of this method is an array of WebdriverIO element objects that match.
For a concrete example, see test/rpc-e2e-specs.js
Tests expect a running Classifier server on port 50051.