apollo-ai-api-client
Advanced tools
Comparing version 0.1.27 to 0.2.0
@@ -39,3 +39,2 @@ export interface IAutoAbstractResponse { | ||
language?: ClusteringLanguage; | ||
skipAbstract?: boolean; | ||
} | ||
@@ -69,4 +68,4 @@ export interface IContinuesClusteringInput { | ||
autoabstract(headline: string, text: string, maxCharacters?: number, keywords?: string[], maxSentences?: number, debug?: boolean): Promise<IAutoAbstractResponse>; | ||
clustering(articles: IClusteringArticle[], threshold?: number, language?: ClusteringLanguage): Promise<IClusteringResponse>; | ||
continuedClustering(newArticles: IArticle[] | string[], presentArticles?: IContinuesClusteringResultItem[], options?: IContinuesClusteringOptions): Promise<any>; | ||
clustering(articles: IClusteringArticle[], threshold?: number, language?: ClusteringLanguage): Promise<IClusteringResponse[]>; | ||
continuedClustering(newArticles: IArticle[] | string[], presentArticles?: IContinuesClusteringResultItem[], options?: IContinuesClusteringOptions): Promise<IClusteringResponse[]>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,99 +19,91 @@ const node_fetch_1 = require("node-fetch"); | ||
executeAutoabstract(body, debug = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield node_fetch_1.default(this.apolloApiEndpoint + this.autoAbstractEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(Object.assign({ debug }, body)), | ||
}); | ||
return node_fetch_1.default(this.apolloApiEndpoint + this.autoAbstractEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(Object.assign({ debug }, body)), | ||
}).then((response) => { | ||
if (response.status !== 200) { | ||
throw Error('Received invalid response from autoabstract endpoint'); | ||
return Promise.reject({ message: 'Received invalid response from autoabstract endpoint', error: response.text() }); | ||
} | ||
return yield response.json(); | ||
}); | ||
} | ||
autoabstractUrl(url, maxCharacters = 400, keywords, maxSentences, debug) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const body = { | ||
url, | ||
keywords: keywords ? keywords.join(',') : '', | ||
}; | ||
if (maxSentences) { | ||
body.maxSentences = maxSentences; | ||
} | ||
else { | ||
body.maxCharacters = maxCharacters; | ||
return response.json(); | ||
} | ||
return yield this.executeAutoabstract(body, debug); | ||
}).catch((err) => { | ||
return Promise.reject({ message: 'Received invalid response from autoabstract endpoint', error: err }); | ||
}); | ||
} | ||
autoabstractUrl(url, maxCharacters = 400, keywords, maxSentences, debug) { | ||
const body = { | ||
url, | ||
keywords: keywords ? keywords.join(',') : '', | ||
}; | ||
if (maxSentences) { | ||
body.maxSentences = maxSentences; | ||
} | ||
else { | ||
body.maxCharacters = maxCharacters; | ||
} | ||
return this.executeAutoabstract(body, debug); | ||
} | ||
autoabstract(headline, text, maxCharacters = 400, keywords, maxSentences, debug) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const body = { | ||
headline, | ||
text, | ||
keywords: keywords ? keywords.join(',') : '', | ||
}; | ||
if (maxSentences) { | ||
body.maxSentences = maxSentences; | ||
} | ||
else { | ||
body.maxCharacters = maxCharacters; | ||
} | ||
return yield this.executeAutoabstract(body, debug); | ||
}); | ||
const body = { | ||
headline, | ||
text, | ||
keywords: keywords ? keywords.join(',') : '', | ||
}; | ||
if (maxSentences) { | ||
body.maxSentences = maxSentences; | ||
} | ||
else { | ||
body.maxCharacters = maxCharacters; | ||
} | ||
return this.executeAutoabstract(body, debug); | ||
} | ||
clustering(articles, threshold = 0.8, language = ClusteringLanguage.de) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = new url_1.URL(this.apolloApiEndpoint + this.clusteringEndpoint); | ||
url.searchParams.append('threshold', threshold.toString()); | ||
url.searchParams.append('language', language); | ||
const collectionResult = yield node_fetch_1.default(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(articles), | ||
timeout: 300000, | ||
}); | ||
const clusterResult = yield collectionResult.json(); | ||
return clusterResult; | ||
}); | ||
const url = new url_1.URL(this.apolloApiEndpoint + this.clusteringEndpoint); | ||
url.searchParams.append('threshold', threshold.toString()); | ||
url.searchParams.append('language', language); | ||
return node_fetch_1.default(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(articles), | ||
timeout: 300000, | ||
}).then((clusteringResult) => clusteringResult.json()); | ||
} | ||
continuedClustering(newArticles, presentArticles = [], options = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const parameters = { newArticles }; | ||
if (presentArticles && presentArticles.length > 0) { | ||
parameters.result = presentArticles; | ||
} | ||
const url = new url_1.URL(this.apolloApiEndpoint + this.combinedApiEndpoint); | ||
if (options.abstractMaxChars !== undefined) { | ||
url.searchParams.append('maxChars', options.abstractMaxChars.toString()); | ||
} | ||
if (options.keywords) { | ||
url.searchParams.append('keywords', options.keywords.join(',')); | ||
} | ||
if (options.threshold !== undefined) { | ||
url.searchParams.append('threshold', options.threshold.toString()); | ||
} | ||
if (options.language) { | ||
url.searchParams.append('language', options.language); | ||
} | ||
const clusteringResult = yield node_fetch_1.default(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(parameters), | ||
timeout: 300000, | ||
}); | ||
return yield clusteringResult.json(); | ||
}); | ||
const parameters = { newArticles }; | ||
if (presentArticles && presentArticles.length > 0) { | ||
parameters.result = presentArticles; | ||
} | ||
const url = new url_1.URL(this.apolloApiEndpoint + this.combinedApiEndpoint); | ||
if (options.abstractMaxChars !== undefined) { | ||
url.searchParams.append('maxChars', options.abstractMaxChars.toString()); | ||
} | ||
if (options.keywords) { | ||
url.searchParams.append('keywords', options.keywords.join(',')); | ||
} | ||
if (options.threshold !== undefined) { | ||
url.searchParams.append('threshold', options.threshold.toString()); | ||
} | ||
if (options.language) { | ||
url.searchParams.append('language', options.language); | ||
} | ||
return node_fetch_1.default(url.toString(), { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Bearer ' + this.apiKey, | ||
}, | ||
body: JSON.stringify(parameters), | ||
timeout: 300000, | ||
}).then((clusteringResult) => clusteringResult.json()); | ||
} | ||
@@ -126,0 +110,0 @@ } |
{ | ||
"name": "apollo-ai-api-client", | ||
"version": "0.1.27", | ||
"version": "0.2.0", | ||
"description": "Client for the apollo.ai auto abstract api.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13592
186