apollo-ai-api-client
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -46,3 +46,3 @@ export interface IAutoAbstractResponse { | ||
export interface IContinuousClustering { | ||
newArticles?: IArticle[] | string[]; | ||
newArticles?: Array<IArticle | string>; | ||
result?: IContinuousClusteringResultItem[]; | ||
@@ -77,6 +77,6 @@ } | ||
private executeAutoabstract; | ||
autoabstractUrl(url: string, maxCharacters?: number, keywords?: string[], maxSentences?: number, debug?: boolean): Promise<IAutoAbstractResponse>; | ||
autoabstractUrl(endpointUrl: string, maxCharacters?: number, keywords?: string[], maxSentences?: number, debug?: boolean): Promise<IAutoAbstractResponse>; | ||
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?: IContinuousClusteringResultItem[], options?: IContinuousClusteringOptions): Promise<IContinuousClusteringResponse>; | ||
continuedClustering(newArticles: Array<IArticle | string>, presentArticles?: IContinuousClusteringResultItem[], options?: IContinuousClusteringOptions): Promise<IContinuousClusteringResponse>; | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
const url_1 = require("url"); | ||
const _ = require("lodash"); | ||
var ClusteringLanguage; | ||
@@ -40,5 +41,5 @@ (function (ClusteringLanguage) { | ||
} | ||
autoabstractUrl(url, maxCharacters = 400, keywords, maxSentences, debug) { | ||
autoabstractUrl(endpointUrl, maxCharacters = 400, keywords, maxSentences, debug) { | ||
const body = { | ||
url, | ||
url: endpointUrl, | ||
keywords: keywords ? keywords.join(',') : '', | ||
@@ -69,6 +70,6 @@ }; | ||
clustering(articles, threshold = 0.8, language = ClusteringLanguage.de) { | ||
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(), { | ||
const endpointUrl = new url_1.URL(this.apolloApiEndpoint + this.clusteringEndpoint); | ||
endpointUrl.searchParams.append('threshold', threshold.toString()); | ||
endpointUrl.searchParams.append('language', language); | ||
return node_fetch_1.default(endpointUrl.toString(), { | ||
method: 'POST', | ||
@@ -89,2 +90,25 @@ headers: { | ||
} | ||
else { | ||
parameters.result = []; | ||
} | ||
const newArticleIds = newArticles.map((nA) => { | ||
if (typeof nA === 'string') { | ||
return nA; | ||
} | ||
else { | ||
return nA.id; | ||
} | ||
}); | ||
const presentArticleIds = presentArticles.map((pA, index) => { | ||
if (pA && pA.article && pA.article.id) { | ||
return pA.article.id; | ||
} | ||
else { | ||
throw new Error('Invalid present Article' + pA + ' at position ' + index); | ||
} | ||
}); | ||
const duplicates = _.intersection(newArticleIds, presentArticleIds); | ||
if (duplicates.length !== 0) { | ||
throw new Error('Passing the same article in newArticles and presentArticles is not allowed.'); | ||
} | ||
const url = new url_1.URL(this.apolloApiEndpoint + this.combinedApiEndpoint); | ||
@@ -112,3 +136,11 @@ if (options.abstractMaxChars !== undefined) { | ||
timeout: 300000, | ||
}).then((clusteringResult) => clusteringResult.json()); | ||
}).then((clusteringResult) => { | ||
return clusteringResult.json().catch((e) => { | ||
console.log(e); | ||
return Promise.reject(e); | ||
}); | ||
}, (error) => { | ||
console.log(error); | ||
return Promise.reject(error); | ||
}); | ||
} | ||
@@ -115,0 +147,0 @@ } |
{ | ||
"name": "apollo-ai-api-client", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Client for the apollo.ai auto abstract api.", | ||
@@ -29,9 +29,11 @@ "keywords": [ | ||
"dependencies": { | ||
"node-fetch": "^1.7.1" | ||
"lodash": "^4.17.11", | ||
"node-fetch": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.14", | ||
"@types/node-fetch": "^1.6.7", | ||
"tslint": "^5.4.3", | ||
"typescript": "^2.4.0" | ||
"@types/lodash": "^4.14.116", | ||
"@types/node": "^10.11.0", | ||
"@types/node-fetch": "^2.1.2", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.3" | ||
}, | ||
@@ -38,0 +40,0 @@ "engines": { |
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
16222
230
2
5
+ Addedlodash@^4.17.11
+ Addedlodash@4.17.21(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedencoding@0.1.13(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
Updatednode-fetch@^2.2.0