Package Exports
- perspective-api-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (perspective-api-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
perspective-api-client
NodeJS client library for the Perspective API.
Install
$ npm install perspective-api-clientUsage
const Perspective = require('perspective-api-client');
const perspective = new Perspective({apiKey: process.env.PERSPECTIVE_API_KEY});
(async () => {
const text = 'What kind of idiot name is foo? Sorry, I like your name.';
const result = await perspective.analyze(text, {doNotStore: true});
console.log(JSON.stringify(result, null, 2));
})();
// {
// "attributeScores": {
// "TOXICITY": {
// "spanScores": [
// {
// "begin": 0,
// "end": 56,
// "score": {
// "value": 0.8728314,
// "type": "PROBABILITY"
// }
// }
// ],
// "summaryScore": {
// "value": 0.8728314,
// "type": "PROBABILITY"
// }
// }
// },
// "languages": [
// "en"
// ]
// }Specifying models
The TOXICITY model is used by default. To specify additional models,
pass options.attributes.
(async () => {
const text = 'What kind of idiot name is foo? Sorry, I like your name.';
const result = await perspective.analyze(text, {attributes: ['toxicity', 'unsubstantial'], doNotStore: true});
console.log(JSON.stringify(result, null, 2));
})();
// {
// "attributeScores": {
// "TOXICITY": {
// ...
// }
// },
// "UNSUBSTANTIAL": {
// "spanScores": [
// {
// "begin": 0,
// "end": 32,
// "score": {
// "value": 0.72937065,
// "type": "PROBABILITY"
// }
// },
// {
// "begin": 32,
// "end": 56,
// "score": {
// "value": 0.8579436,
// "type": "PROBABILITY"
// }
// }
// ],
// "summaryScore": {
// "value": 0.6332942,
// "type": "PROBABILITY"
// }
// }
// },
// "languages": [
// "en"
// ]
// }More options
You can also pass an AnalyzeComment object for more control over the request.
(async () => {
const text = 'What kind of idiot name is foo? Sorry, I like your name.';
const result = await perspective.analyze({
comment: {text},
requestedAttributes: {TOXICITY: {scoreThreshold: 0.7}}
});
console.log(JSON.stringify(result, null, 2));
})();
// {
// "attributeScores": {
// "TOXICITY": {
// "spanScores": [
// {
// "begin": 0,
// "end": 56,
// "score": {
// "value": 0.8728314,
// "type": "PROBABILITY"
// }
// }
// ],
// "summaryScore": {
// "value": 0.8728314,
// "type": "PROBABILITY"
// }
// }
// },
// "languages": [
// "en"
// ]
// }API
perspective = new Perspective()
analyze(text, [options])
text
Type: String or Object
Either the text to analyze or an AnalyzeComment object.
options
attributes
Type: Array or Object
Model names to analyze. TOXICITY is analyzed by default. If passing an Array of names, the names may be lowercased.
See https://github.com/conversationai/perspectiveapi/blob/master/api_reference.md#models
for a list of valid models.
doNotStore
Type: Boolean
Default: false
Whether the API is permitted to store comment and context from this request.
License
MIT © Steven Loria