|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 12 | +class GrammaticalCorrection { |
| 13 | + constructor(access_token) { |
| 14 | + this.getGrammaticalCorrection = (text) => __awaiter(this, void 0, void 0, function* () { |
| 15 | + try { |
| 16 | + // Make the GET request using fetch |
| 17 | + const response = yield fetch("https://api.ai21.com/studio/v1/gec", { |
| 18 | + headers: { |
| 19 | + "Authorization": `Bearer ${this.access_token}`, |
| 20 | + "Content-Type": "application/json" |
| 21 | + }, |
| 22 | + body: JSON.stringify({ |
| 23 | + "text": text |
| 24 | + }), |
| 25 | + method: "POST" |
| 26 | + }); |
| 27 | + // Parse the JSON response |
| 28 | + const data = yield response.json(); |
| 29 | + // Return the data |
| 30 | + return data; |
| 31 | + } |
| 32 | + catch (error) { |
| 33 | + // Handle errors that occurred during the fetch call |
| 34 | + console.error('An error occurred while fetching data'); |
| 35 | + return 'An error occurred while fetching data'; |
| 36 | + } |
| 37 | + }); |
| 38 | + this.access_token = access_token; |
| 39 | + } |
| 40 | +} |
| 41 | +exports.default = GrammaticalCorrection; |
| 42 | +// import requests |
| 43 | +// fetch("https://api.ai21.com/studio/v1/paraphrase", { |
| 44 | +// headers: { |
| 45 | +// "Authorization": "Bearer YOUR_API_KEY", |
| 46 | +// "Content-Type": "application/json" |
| 47 | +// }, |
| 48 | +// body: JSON.stringify({ |
| 49 | +// "text": "Throughout this page, we will explore the advantages and features of the Paraphrase API." |
| 50 | +// }), |
| 51 | +// method: "POST" |
| 52 | +// }); |
0 commit comments