Comparing version 1.0.34 to 1.0.35
export = Client; | ||
declare class Client { | ||
constructor(model: string, token: string, gpu?: boolean, lang?: string); | ||
constructor(model: string, token: string, gpu?: boolean, lang?: string, asynchronous?: boolean); | ||
headers: { | ||
@@ -33,3 +33,21 @@ Authorization: string; | ||
}; | ||
} | { | ||
status: number; | ||
statusText: string; | ||
data: { | ||
url: string; | ||
} | ||
}>; | ||
asyncResult(url: string): Promise<{ | ||
status: number; | ||
statusText: string; | ||
data: { | ||
created_on: string; | ||
finished_on: string; | ||
request_body: string; | ||
http_code: number; | ||
error_detail: string; | ||
content: string; | ||
}; | ||
}>; | ||
chatbot(input: string, context: string, history: { input: string, response: string }[]): Promise<{ | ||
@@ -151,2 +169,8 @@ status: number; | ||
}; | ||
} | { | ||
status: number; | ||
statusText: string; | ||
data: { | ||
url: string; | ||
} | ||
}>; | ||
@@ -197,2 +221,8 @@ question(context: string, question: string): Promise<{ | ||
}; | ||
} | { | ||
status: number; | ||
statusText: string; | ||
data: { | ||
url: string; | ||
} | ||
}>; | ||
@@ -199,0 +229,0 @@ translation(text: string, source: string, target: string): Promise<{ |
27
index.js
@@ -7,3 +7,3 @@ const axios = require('axios') | ||
class Client { | ||
constructor(model, token, gpu = false, lang = '') { | ||
constructor(model, token, gpu = false, lang = '', asynchronous = false) { | ||
this.headers = { | ||
@@ -14,2 +14,4 @@ 'Authorization': 'Token ' + token, | ||
this.rootURL = BASE_URL + '/' + API_VERSION + '/' | ||
if (lang == 'en') { | ||
@@ -19,14 +21,15 @@ lang = '' | ||
if (gpu && lang != '') { | ||
this.rootURL = BASE_URL + '/' + API_VERSION + '/gpu/' + lang + '/' + model | ||
if (gpu) { | ||
this.root_url += 'gpu/' | ||
} | ||
else if (gpu && lang == '') { | ||
this.rootURL = BASE_URL + '/' + API_VERSION + '/gpu/' + model | ||
if (lang != '') { | ||
this.root_url += lang + '/' | ||
} | ||
else if (!gpu && lang != '') { | ||
this.rootURL = BASE_URL + '/' + API_VERSION + '/' + lang + '/' + model | ||
if (asynchronous) { | ||
this.root_url += "async/" | ||
} | ||
else { | ||
this.rootURL = BASE_URL + '/' + API_VERSION + '/' + model | ||
} | ||
this.root_url += model | ||
} | ||
@@ -59,2 +62,6 @@ | ||
asyncResult(url) { | ||
return axios.get(url, { headers: this.headers }) | ||
} | ||
chatbot(input, context = null, history = null) { | ||
@@ -61,0 +68,0 @@ const payload = { |
{ | ||
"name": "nlpcloud", | ||
"version": "1.0.34", | ||
"version": "1.0.35", | ||
"description": "NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, paraphrasing, text generation, image generation, blog post generation, code generation, question answering, automatic speech recognition, machine translation, language detection, semantic search, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API.\n\nThis is the Node.js client for the NLP Cloud API.\n\nMore details here: https://nlpcloud.io\n\nDocumentation: https://docs.nlpcloud.io", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -152,2 +152,16 @@ # Node.js Client For NLP Cloud | ||
If you want to make asynchronous requests, pass `true` as the 4th argument. | ||
```js | ||
const NLPCloudClient = require('nlpcloud'); | ||
const client = new NLPCloudClient("<model>", "<your token>", false, '<your language code>', true) | ||
``` | ||
If you are making asynchronous requests, you will always receive a quick response containing a URL. You should then poll this URL with `asyncResult()` on a regular basis (every 10 seconds for example) in order to check if the result is available. Here is an example: | ||
```js | ||
client.asyncResult("https://api.nlpcloud.io/v1/get-async-result/21718218-42e8-4be9-a67f-b7e18e03b436") | ||
``` | ||
### Ad Generation and Product Description Generation Endpoint | ||
@@ -154,0 +168,0 @@ |
34142
486
401