watson-nlu-usage
Watson Natural Language Understanding (NLU) API usage module.
The absorption of Alchemy API by IBM Watson Developer Cloud into Watson NLU means usage information no longer comes back in API response headers. This module provides a way to get usage information using IBM Bluemix APIs instead.
Installation
npm install --save watson-nlu-usage
Usage
const WatsonNLUUsage = ;const watsonNLUUsage = username: 'user.with.audit.permissions@some.email.com' password: 'password-for-said-user' organizationName: 'some-bluemix-organization' spaceName: 'some-bluemix-space' serviceName: 'some-bluemix-service' instanceName: 'some-watson-nlu-instance' plan: 'free' // default region: 'us-south' // default; // Estimate the cost of a call to Watson NLU using the free planwatsonNLUUsage ; // Estimate the cost of a call to Watson NLU using the paid standard planwatsonNLUUsage ; // Get usage for the current monthwatsonNLUUsage ; // Get usage for the current month including free calls in the itemCountwatsonNLUUsage ; // Get usage for January 2017watsonNLUUsage ;
Bluemix setup
-
A Watson NLU instance. Follow their page to log into Bluemix and if you don't already have these, create the following: an
organization
containing aspace
containing aservice
containing a (Watson NLU)instance
. Keep track of the names of all those components and make sure you have added a user with at leastauditor
permissions. You will need that user's credentials to get usage information. -
You may also want to take note of the region for your organization. This module assumes
us-south
by default.
API
constructor
new WatsonNLUUsage(options) ==> watsonNLUUsage instance
-
options.username
: Username (email address) for user with audit access to the target instance. -
options.password
: Password for for user inoptions.username
. -
options.organizationName
: Bluemix organization name owning the target instance. -
options.spaceName
: Bluemix space name (owned byoptions.organizationName
) owning the target instance. -
options.serviceName
: Bluemix service name (owned byoptions.spaceName
) owning the target instance. -
options.instanceName
: Bluemix instance name for the target Watson NLU instance. -
options.plan (default: 'free')
: The Watson NLU planoptions.instanceName
is on. One of'free' | 'standard'
. -
options.region (default: 'us-south')
: The Bluemix region to use for API calls.
estimateCost
Estimates the cost (in items and money) of a call to Watson NLU API. This estimate has a crude way of looking at the size of the payload
and at worst over-estimates the cost since it does not take into account any cleaning the Watson NLU API may do to the payload
server-side before analyzing it. It also is set to read only the first 50kb of a payload
in keeping with the published limitations.
.estimateCost(options) ==> Promise(costEstimate)
-
options.payload
: Text payload for which to estimate the processing cost. -
options.featureCount (default: 1)
: The number of features to extract fromoptions.payload
(e.g. concepts and entities extraction are2
features). -
options.plan (default: 'free')
: One of'free' | 'standard'
. The plan to use when estimating the cost. If set to'standard'
it will gather the current month's usage and use it to bootstrap the estimate into the right cost tiers. -
options.includeFreeUsage (default: false)
: Include free usage calls (typically 1000 per day) incostEstimate.itemCost
. -
costEstimate.plan
: NLU plan used to estimate the cost ofoptions.payload
. -
costEstimate.itemCost
: Estimated number of NLU items incurred for extractingoptions.featureCount
features fromoptions.payload
. -
costEstimate.moneyCost
: Estimated$
cost of extractingcostEstimate.itemCost
.
getUsage
.getUsage(options) ==> Promise(usageStats)
-
options.month (default: current month, format: 'YYYY-MM' )
: Month to getusageStats
for. -
options.includeFreeUsage (default: true)
: Include free calls inusageStats.totalCost
. -
usageStats.itemCount
: The number of NLU items consumed in the month specified inoptions.month
. -
usageStats.totalCost
: The total cost for processingusageStats.itemCount
inoptions.month
.
Developing
npm installnpm run buildnpm run test