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

@conversationai/perspectiveapi-js-client

Package Overview
Dependencies
Maintainers
10
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conversationai/perspectiveapi-js-client

A Javascript client for the Perspective API

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
10
Created
Source

perspectiveapi-js-client

A simple example JS/TS client library for the Perspective API. This client can be used to send text to the API and get back the scores for a set of model attributes.

Usage

This libray is published on npm as @conversationai/perspectiveapi-js-client.

To use it, you'll first need an API key from ConversationAI's Perspective API. Then you can use the library like this:

const { Client } = require("@conversationai/perspectiveapi-js-client");
const client = new Client(YOUR_API_KEY);
const results = client.getScores(text, options);

Methods

This client exposes one method, getScores.

getScores(text, options);

Parameters

text (Required)

A string between 1 and 3000 characters representing a piece of text (e.g. a comment on an article) to be analyzed by Perspective API.

options

An optional object that specifies options for the API.

Accepted keys in the options object are:

FieldDescription
context.entriesA list of objects providing the context for text. Defaults to null, equivalent to an empty list.
context.entries[].textThe text of a context object.
attributesAn array of strings specifying the attributes to get scores for. See the Perspective docs for a list of available attributes. Default: ["SPAM", "TOXICITY"]
languagesA list of ISO 631-1 two-letter language codes specifying the language(s) that text is in (for example, "en", "es", "fr", etc). Default: ["EN"]
doNotStoreWhether the API is permitted to store text and context from this request. Default: true
stripHtmlA boolean specifying whether to strip html tags from text. Default: true

Return Value

A promise that rejects with an Error object containing a message property specifying the error, or resolves to an object of attribute scores of the shape [attribute: string]: number, where the number is a float between 0 and 1. Here's an example result:

{
  TOXICITY: 0.65,
  SPAM: 0.25
}

The above result would mean that the Perspective API suggests the text is 65% likely to be toxic and 25% likely to be spam.

Tests

Run yarn test to run the test suite.

FAQs

Package last updated on 19 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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