-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
343 lines (258 loc) · 7.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
const axios = require('axios')
const BASE_URL = 'https://api.nlpcloud.io'
const API_VERSION = 'v1'
class Client {
constructor(params) {
var model = params.model
var token = params.token
var gpu = params.gpu ?? false
var lang = params.lang ?? ''
var async = params.async ?? false
this.headers = {
'Authorization': 'Token ' + token,
'User-Agent': 'nlpcloud-javascript-client'
}
this.rootURL = BASE_URL + '/' + API_VERSION + '/'
if (lang == 'en') {
lang = ''
}
if (lang == 'eng_Latn') {
lang = ''
}
if (gpu) {
this.rootURL += 'gpu/'
}
if (async) {
this.rootURL += "async/"
}
if (lang != '') {
this.rootURL += lang + '/'
}
this.rootURL += model
}
adGeneration(params) {
var keywords = params.keywords
const payload = {
'keywords': keywords
};
return axios.post(this.rootURL + '/' + 'ad-generation', payload, { headers: this.headers })
}
asr(params) {
var url = params.url ?? null
var encodedFile = params.encodedFile ?? null
var inputLanguage = params.inputLanguage ?? null
const payload = {
'url': url,
'encoded_file': encodedFile,
'input_language': inputLanguage
};
return axios.post(this.rootURL + '/' + 'asr', payload, { headers: this.headers })
}
asyncResult(params) {
var url = params.url
return axios.get(url, { headers: this.headers })
}
chatbot(params) {
var input = params.input
var context = params.context ?? null
var history = params.history ?? null
const payload = {
'input': input,
'context': context,
'history': history
};
return axios.post(this.rootURL + '/' + 'chatbot', payload, { headers: this.headers })
}
classification(params) {
var text = params.text
var labels = params.labels ?? null
var multiClass = params.multiClass ?? null
const payload = {
'text': text,
'labels': labels,
'multi_class': multiClass
};
return axios.post(this.rootURL + '/' + 'classification', payload, { headers: this.headers })
}
codeGeneration(params) {
var instruction = params.instruction
const payload = {
'instruction': instruction
};
return axios.post(this.rootURL + '/' + 'code-generation', payload, { headers: this.headers })
}
dependencies(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'dependencies', payload, { headers: this.headers })
}
embeddings(params) {
var sentences = params.sentences
const payload = {
'sentences': sentences
};
return axios.post(this.rootURL + '/' + 'embeddings', payload, { headers: this.headers })
}
entities(params) {
var text = params.text
var searchedEntity = params.searchedEntity ?? null
const payload = {
'text': text,
'searched_entity': searchedEntity
};
return axios.post(this.rootURL + '/' + 'entities', payload, { headers: this.headers })
}
generation(params) {
var text = params.text
var maxLength = params.maxLength ?? null
var lengthNoInput = params.lengthNoInput ?? null
var endSequence = params.endSequence ?? null
var removeInput = params.removeInput ?? null
var numBeams = params.numBeams ?? null
var numReturnSequences = params.numReturnSequences ?? null
var topK = params.topK ?? null
var topP = params.topP ?? null
var temperature = params.temperature ?? null
var repetitionPenalty = params.repetitionPenalty ?? null
var badWords = params.badWords ?? null
var removeEndSequence = params.removeEndSequence ?? null
const payload = {
'text': text,
'max_length': maxLength,
'length_no_input': lengthNoInput,
'end_sequence': endSequence,
'remove_input': removeInput,
'num_beams': numBeams,
'num_return_sequences': numReturnSequences,
'top_k': topK,
'top_p': topP,
'temperature': temperature,
'repetition_penalty': repetitionPenalty,
'bad_words': badWords,
'remove_end_sequence': removeEndSequence
};
return axios.post(this.rootURL + '/' + 'generation', payload, { headers: this.headers })
}
gsCorrection(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'gs-correction', payload, { headers: this.headers })
}
imageGeneration(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'image-generation', payload, { headers: this.headers })
}
intentClassification(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'intent-classification', payload, { headers: this.headers })
}
kwKpExtraction(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'kw-kp-extraction', payload, { headers: this.headers })
}
langdetection(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'langdetection', payload, { headers: this.headers })
}
paraphrasing(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'paraphrasing', payload, { headers: this.headers })
}
question(params) {
var question = params.question
var context = params.context ?? null
const payload = {
'question': question,
'context': context
};
return axios.post(this.rootURL + '/' + 'question', payload, { headers: this.headers })
}
semanticSearch(params) {
var text = params.text
var numResults = params.numResults ?? null
const payload = {
'text': text,
'num_results': numResults
};
return axios.post(this.rootURL + '/' + 'semantic-search', payload, { headers: this.headers })
}
semanticSimilarity(params) {
var sentences = params.sentences
const payload = {
'sentences': sentences
};
return axios.post(this.rootURL + '/' + 'semantic-similarity', payload, { headers: this.headers })
}
sentenceDependencies(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'sentence-dependencies', payload, { headers: this.headers })
}
sentiment(params) {
var text = params.text
var target = params.target ?? null
const payload = {
'text': text,
'target': target
};
return axios.post(this.rootURL + '/' + 'sentiment', payload, { headers: this.headers })
}
speechSynthesis(text, voice = null) {
var text = params.text
var voice = params.voice ?? null
const payload = {
'text': text,
'voice': voice
};
return axios.post(this.rootURL + '/' + 'speech-synthesis', payload, { headers: this.headers })
}
summarization(params) {
var text = params.text
var size = params.size ?? null
const payload = {
'text': text,
'size': size
};
return axios.post(this.rootURL + '/' + 'summarization', payload, { headers: this.headers })
}
tokens(params) {
var text = params.text
const payload = {
'text': text
};
return axios.post(this.rootURL + '/' + 'tokens', payload, { headers: this.headers })
}
translation(params) {
var text = params.text
var source = params.source ?? null
var target = params.target
const payload = {
'text': text,
'source': source,
'target': target
};
return axios.post(this.rootURL + '/' + 'translation', payload, { headers: this.headers })
}
}
module.exports = Client