Class: NLPCloud::Client
- Inherits:
-
Object
- Object
- NLPCloud::Client
- Defined in:
- lib/nlpcloud.rb
Overview
Client requests the API.
Instance Method Summary collapse
- #ad_generation(keywords) ⇒ Object
- #asr(url: nil, encoded_file: nil, input_language: nil) ⇒ Object
- #async_result(url) ⇒ Object
- #chatbot(text, context: nil, history: nil) ⇒ Object
- #classification(text, labels: nil, multi_class: nil) ⇒ Object
- #code_generation(instruction) ⇒ Object
- #dependencies(text) ⇒ Object
- #embeddings(sentences) ⇒ Object
- #entities(text, searched_entity: nil) ⇒ Object
- #generation(text, max_length: nil, length_no_input: nil, end_sequence: nil, remove_input: nil, num_beams: nil, num_return_sequences: nil, top_k: nil, top_p: nil, temperature: nil, repetition_penalty: nil, bad_words: nil, remove_end_sequence: nil) ⇒ Object
- #gs_correction(text) ⇒ Object
- #image_generation(text) ⇒ Object
-
#initialize(model, token, gpu: false, lang: '', asynchronous: false) ⇒ Client
constructor
A new instance of Client.
- #intent_classification(text) ⇒ Object
- #kw_kp_extraction(text) ⇒ Object
- #langdetection(text) ⇒ Object
- #paraphrasing(text) ⇒ Object
- #question(question, context: nil) ⇒ Object
- #semantic_search(text, num_results: nil) ⇒ Object
- #semantic_similarity(sentences) ⇒ Object
- #sentence_dependencies(text) ⇒ Object
- #sentiment(text) ⇒ Object
- #speech_synthesis(text, voice: nil) ⇒ Object
- #summarization(text, size: nil) ⇒ Object
- #tokens(text) ⇒ Object
- #translation(text, source, target) ⇒ Object
Constructor Details
#initialize(model, token, gpu: false, lang: '', asynchronous: false) ⇒ Client
Returns a new instance of Client.
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 |
# File 'lib/nlpcloud.rb', line 12 def initialize(model, token, gpu: false, lang: '', asynchronous: false) @headers = { 'Authorization' => "Token #{token}", 'Content-Type' => 'application/json', 'User-Agent' => 'nlpcloud-ruby-client' } @root_url = "#{BASE_URL}/#{API_VERSION}/" if lang == "en" lang = "" end if lang == "eng_Latn" lang = "" end if gpu @root_url += "gpu/" end if asynchronous @root_url += "async/" end if lang != "" @root_url += lang + "/" end @root_url += model end |
Instance Method Details
#ad_generation(keywords) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/nlpcloud.rb', line 44 def ad_generation(keywords) payload = { 'keywords' => keywords } response = RestClient.post("#{@root_url}/ad-generation", payload.to_json, @headers) JSON.parse(response.body) end |
#asr(url: nil, encoded_file: nil, input_language: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/nlpcloud.rb', line 52 def asr(url: nil, encoded_file: nil, input_language: nil) payload = { 'url' => url, 'encoded_file' => encoded_file, 'input_language' => input_language } response = RestClient.post("#{@root_url}/asr", payload.to_json, @headers) JSON.parse(response.body) end |
#async_result(url) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/nlpcloud.rb', line 62 def async_result(url) response = RestClient.get(url, @headers) if response.body && !response.body.empty? JSON.parse(response.body) end end |
#chatbot(text, context: nil, history: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/nlpcloud.rb', line 70 def chatbot(text, context: nil, history: nil) payload = { 'text' => text, 'context' => context, 'history' => history } response = RestClient.post("#{@root_url}/chatbot", payload.to_json, @headers) JSON.parse(response.body) end |
#classification(text, labels: nil, multi_class: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/nlpcloud.rb', line 80 def classification(text, labels: nil, multi_class: nil) payload = { 'text' => text, 'labels' => labels, 'multi_class' => multi_class } response = RestClient.post("#{@root_url}/classification", payload.to_json, @headers) JSON.parse(response.body) end |
#code_generation(instruction) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/nlpcloud.rb', line 90 def code_generation(instruction) payload = { 'instruction' => instruction } response = RestClient.post("#{@root_url}/code-generation", payload.to_json, @headers) JSON.parse(response.body) end |
#dependencies(text) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/nlpcloud.rb', line 98 def dependencies(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/dependencies", payload.to_json, @headers) JSON.parse(response.body) end |
#embeddings(sentences) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/nlpcloud.rb', line 106 def (sentences) payload = { 'sentences' => sentences } response = RestClient.post("#{@root_url}/embeddings", payload.to_json, @headers) JSON.parse(response.body) end |
#entities(text, searched_entity: nil) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/nlpcloud.rb', line 114 def entities(text, searched_entity: nil) payload = { 'text' => text, 'searched_entity' => searched_entity } response = RestClient.post("#{@root_url}/entities", payload.to_json, @headers) JSON.parse(response.body) end |
#generation(text, max_length: nil, length_no_input: nil, end_sequence: nil, remove_input: nil, num_beams: nil, num_return_sequences: nil, top_k: nil, top_p: nil, temperature: nil, repetition_penalty: nil, bad_words: nil, remove_end_sequence: nil) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/nlpcloud.rb', line 123 def generation(text, max_length: nil, length_no_input: nil, end_sequence: nil, remove_input: nil, num_beams: nil, num_return_sequences: nil, top_k: nil, top_p: nil, temperature: nil, repetition_penalty: nil, bad_words: nil, remove_end_sequence: nil) payload = { 'text' => text, 'max_length' => max_length, 'length_no_input' => length_no_input, 'end_sequence' => end_sequence, 'remove_input' => remove_input, 'num_beams' => num_beams, 'num_return_sequences' => num_return_sequences, 'top_k' => top_k, 'top_p' => top_p, 'temperature' => temperature, 'repetition_penalty' => repetition_penalty, 'bad_words' => bad_words, 'remove_end_sequence' => remove_end_sequence } response = RestClient.post("#{@root_url}/generation", payload.to_json, @headers) JSON.parse(response.body) end |
#gs_correction(text) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/nlpcloud.rb', line 146 def gs_correction(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/gs-correction", payload.to_json, @headers) JSON.parse(response.body) end |
#image_generation(text) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/nlpcloud.rb', line 154 def image_generation(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/image-generation", payload.to_json, @headers) JSON.parse(response.body) end |
#intent_classification(text) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/nlpcloud.rb', line 162 def intent_classification(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/intent-classification", payload.to_json, @headers) JSON.parse(response.body) end |
#kw_kp_extraction(text) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/nlpcloud.rb', line 170 def kw_kp_extraction(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/kw-kp-extraction", payload.to_json, @headers) JSON.parse(response.body) end |
#langdetection(text) ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/nlpcloud.rb', line 178 def langdetection(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/langdetection", payload.to_json, @headers) JSON.parse(response.body) end |
#paraphrasing(text) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/nlpcloud.rb', line 186 def paraphrasing(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/paraphrasing", payload.to_json, @headers) JSON.parse(response.body) end |
#question(question, context: nil) ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/nlpcloud.rb', line 194 def question(question, context: nil) payload = { 'question' => question, 'context' => context } response = RestClient.post("#{@root_url}/question", payload.to_json, @headers) JSON.parse(response.body) end |
#semantic_search(text, num_results: nil) ⇒ Object
203 204 205 206 207 208 209 210 |
# File 'lib/nlpcloud.rb', line 203 def semantic_search(text, num_results: nil) payload = { 'text' => text, 'num_results' => num_results } response = RestClient.post("#{@root_url}/semantic_search", payload.to_json, @headers) JSON.parse(response.body) end |
#semantic_similarity(sentences) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/nlpcloud.rb', line 212 def semantic_similarity(sentences) payload = { 'sentences' => sentences } response = RestClient.post("#{@root_url}/semantic_similarity", payload.to_json, @headers) JSON.parse(response.body) end |
#sentence_dependencies(text) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/nlpcloud.rb', line 220 def sentence_dependencies(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/sentence-dependencies", payload.to_json, @headers) JSON.parse(response.body) end |
#sentiment(text) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/nlpcloud.rb', line 228 def sentiment(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/sentiment", payload.to_json, @headers) JSON.parse(response.body) end |
#speech_synthesis(text, voice: nil) ⇒ Object
236 237 238 239 240 241 242 243 |
# File 'lib/nlpcloud.rb', line 236 def speech_synthesis(text, voice: nil) payload = { 'text' => text, 'voice' => voice } response = RestClient.post("#{@root_url}/speech-synthesis", payload.to_json, @headers) JSON.parse(response.body) end |
#summarization(text, size: nil) ⇒ Object
245 246 247 248 249 250 251 252 |
# File 'lib/nlpcloud.rb', line 245 def summarization(text, size: nil) payload = { 'text' => text, 'size' => size } response = RestClient.post("#{@root_url}/summarization", payload.to_json, @headers) JSON.parse(response.body) end |
#tokens(text) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/nlpcloud.rb', line 254 def tokens(text) payload = { 'text' => text } response = RestClient.post("#{@root_url}/tokens", payload.to_json, @headers) JSON.parse(response.body) end |
#translation(text, source, target) ⇒ Object
262 263 264 265 266 267 268 269 270 |
# File 'lib/nlpcloud.rb', line 262 def translation(text, source, target) payload = { 'text' => text, 'source' => source, 'target' => target } response = RestClient.post("#{@root_url}/translation", payload.to_json, @headers) JSON.parse(response.body) end |