Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clarifai

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clarifai - npm Package Compare versions

Comparing version 1.2.1 to 2.0.7

.babelrc

76

gulp/gulpfile.js

@@ -15,3 +15,2 @@ var gulp = require('gulp');

var jasmine = require('gulp-jasmine');
var gulp = require('gulp');
var del = require('del');

@@ -21,9 +20,8 @@ var fs = require('fs');

var awspublish = require('gulp-awspublish');
var VERSION = require('../package.json').version;
var VERSION = require('./../package.json').version;
var tasks = [
'browserify',
'jslint',
'html'
'browserify'
];

@@ -41,8 +39,8 @@

function watchFiles() {
gulp.watch('../index.js', ['jslint', 'browserify']);
gulp.watch('../lib/**', ['jslint', 'browserify']);
gulp.watch('../examples/**', ['html']);
gulp.watch('./../index.js', ['jslint', 'browserify']);
gulp.watch('./../src/**', ['jslint', 'browserify']);
gulp.watch('./../examples/**', ['html']);
}
// browserify lib/js to build/js
// browserify src/js to build/js
gulp.task('browserify', function() {

@@ -64,9 +62,9 @@ var buildVars = getBuildVars();

];
return gulp.src('../index.js')
return gulp.src('./../index.js')
.pipe(browserify({
'insertGlobals': false,
'debug': buildVars.browserifyDebug,
'transform': ['envify']
})
.on('error', notify.onError(function(error) {
'debug': false,
'transform': ['babelify']
}).on('error', notify.onError(function(error) {
var message = 'Browserify error: ' + error.message;

@@ -87,3 +85,3 @@ if ( buildVars.browserifyFailOnError === true ) {

.pipe(insert.prepend(BROWSER_HEADER))
.pipe(gulp.dest('../build/'))
.pipe(gulp.dest('./../build/'));
});

@@ -96,3 +94,3 @@

var CLIENT_SECRET = process.env.CLIENT_SECRET || '';
return gulp.src('../examples/**.html')
return gulp.src('./../examples/**.html')
.pipe(gulpif( buildVars.uglify, htmlmin({collapseWhitespace: true}) ))

@@ -115,3 +113,3 @@ .pipe(replace({

}))
.pipe(gulp.dest('../build/examples'));
.pipe(gulp.dest('./../build/examples'));
});

@@ -122,3 +120,3 @@

var port = gutil.env.port || '3000';
return gulp.src('../build')
return gulp.src('./../build')
.pipe(webserver({

@@ -227,3 +225,3 @@ 'livereload': false,

function dontFailOnError() {
return gulp.src(['../lib/**/*.js'])
return gulp.src(['./../src/**/*.js'])
.pipe(eslint(lintOptions))

@@ -235,3 +233,3 @@ .pipe(eslint.format())

function failOnError() {
return gulp.src(['../lib/**/*.js'])
return gulp.src(['./../src/**/*.js'])
.pipe(eslint(lintOptions))

@@ -246,6 +244,12 @@ .pipe(eslint.format())

gulp.task('test', function() {
return gulp.src('../spec/*.js')
return gulp.src('./../spec/*.js')
.pipe(jasmine({
'includeStackTrace': true,
'verbose': true,
'timeout': 60000
'timeout': 60000,
'config': {
'helpers': [
'./../node_modules/babel-register/lib/node.js'
]
}
}).on('end', function() {

@@ -261,3 +265,3 @@ process.exit();

return del([
'../build/**',
'./../build/**',
], {'force': true});

@@ -275,3 +279,2 @@ });

function publish() {
var src = '../build/clarifai-' + VERSION + '.js';
var aws;

@@ -283,3 +286,3 @@ if ( gutil.env.aws ) {

console.log('Using aws:', 'file');
aws = JSON.parse(fs.readFileSync('../aws.json'));
aws = JSON.parse(fs.readFileSync('./../aws.json'));
}

@@ -292,8 +295,5 @@ console.log('Deploying to bucket:', aws.params.Bucket);

};
return gulp.src([
'../build/clarifai-' + VERSION + '.js',
'../build/clarifai-' + VERSION + '.zip'
])
return gulp.src('./../build/**')
.pipe(rename(function (path) {
path.dirname += '/js';
path.dirname = '/js/' + path.dirname;
}))

@@ -306,11 +306,11 @@ .pipe(publisher.publish(headers))

return gulp.src([
'../index.js',
'../README.md',
'../spec',
'../lib/*',
'../package.json',
'../examples/*'
],{ 'base': '../' })
'./../index.js',
'./../README.md',
'./../spec',
'./../src/*',
'./../package.json',
'./../examples/*'
],{ 'base': './../' })
.pipe(zip('clarifai-' + VERSION + '.zip'))
.pipe(gulp.dest('../build'));
});
.pipe(gulp.dest('./../build'));
});

@@ -30,3 +30,3 @@ ## Build From Source

* `--stage` - if set will build with the env vars found in `gulpfile.js`. Possible values are: `dev`
* `--stage` - if set will build with the env vars found in `gulpfile.js`. Possible values are: `dev`
(default), `test`, `staging`, `prod`

@@ -36,6 +36,9 @@ * `--port 4000` - if set the webserver will run on the port passed in (default 3000)

#### JSDocs
To compile docs, run `jsdoc src/* -t node_modules/minami -d build/docs` in the root folder.
## Examples
* Run in the browser: `CLIENT_ID=foo CLIENT_SECRET=bar gulp build`
* Run in node.js: `CLIENT_ID=foo CLIENT_SECRET=bar node examples/node-example`
* Run in node.js: `CLIENT_ID=foo CLIENT_SECRET=bar node examples/node-example`

@@ -1,166 +0,13 @@

var config = require('./lib/config');
var token = require('./lib/token');
var tag = require('./lib/tag');
var info = require('./lib/info');
var languages = require('./lib/languages');
var callback = require('./lib/callback');
var color = require('./lib/color');
var feedback = require('./lib/feedback');
var usage = require('./lib/usage');
let App = require('./src/App');
module.exports = global.Clarifai = {
initialize: function(options) {
config.set('apiEndpoint', options.apiEndpoint || process.env.API_ENDPOINT || 'https://api.clarifai.com');
config.set('clientId', options.clientId || process.env.CLIENT_ID);
config.set('clientSecret', options.clientSecret || process.env.CLIENT_SECRET);
token.delete();
},
/**
* Gets a token from the API using client credentials
* @method getToken
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the token string or rejected with an error
*/
getToken: function(_callback) {
var promise = token.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Sets the token to use for the API
* @method setToken
* @param {String} _token The token you are setting
* @return {Boolean} true if token has valid fields, false if not
*/
setToken: function(_token) {
return token.set(_token);
},
/**
* Deletes the token
* @method deleteToken
*/
deleteToken: function() {
token.delete();
},
/**
* Gets tags given a url
* @method getTagsByUrl
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} model The model used to tag the image (optional)
* @param {String} language The language used to tag the image (optional)
* @param {String} or {Array} selectClasses Restrict the tags returned
* @param {String} or {Array} localId Provide a localId for each url to simplify tracking requests (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getTagsByUrl: function(url, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = tag.getByUrl(url, options);
callback.handle(promise, callbackFn);
return promise;
},
/**
* Gets tags given image bytes
* @method getTagsByImageBytes
* @param {String} image bytes Base64 encoded image bytes.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} model The model used to tag the image (optional)
* @param {String} language The language used to tag the image (optional)
* @param {String} or {Array} selectClasses Restrict the tags returned
* @param {String} or {Array} localId Provide a localId for each url to simplify tracking requests (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getTagsByImageBytes: function(imageBytes, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = tag.getByImageBytes(imageBytes, options);
callback.handle(promise, callbackFn);
return promise;
},
/**
* Gets API info
* @method getInfo
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getInfo: function(_callback) {
var promise = info.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Gets languages supported by the API
* @method getLanguages
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getLanguages: function(_callback) {
var promise = languages.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Gets colors given a url
* @method getColorByUrl
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getColorsByUrl: function(url, _callback) {
var promise = color.getByUrl(url);
callback.handle(promise, _callback);
return promise;
},
/**
* Gets colors given image bytes
* @method getColorsByImageBytes
* @param {String} url A publicly accessible url of the image.
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getColorsByImageBytes: function(imageBytes, _callback) {
var promise = color.getByImageBytes(imageBytes);
callback.handle(promise, _callback);
return promise;
},
/**
* Gets API usage
* @method getUsage
* @param {Function} callback A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
getUsage: function(_callback) {
var promise = usage.get();
callback.handle(promise, _callback);
return promise;
},
/**
* Provide feedback for a url or list of urls
* @method createFeedback
* @param {String} or {Array} url A publicly accessible url of the image.
* @param {Object} options Object with keys explained below: (optional)
* @param {String} or {Array} addTags Add additional tags that are relevant to the given image(s) (optional)
* @param {String} or {Array} removeTags Remove tags that are not relevant to the given image(s) (optional)
* @param {String} or {Array} similarUrls Tell the system two or more images are similar (optional)
* @param {String} or {Array} disSimilarUrls Tell the system two or more images are dissimilar (optional)
* @param {String} or {Array} searchClick Tell the system that the search result was relevant to the query (optional)
* @param {Function} A node-style calback function that accepts err, token (optional)
* @return {Promise(token, error} A Promise that is fulfilled with the API response or rejected with an error
*/
createFeedback: function(url, options, _callback) {
var callbackFn = _callback;
if ( typeof options === 'function' ) {
callbackFn = options;
};
var promise = feedback.create(url, options);
callback.handle(promise, callbackFn);
return promise;
}
App,
GENERAL_MODEL: "aaa03c23b3724a16a56b629203edc62c",
FOOD_MODEL: "bd367be194cf45149e75f01d59f77ba7",
TRAVEL_MODEL: "eee28c313d69466f836ab83287a54ed9",
NSFW_MODEL: "e9576d86d2004ed1a38ba0cf39ecb4b1",
WEDDINGS_MODEL: "c386b7a870114f4a87477c0824499348",
COLOR_MODEL: "eeed0b6733a644cea07cf4c60f87ebb7",
CLUSTER_MODEL: "cccbe437d6e54e2bb911c6aa292fb072",
BLUR: "ddd9d34872ab32be9f0e3b2b98a87be2"
};
{
"name": "clarifai",
"version": "1.2.1",
"version": "2.0.7",
"description": "Official Clarifai Javascript SDK",

@@ -9,7 +9,15 @@ "main": "index.js",

"license": "Apache-2.0",
"scripts": {
"jsdoc": "jsdoc src/* -t node_modules/minami -d build/docs-$npm_package_version"
},
"dependencies": {
"axios": "0.9.1",
"es6-promise": "3.1.2"
"axios": "0.11.1",
"es6-promise": "3.1.2",
"form-data": "0.2.0"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.14.0",
"babelify": "^7.3.0",
"del": "2.0.2",

@@ -20,2 +28,3 @@ "envify": "3.4.0",

"gulp-awspublish": "3.0.1",
"gulp-babel": "^6.1.2",
"gulp-browserify": "0.5.1",

@@ -37,3 +46,5 @@ "gulp-concat": "2.6.0",

"gulp-webserver": "0.9.1",
"gulp-zip": "^3.2.0",
"gulp-zip": "3.2.0",
"jsdoc": "^3.4.1",
"minami": "^1.1.1",
"require-dir": "0.3.0",

@@ -40,0 +51,0 @@ "serve-static": "1.10.0"

# Clarifai JavaScript Client
The official JavaScript client for interacting with the [Clarifai API](https://developer.clarifai.com).
The official JavaScript client for interacting with the [Clarifai API](https://developer-preview.clarifai.com).

@@ -14,8 +14,7 @@ ## Basic Use

var Clarifai = require('clarifai');
var app = new Clarifai.App(
'{clientId}',
'{clientSecret}'
);
Clarifai.initialize({
'clientId': '{clientId}',
'clientSecret': '{clientSecret}'
});
```

@@ -26,235 +25,18 @@

```js
<script type="text/javascript" src="https://sdk.clarifai.com/js/clarifai-1.2.1.js"></script>
<script type="text/javascript" src="https://sdk.clarifai.com/js/clarifai-2.0.7.js"></script>
<script>
Clarifai.initialize({
'clientId': '{clientId}',
'clientSecret': '{clientSecret}'
});
var app = new Clarifai.App(
'{clientId}',
'{clientSecret}'
);
</script>
```
## Table of Contents
## Docs
#### Tag
Dive right into code examples to get up and running as quickly as possible with our [Quick Start](https://developer-preview.clarifai.com/quick-start/).
* [Get tags for an image via URL](#get-tags-for-an-image-via-url)
* [Get tags for an image via bytes](#get-tags-for-an-image-via-image-bytes)
* [Get tags for multiple images via url](#get-tags-for-multiple-images-via-url)
* [Get tags for an image via url passing in a model](#get-tags-for-an-image-via-url-passing-in-a-model)
* [Get tags for an image via url passing in a language](#get-tags-for-an-image-via-url-passing-in-a-language)
* [Get tags for an image via url and set a localId](#get-tags-for-an-image-via-url-and-set-a-localid)
* [Get tags for an image via url and restrict the tags returned](#get-tags-for-an-image-via-url-and-restrict-the-tags-returned)
Learn the basics — predicting the contents of an image, searching across a collection and creating your own models with our [Guide](https://developer-preview.clarifai.com/guide/).
#### Info
* [Get API info](#get-api-info)
#### Languages
* [Get supported languages](#get-supported-languages)
#### Color
* [Get colors for an image via url](#get-colors-for-an-image-via-url)
#### Usage
* [Get API usage](#get-api-usage)
#### Feedback
* [Send feedback to the API](#send-feedback-to-the-api)
#### Token
* [Get a token](#get-a-token)
* [Set a token](#set-a-token)
* [Delete a token](#delete-a-token)
#### Promises and Callbacks
* [Instructions](#promises-and-callbacks)
## Examples
### Tag
#### Get tags for an image via url
```js
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg').then(
handleResponse,
handleError
);
```
#### Get tags for multiple images via url
```js
Clarifai.getTagsByUrl([
'https://samples.clarifai.com/wedding.jpg',
'https://samples.clarifai.com/cookies.jpeg'
]).then(
handleResponse,
handleError
);
```
#### Get tags for an image via image bytes
```js
Clarifai.getTagsByImageBytes('R0lGODlhZAHIAPcAAKeno6Oinc3Do6iVeMe7o1ZEM...').then(
handleResponse,
handleError
);
```
#### Get tags for an image via url passing in a model
```js
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
'model': 'nsfw-v0.1'
}).then(
handleResponse,
handleError
);
```
#### Get tags for an image via url passing in a language
```js
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
'language': 'es'
}).then(
handleResponse,
handleError
);
```
#### Get tags for an image via url and set a localId
```js
Clarifai.getTagsByUrl('https://samples.clarifai.com/wedding.jpg', {
'localId': 'myLocalId'
}).then(
handleResponse,
handleError
);
```
#### Get tags for an image via url and restrict the tags returned
```js
Clarifai.getTagsByUrl(
'https://samples.clarifai.com/wedding.jpg',
{
'selectClasses': ['people', 'dress', 'wedding']
}
).then(
handleResponse,
handleError
);
```
### Info
#### Get API info
```js
Clarifai.getInfo().then(
handleResponse,
handleError
);
```
### Languages
#### Get supported languages
```js
Clarifai.getLanguages().then(
handleResponse,
handleError
);
```
### Color
#### Get colors for an image via url
```js
Clarifai.getColorsByUrl('https://samples.clarifai.com/wedding.jpg').then(
handleResponse,
handleError
);
```
#### Get colors for an image via image bytes
```js
Clarifai.getColorsByImageBytes('R0lGODlhZAHIAPcAAKeno6Oinc3Do6iVeMe7o1ZEM...').then(
handleResponse,
handleError
);
```
### Usage
#### Get API usage
```js
Clarifai.getUsage().then(
handleResponse,
handleError
);
```
### Feedback
#### Send feedback to the API
```js
Clarifai.createFeedback('https://samples.clarifai.com/wedding.jpg', {
'addTags': ['family', 'friends',],
'removeTags': ['military', 'protest'],
}).then(
handleResponse,
handleError
);
```
### Token
#### Get a token
**Note:** You should not have to call this directly in most cases. Any method that needs a token will call
it for you.
```js
Clarifai.getToken().then(
function(response) {
console.log(response);
},
function(err){
console.log(err);
}
);
```
#### Set a token
```js
var tokenSetBoolean = Clarifai.setToken('some-token-string');
```
#### Delete a token
```js
Clarifai.deleteToken();
```
### Promises and Callbacks
All methods return promises. If you'd rather user callbacks, just pass in a callback function as the last
param to any method. If there are multiple params and some are optional, you'll need to pass in `null` for
those.
Looking for a different client? We have many languages available with lots of documentation [API Reference](https://developer-preview.clarifai.com/reference/)

@@ -1,2 +0,5 @@

var Clarifai = require('./../index.js');
var fs = require('fs');
var Clarifai = require('./../index');
var Models = require('./../src/Models');
var Inputs = require('./../src/Inputs');
var imageBytes = require('./image-bytes');

@@ -7,19 +10,26 @@

var sampleImage3 = 'https://samples.clarifai.com/cookies.jpeg';
var app;
function generateRandomId() {
return Math.floor(Math.random() * 1000000);
}
describe('Clarifai JS SDK', function() {
beforeAll(function() {
Clarifai.initialize({
'clientId': process.env.CLIENT_ID,
'clientSecret': process.env.CLIENT_SECRET
});
app = new Clarifai.App(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
{
'apiEndpoint': process.env.API_ENDPOINT
}
);
});
describe('Token', function() {
it('Gets a token as a string', function(done) {
Clarifai.getToken().then(
app._config.token().then(
function(response) {
expect(response).toEqual(jasmine.any(String));
expect(response['access_token']).toEqual(jasmine.any(String));
done();

@@ -30,3 +40,3 @@ },

});
it('Sets a token with an object', function(done) {

@@ -39,19 +49,19 @@ var token = {

};
var tokenSet = Clarifai.setToken(token);
Clarifai.getToken().then(
function(response) {
expect(tokenSet).toEqual(true);
expect(response).toEqual(jasmine.any(String));
done();
},
errorHandler.bind(done)
);
});
var tokenSet = app.setToken(token);
app._config.token().then(
function(response) {
expect(tokenSet).toEqual(true);
expect(response['access_token']).toEqual(jasmine.any(String));
done();
},
errorHandler.bind(done)
);
});
it('Sets a token with a string', function(done) {
var tokenSet = Clarifai.setToken('foo');
Clarifai.getToken().then(
var tokenSet = app.setToken('foo');
app._config.token().then(
function(response) {
expect(tokenSet).toEqual(true);
expect(response).toEqual(jasmine.any(String));
expect(response['access_token']).toEqual(jasmine.any(String));
done();

@@ -62,30 +72,219 @@ },

});
it('Deletes a token', function() {
Clarifai.deleteToken();
});
});
describe('Tag', function() {
it('Gets tags for an image via url', function(done) {
Clarifai.getTagsByUrl(sampleImage2).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
done();
},
errorHandler.bind(done)
);
});
it('Gets tags for multiple images via url', function(done) {
Clarifai.getTagsByUrl([
sampleImage2,
sampleImage3
describe('Inputs', function() {
var id = 'test-id' + generateRandomId();
it('Adds an input', function(done) {
app.inputs.create([
{
"url": "https://samples.clarifai.com/metro-north.jpg",
"id": id
}
]).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs instanceof Inputs).toBe(true);
expect(inputs.length).toBe(1);
expect(inputs[0].createdAt).toBeDefined();
expect(inputs[0].id).toBeDefined();
expect(inputs[0].toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
var id2 = 'test-id' + generateRandomId();
it('Adds an input with tags', function(done) {
app.inputs.create([
{
"url": "https://samples.clarifai.com/metro-north.jpg",
"id": id2,
"concepts": [
{
"id": "train",
"value": true
},
{
"id": "car",
"value": false
}
]
}
]).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs instanceof Inputs).toBe(true);
expect(inputs.length).toBe(1);
expect(inputs[0].createdAt).toBeDefined();
expect(inputs[0].id).toBeDefined();
expect(inputs[0].toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
var id3 = 'test-id' + generateRandomId();
var id4 = 'test-id' + generateRandomId();
it('Bulk adds inputs', function(done) {
app.inputs.create([
{
"url": "https://samples.clarifai.com/metro-north.jpg",
"id": id3
},
{
"url": "https://samples.clarifai.com/dog.tiff",
"id": id4
}
]).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs instanceof Inputs).toBe(true);
expect(inputs.length).toBe(2);
expect(inputs[0].createdAt).toBeDefined();
expect(inputs[0].id).toBeDefined();
expect(inputs[0].toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
var id5 = 'test-id' + generateRandomId();
var id6 = 'test-id' + generateRandomId();
it('Bulk adds inputs with tags', function(done) {
app.inputs.create([
{
"url": "http://i.imgur.com/HEoT5xR.png",
"id": id5,
"concepts": [
{
"id": "ferrari",
"value": true
},
{
"id": "outdoors"
}
]
},
{
"url": "http://i.imgur.com/It5JRaj.jpg",
"id": id6,
"concepts": [
{
"id": "ferrari",
"value": true
},
{
"id": "outdoors",
"value": false
}
]
}
]).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs instanceof Inputs).toBe(true);
expect(inputs.length).toBe(2);
expect(inputs[0].createdAt).toBeDefined();
expect(inputs[0].id).toBeDefined();
expect(inputs[0].toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
it('Gets all inputs', function(done) {
app.inputs.list({
'page': 1,
'perPage': 5
}).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs instanceof Inputs).toBe(true);
expect(inputs.length).toBe(5);
var input = inputs[0];
expect(input.id).toBeDefined();
expect(input.createdAt).toBeDefined();
expect(input.toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
it('Gets a single input by id', function(done) {
app.inputs.get(id).then(
function(input) {
expect(input).toBeDefined();
expect(input.id).toBe(id);
expect(input.createdAt).toBeDefined();
expect(input.toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
it('Gets inputs status', function(done) {
app.inputs.getStatus().then(
function(response) {
expect(response.counts).toBeDefined();
var counts = response.counts;
expect(counts.processed).toBeDefined();
expect(counts.to_process).toBeDefined();
expect(counts.errors).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
it('Updates an input', function(done) {
app.inputs.mergeConcepts([
{
id,
concepts: [
{ "id":"train", "value": true },
{ "id":"car", "value": false }
]
}
]).then(
function(inputs) {
expect(inputs).toBeDefined();
expect(inputs.length).toBe(1);
expect(inputs instanceof Inputs).toBe(true);
expect(inputs[0].createdAt).toBeDefined();
expect(inputs[0].id).toBeDefined();
expect(inputs[0].toObject().data).toBeDefined();
done();
},
errorHandler.bind(done)
);
});
});
describe('Models', function() {
var testModel;
var generalModel;
var generalModelId;
it('Creates a new model', function(done) {
app.models.create('vroom-vroom', [
{
'id': 'ferrari'
}
]).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(2);
function(model) {
expect(model).toBeDefined();
expect(model.name).toBeDefined();
expect(model.id).toBeDefined();
testModel = model;
expect(model.createdAt).toBeDefined();
expect(model.appId).toBeDefined();
expect(model.outputInfo).toBeDefined();
expect(model.modelVersion).toBeDefined();
done();

@@ -96,8 +295,13 @@ },

});
it('Gets tags for an image via bytes', function(done) {
Clarifai.getTagsByImageBytes(imageBytes).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
it('Creates a new model version', function(done) {
testModel.train().then(
function(model) {
expect(model).toBeDefined();
expect(model.modelVersion).toBeDefined();
expect(model.toObject()).toBeDefined();
var version = model.modelVersion;
expect(version.id).toBeDefined();
expect(version.created_at).toBeDefined();
done();

@@ -108,11 +312,13 @@ },

});
it('Get tags for an image via url passing in a model', function(done) {
Clarifai.getTagsByUrl(sampleImage2, {
'model': 'nsfw-v0.1'
}).then(
function(response) {
expect(response.meta.tag.model).toBe('nsfw-v0.1');
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
it('Creates a new model version and returns after it has finished', function(done) {
testModel.train(true).then(
function(model) {
expect(model).toBeDefined();
expect(model.modelVersion).toBeDefined();
expect(model.toObject()).toBeDefined();
var version = model.modelVersion;
expect(version.id).toBeDefined();
expect(version.created_at).toBeDefined();
expect(version.status.code).toBe(21100);
done();

@@ -123,11 +329,17 @@ },

});
it('Get tags for an image via url passing in a language', function(done) {
Clarifai.getTagsByUrl(sampleImage2, {
'language': 'es'
}).then(
function(response) {
expect(response.results[0].result.tag.classes[0]).toBe('ceremonia');
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
it('Searches for a model', function(done) {
app.models.search('vroom-vroom').then(
function(models) {
expect(models).toBeDefined();
var model = models[0];
expect(model).toBeDefined();
expect(model.name).toBe('vroom-vroom');
expect(model.id).toBeDefined();
generalModelId = model.id;
generalModel = model;
expect(model.createdAt).toBeDefined();
expect(model.appId).toBeDefined();
expect(model.outputInfo).toBeDefined();
expect(model.modelVersion).toBeDefined();
done();

@@ -138,25 +350,23 @@ },

});
it('Get tags for an image via url and set a localId', function(done) {
Clarifai.getTagsByUrl(sampleImage2, {
'localId': 'myLocalId'
}).then(
function(response) {
expect(response.results[0].local_id).toBe('myLocalId');
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
done();
it('Call predict on models collection giving a model id', function(done) {
app.models.predict(generalModelId, [
{
'url': 'http://www.ramtrucks.com/assets/towing_guide/images/before_you_buy/truck.png'
},
errorHandler.bind(done)
);
});
it('Get tags for an image via url and restrict the tags returned', function(done) {
Clarifai.getTagsByUrl(sampleImage2, {
'selectClasses': ['people', 'wedding']
}).then(
{
'url': 'http://www.planwallpaper.com/static/images/ferrari-9.jpg'
}
]).then(
function(response) {
expect(response.results[0].result.tag.classes.length).toBe(2);
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
expect(response.data.outputs).toBeDefined();
var outputs = response.data.outputs;
expect(outputs.length).toBe(2);
var output = outputs[0];
expect(output.id).toBeDefined();
expect(output.status).toBeDefined();
expect(output.input).toBeDefined();
expect(output.model).toBeDefined();
expect(output.created_at).toBeDefined();
expect(output.data).toBeDefined();
done();

@@ -167,39 +377,23 @@ },

});
});
describe('Info', function() {
it('Gets info from the API', function(done) {
Clarifai.getInfo().then(
function(response) {
expect(response.status_code).toBe('OK');
expect(response.results.max_image_size).toBeDefined();
expect(response.results.default_language).toBeDefined();
expect(response.results.max_video_size).toBeDefined();
expect(response.results.max_image_bytes).toBeDefined();
expect(response.results.min_image_size).toBeDefined();
expect(response.results.default_model).toBeDefined();
expect(response.results.max_video_bytes).toBeDefined();
expect(response.results.max_video_duration).toBeDefined();
expect(response.results.max_batch_size).toBeDefined();
expect(response.results.max_video_batch_size).toBeDefined();
expect(response.results.min_video_size).toBeDefined();
expect(response.results.api_version).toBeDefined();
done();
it('Attaches model outputs', function(done) {
generalModel.predict([
{
'url': 'http://www.ramtrucks.com/assets/towing_guide/images/before_you_buy/truck.png'
},
errorHandler.bind(done)
);
});
});
describe('Usage', function() {
it('Gets usage from the API', function(done) {
Clarifai.getUsage().then(
{
'url': 'http://www.planwallpaper.com/static/images/ferrari-9.jpg'
}
]).then(
function(response) {
expect(response.status_code).toBe('OK');
expect(response.results.user_throttles).toBeDefined();
expect(response.results.app_throttles).toBeDefined();
expect(response.data.outputs).toBeDefined();
var outputs = response.data.outputs;
expect(outputs.length).toBe(2);
var output = outputs[0];
expect(output.id).toBeDefined();
expect(output.status).toBeDefined();
expect(output.input).toBeDefined();
expect(output.model).toBeDefined();
expect(output.created_at).toBeDefined();
expect(output.data).toBeDefined();
done();

@@ -210,12 +404,15 @@ },

});
});
describe('Languages', function() {
it('Gets languages from the API', function(done) {
Clarifai.getLanguages().then(
function(response) {
expect(response.status_code).toBe('OK');
expect(response.languages).toBeDefined();
describe('Search', function() {
it('Filter by images/inputs only', function(done) {
app.inputs.search([
{
'url': 'https://samples.clarifai.com/metro-north.jpg'
}
]).then(
function(inputs) {
expect(inputs instanceof Inputs).toBe(true);
expect(inputs[0].score).toBeDefined();
done();

@@ -226,28 +423,15 @@ },

});
});
describe('Color', function() {
it('Gets color for an image via url', function(done) {
Clarifai.getColorsByUrl(sampleImage2).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
expect(response.results[0].colors).toBeDefined();
done();
it('Filter by concepts/inputs only', function(done) {
app.inputs.search([
{
'url': 'https://samples.clarifai.com/metro-north.jpg'
},
errorHandler.bind(done)
);
});
it('Gets color for multiple images via url', function(done) {
Clarifai.getColorsByUrl([
sampleImage2,
sampleImage3
{
"url": "https://samples.clarifai.com/dog.tiff",
}
]).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(2);
expect(response.results[0].colors).toBeDefined();
function(inputs) {
expect(inputs instanceof Inputs).toBe(true);
expect(inputs[0].score).toBeDefined();
done();

@@ -258,35 +442,22 @@ },

});
it('Gets color for an image via bytes', function(done) {
Clarifai.getColorsByImageBytes(imageBytes).then(
function(response) {
expect(response.status_msg).toBe('All images in request have completed successfully. ');
expect(response.results.length).toBe(1);
expect(response.results[0].colors).toBeDefined();
done();
it('Filter by images and concepts', function(done) {
var val = app.inputs.search([
{
'url': 'https://samples.clarifai.com/metro-north.jpg'
},
errorHandler.bind(done)
);
});
});
describe('Feedback', function() {
it('Sends feedback to the API', function(done) {
Clarifai.createFeedback(sampleImage, {
'addTags': ['snow', 'evening',],
'removeTags': ['road', 'business'],
}).then(
function(response) {
expect(response.status_code).toBe('OK');
expect(response.status_msg).toBe('Feedback successfully recorded. ');
{
'name': 'ferrari'
}
]);
val.then(
function(inputs) {
expect(inputs instanceof Inputs).toBe(true);
expect(inputs[0].score).toBeDefined();
done();
},
errorHandler.bind(done)
);
)
});
});
});

@@ -300,2 +471,3 @@

function errorHandler(err) {
console.log(err);
expect(err).toBe(true);

@@ -307,2 +479,2 @@ this();

console.log(JSON.stringify(obj, null, 2));
}
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc