ai21-sdk
v1.0.3
Published
A npm package designed specializing in Natural Language Processing, which develops AI systems that can understand and generate natural language.
Downloads
22
Maintainers
Readme
ai21-sdk (An unofficial NPM package for AI21 Labs)
A npm package designed specializing in Natural Language Processing, which develops AI systems that can understand and generate natural language. AI21’s tools provide robust and flexible solutions for developers looking to integrate advanced language models into their applications.
About AI21 Labs
AI21 Labs is a leading company in the field of artificial intelligence, specifically in natural language processing (NLP) and generative AI. They develop advanced AI models and tools to assist in various tasks involving text understanding, generation, and manipulation. AI21's models are known for their high performance and capability to generate human-like text.
Main Functions
Text Generation: AI21 models can generate coherent and contextually relevant text based on a given prompt. This is useful for content creation, creative writing, and other applications requiring natural language generation.
Text Summarization: The models can summarize long pieces of text into shorter, more concise versions without losing the essential information.
Text Completion: Given the start of a sentence or paragraph, AI21 models can complete the text in a coherent manner.
Question Answering: These models can answer questions based on provided context or general knowledge.
How to Use
- Create an account and Sign In: https://studio.ai21.com/
- Go into the Profile and Click on API key. Copy the API key and we will use it to authenticate your account.
Installation
You can install this package using npm or yarn.
npm
npm i ai21-sdk
yarn
yarn add ai21-sdk
Usage
// Usage example
import Paraphrase from "ai21-sdk/dist/paraphrase";
import GrammaticalCorrection from "ai21-sdk/dist/grammaticalCorrection";
import TextImprovements from "ai21-sdk/dist/textImprovements";
import TextSegmentation from "ai21-sdk/dist/textSegmentation";
import ContextualAnswer from "ai21-sdk/dist/contextualAnswers";
const access_token = 'xxxxxxxxxxxxxxxxxx';
const paraphrase = new Paraphrase(access_token);
const grammaticalCorrection = new GrammaticalCorrection(access_token);
const textImprovements = new TextImprovements(access_token);
const textSegmentation = new TextSegmentation(access_token);
const contextualAnswer = new ContextualAnswer(access_token);
paraphrase.getParaphrase('I am Muhammad Usman & I am 30 years').then( result => console.log(result));
grammaticalCorrection.getGrammaticalCorrection('I Muhammad Usman I 30 years old').then( result => console.log(result));
textImprovements.getTextImprovements('I am Muhammad Usman and I 30 years old Pakstan', ["fluency"]).then( result => console.log(result));
textSegmentation.getTextSegmentation('https://www.nhs.uk/conditions/carpal-tunnel-syndrome/', 'URL').then( result => console.log(result));
contextualAnswer.getContextualAnswer('Something large text context', 'Did the economy shrink?').then( result => console.log(result));
Functions
| Function | Description | |---------|---------| | getParaphrase | Takes a piece of text and returns a list of paraphrases that convey the same meaning using different words. | | getGrammaticalCorrection | Detects grammar, spelling, punctuation, and word choice errors in text, and suggests how to correct them. | | getTextImprovements | Provides rewrite recommendations for improving the fluency, clarity and style of the input text. | | getTextSegmentation | Takes a document (raw text or URL) and returns segmentation into paragraphs by topic. | | getContextualAnswer | Receives a document and a question and returns an answer based entirely on the document context. |
Scripts
Build
To compile the TypeScript files to JavaScript, run:
npm run build
Test
To run tests, use:
npm run test
Configuration
TypeScript Configuration
This package uses a tsconfig.json
file for TypeScript configuration. Here is an example:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
},
}
Contributing
Support
LICENSE
This project is licensed under the MIT License - see the LICENSE file for details.