ibm_watson 1.6.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -382,6 +382,15 @@ if !ENV["ASSISTANT_APIKEY"].nil? && !ENV["ASSISTANT_URL"].nil?
382
382
  )
383
383
  assert(service_response.nil?)
384
384
  end
385
+
386
+ def test_bulk_classify
387
+ skip "Covered with the unit test. No need to run it here"
388
+
389
+ service_response = service.bulk_classify(
390
+ workspace_id: ENV["ASSISTANT_WORKSPACE_ID"]
391
+ )
392
+ assert(service_response.nil?)
393
+ end
385
394
  end
386
395
  else
387
396
  class AssistantV1Test < Minitest::Test
@@ -82,5 +82,14 @@ if !ENV["ASSISTANT_APIKEY"].nil? && !ENV["ASSISTANT_URL"].nil?
82
82
  )
83
83
  assert(service_response.nil?)
84
84
  end
85
+
86
+ def test_bulk_classify
87
+ skip "Covered with the unit test. No need to run it here"
88
+
89
+ service_response = service.bulk_classify(
90
+ skill_id: ENV["ASSISTANT_WORKSPACE_ID"]
91
+ )
92
+ assert(service_response.nil?)
93
+ end
85
94
  end
86
95
  end
@@ -120,6 +120,7 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
120
120
  )
121
121
  query_id = service_response.result["query_id"]
122
122
  refute(service_response.nil?)
123
+ # puts JSON.pretty_generate(service_response.result)
123
124
 
124
125
  service_response = service.get_training_query(
125
126
  project_id: @project_id,
@@ -134,6 +135,12 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
134
135
  examples: []
135
136
  )
136
137
  refute(service_response.nil?)
138
+
139
+ service_response = service.delete_training_query(
140
+ project_id: @project_id,
141
+ query_id: query_id
142
+ )
143
+ assert(service_response.nil?)
137
144
  end
138
145
 
139
146
  def test_create_get_update_delete_collection
@@ -238,6 +245,14 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
238
245
  assert(service_response.nil?)
239
246
  end
240
247
 
248
+ def test_query_collection_notices
249
+ service_response = service.query_collection_notices(
250
+ project_id: @project_id,
251
+ collection_id: @collection_id
252
+ )
253
+ refute(service_response.result.nil?)
254
+ end
255
+
241
256
  def test_delete_user_data
242
257
  skip "Covered with the unit test. No need to run it here"
243
258
 
@@ -246,6 +261,20 @@ if !ENV["DISCOVERY_V2_APIKEY"].nil?
246
261
  )
247
262
  assert(service_response.nil?)
248
263
  end
264
+
265
+ def test_analyze_document
266
+ skip "CPD only. Do not run on premium"
267
+ analyze_data = File.open(Dir.getwd + "/resources/problem.json")
268
+
269
+ service_response = service.analyze_document(
270
+ project_id: @project_id,
271
+ collection_id: @collection_id,
272
+ file: analyze_data,
273
+ file_content_type: "application/json"
274
+ )
275
+ assert((200..299).cover?(service_response.status))
276
+ refute(service_response.nil?)
277
+ end
249
278
  end
250
279
  else
251
280
  class DiscoveryV2Test < Minitest::Test
@@ -86,7 +86,7 @@ if !ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"].nil? && !ENV["NATURAL_LANGUAGE_
86
86
  end
87
87
 
88
88
  def test_list_models
89
- skip
89
+ # skip
90
90
  service.add_default_headers(
91
91
  headers: {
92
92
  "X-Watson-Learning-Opt-Out" => "1",
@@ -96,6 +96,139 @@ if !ENV["NATURAL_LANGUAGE_UNDERSTANDING_APIKEY"].nil? && !ENV["NATURAL_LANGUAGE_
96
96
  service_response = service.list_models
97
97
  assert((200..299).cover?(service_response.status))
98
98
  end
99
+
100
+ def test_check_orphands
101
+ skip "Use to help delete old models"
102
+ service.add_default_headers(
103
+ headers: {
104
+ "X-Watson-Learning-Opt-Out" => "1",
105
+ "X-Watson-Test" => "1"
106
+ }
107
+ )
108
+ service_response = service.list_sentiment_models
109
+ puts JSON.pretty_generate(service_response.result)
110
+ service_response = service.list_categories_models
111
+ puts JSON.pretty_generate(service_response.result)
112
+ service_response = service.list_classifications_models
113
+ puts JSON.pretty_generate(service_response.result)
114
+
115
+ # service.delete_sentiment_model(model_id: "model_id1")
116
+ # service.delete_categories_model(model_id: "0122b971-94c9-4468-a98f-930f4ce28c32")
117
+ # service.delete_classifications_model(model_id: "0122b971-94c9-4468-a98f-930f4ce28c32")
118
+ end
119
+
120
+ def test_sentiment_models
121
+ # skip "test_sentiment_models"
122
+ service.add_default_headers(
123
+ headers: {
124
+ "X-Watson-Learning-Opt-Out" => "1",
125
+ "X-Watson-Test" => "1"
126
+ }
127
+ )
128
+ training_data = File.open(Dir.getwd + "/resources/nlu_sentiment_data.csv")
129
+ service_response = service.create_sentiment_model(
130
+ language: "en",
131
+ training_data: training_data
132
+ )
133
+ assert((200..299).cover?(service_response.status))
134
+
135
+ service_response = service.list_sentiment_models
136
+ model_id = service_response.result["models"][0]["model_id"]
137
+ assert((200..299).cover?(service_response.status))
138
+
139
+ service_response = service.get_sentiment_model(model_id: model_id)
140
+ assert((200..299).cover?(service_response.status))
141
+
142
+ service_response = service.update_sentiment_model(
143
+ model_id: model_id,
144
+ language: "en",
145
+ training_data: training_data
146
+ )
147
+ assert((200..299).cover?(service_response.status))
148
+
149
+ service_response = service.delete_sentiment_model(
150
+ model_id: model_id
151
+ )
152
+ assert((200..299).cover?(service_response.status))
153
+ end
154
+
155
+ def test_categories_models
156
+ # skip "test_categories_models"
157
+ service.add_default_headers(
158
+ headers: {
159
+ "X-Watson-Learning-Opt-Out" => "1",
160
+ "X-Watson-Test" => "1"
161
+ }
162
+ )
163
+ training_data = File.open(Dir.getwd + "/resources/nlu_categories_training.json")
164
+ service_response = service.create_categories_model(
165
+ language: "en",
166
+ training_data: training_data,
167
+ training_data_content_type: "application/json"
168
+ )
169
+ assert((200..299).cover?(service_response.status))
170
+
171
+ service_response = service.list_categories_models
172
+ model_id = service_response.result["models"][0]["model_id"]
173
+ assert((200..299).cover?(service_response.status))
174
+ # puts JSON.pretty_generate(service_response.result)
175
+ # puts JSON.pretty_generate(model_id)
176
+
177
+ service_response = service.get_categories_model(model_id: model_id)
178
+ assert((200..299).cover?(service_response.status))
179
+
180
+ service_response = service.update_categories_model(
181
+ model_id: model_id,
182
+ language: "en",
183
+ training_data: training_data,
184
+ training_data_content_type: "application/json"
185
+ )
186
+ assert((200..299).cover?(service_response.status))
187
+
188
+ service_response = service.delete_categories_model(
189
+ model_id: model_id
190
+ )
191
+ assert((200..299).cover?(service_response.status))
192
+ end
193
+
194
+ def test_classifications_models
195
+ # skip "test_classifications_models"
196
+ service.add_default_headers(
197
+ headers: {
198
+ "X-Watson-Learning-Opt-Out" => "1",
199
+ "X-Watson-Test" => "1"
200
+ }
201
+ )
202
+ training_data = File.open(Dir.getwd + "/resources/nlu_classifications_training.json")
203
+ service_response = service.create_classifications_model(
204
+ language: "en",
205
+ training_data: training_data,
206
+ training_data_content_type: "application/json"
207
+ )
208
+ assert((200..299).cover?(service_response.status))
209
+
210
+ service_response = service.list_classifications_models
211
+ model_id = service_response.result["models"][0]["model_id"]
212
+ assert((200..299).cover?(service_response.status))
213
+ # puts JSON.pretty_generate(service_response.result)
214
+ # puts JSON.pretty_generate(model_id)
215
+
216
+ service_response = service.get_classifications_model(model_id: model_id)
217
+ assert((200..299).cover?(service_response.status))
218
+
219
+ service_response = service.update_classifications_model(
220
+ model_id: model_id,
221
+ language: "en",
222
+ training_data: training_data,
223
+ training_data_content_type: "application/json"
224
+ )
225
+ assert((200..299).cover?(service_response.status))
226
+
227
+ service_response = service.delete_classifications_model(
228
+ model_id: model_id
229
+ )
230
+ assert((200..299).cover?(service_response.status))
231
+ end
99
232
  end
100
233
  else
101
234
  class NaturalLanguageUnderstandingV1Test < Minitest::Test
@@ -48,13 +48,13 @@ if !ENV["TEXT_TO_SPEECH_APIKEY"].nil? && !ENV["TEXT_TO_SPEECH_URL"].nil?
48
48
  end
49
49
 
50
50
  def test_customizations
51
- service_response = @service.list_voice_models
51
+ service_response = @service.list_custom_models
52
52
  refute(service_response.nil?)
53
53
  end
54
54
 
55
55
  def test_custom_words
56
56
  skip "Skip to allow for concurrent travis jobs"
57
- customization_id = @service.create_voice_model(
57
+ customization_id = @service.create_custom_model(
58
58
  name: "test_integration_customization",
59
59
  description: "customization for tests"
60
60
  ).result["customization_id"]
@@ -79,10 +79,67 @@ if !ENV["TEXT_TO_SPEECH_APIKEY"].nil? && !ENV["TEXT_TO_SPEECH_URL"].nil?
79
79
  word: "MACLs"
80
80
  ).result
81
81
  assert(word["translation"] == "mackles")
82
- @service.delete_voice_model(
82
+ @service.delete_custom_model(
83
83
  customization_id: customization_id
84
84
  )
85
85
  end
86
+
87
+ def test_custom_prompts
88
+ customization_id = @service.create_custom_model(
89
+ name: "test_integration_customization",
90
+ description: "RUBY customization for tests"
91
+ ).result["customization_id"]
92
+
93
+ prompt_metadata = { prompt_text: "Thank you and goodbye" }
94
+ prompt_json = JSON[prompt_metadata]
95
+ audio_file = File.open(Dir.getwd + "/resources/speech.wav")
96
+ prompt = @service.add_custom_prompt(
97
+ customization_id: customization_id,
98
+ prompt_id: "rubyprompt_id",
99
+ metadata: prompt_json,
100
+ file: audio_file
101
+ ).result["prompt"]
102
+ assert(prompt == "Thank you and goodbye")
103
+
104
+ prompts = @service.list_custom_prompts(customization_id: customization_id).result["prompts"]
105
+ refute(prompts.nil?)
106
+
107
+ prompt = @service.get_custom_prompt(
108
+ customization_id: customization_id,
109
+ prompt_id: "rubyprompt_id"
110
+ ).result["prompt"]
111
+ assert(prompt == "Thank you and goodbye")
112
+
113
+ @service.delete_custom_prompt(
114
+ customization_id: customization_id,
115
+ prompt_id: "rubyprompt_id"
116
+ )
117
+
118
+ @service.delete_custom_model(
119
+ customization_id: customization_id
120
+ )
121
+ end
122
+
123
+ def test_speaker_models
124
+ audio_file = File.open(Dir.getwd + "/resources/speech.wav")
125
+ @service.create_speaker_model(
126
+ speaker_name: "RubyMike",
127
+ audio: audio_file
128
+ ).result["speaker_model"]
129
+
130
+ speakers = @service.list_speaker_models.result["speakers"]
131
+ speaker_id = speakers[0]["speaker_id"]
132
+ # puts JSON.pretty_generate(speakers)
133
+
134
+ @service.get_speaker_model(
135
+ speaker_id: speaker_id
136
+ ).result["models_speaker"]
137
+
138
+ # speaker_id = d3d03b69-4035-4420-928d-7ac2e0249829
139
+ @service.delete_speaker_model(
140
+ speaker_id: speaker_id
141
+ )
142
+ end
86
143
  end
87
144
  else
88
145
  class TextToSpeechV1Test < Minitest::Test
@@ -8,7 +8,7 @@ SimpleCov.command_name "test:unit"
8
8
 
9
9
  WebMock.disable_net_connect!(allow_localhost: true)
10
10
 
11
- # Unit tests for the Watson Assistant V1 Service
11
+ # Unit tests for the Watson Assistant V1 Services
12
12
  class AssistantV1Test < Minitest::Test
13
13
  include Minitest::Hooks
14
14
  attr_accessor :service
@@ -1401,4 +1401,55 @@ class AssistantV1Test < Minitest::Test
1401
1401
  )
1402
1402
  assert_equal({ "list_mentions_response" => "yes" }, service_response.result)
1403
1403
  end
1404
+
1405
+ def test_bulk_classify
1406
+ workspace_id = "f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec"
1407
+ message_response = {
1408
+ "context" => {
1409
+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b",
1410
+ "system" => {
1411
+ "dialog_stack" => ["root"],
1412
+ "dialog_turn_counter" => 1,
1413
+ "dialog_request_counter" => 1
1414
+ }
1415
+ },
1416
+ "intents" => [],
1417
+ "entities" => [],
1418
+ "input" => {},
1419
+ "output" => {
1420
+ "text" => "okay",
1421
+ "log_messages" => []
1422
+ }
1423
+ }
1424
+ headers = {
1425
+ "Content-Type" => "application/json"
1426
+ }
1427
+ stub_request(:post, "https://api.us-south.assistant.watson.cloud.ibm.com/v1/workspaces/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/bulk_classify?version=2018-02-16")
1428
+ .with(
1429
+ body: "{\"input\":{\"text\":\"Turn on the lights\"}}",
1430
+ headers: {
1431
+ "Accept" => "application/json",
1432
+ "Content-Type" => "application/json",
1433
+ "Host" => "api.us-south.assistant.watson.cloud.ibm.com"
1434
+ }
1435
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
1436
+ service_response = service.bulk_classify(
1437
+ workspace_id: workspace_id,
1438
+ input: { "text" => "Turn on the lights" }
1439
+ )
1440
+ assert_equal(message_response, service_response.result)
1441
+
1442
+ stub_request(:post, "https://api.us-south.assistant.watson.cloud.ibm.com/v1/workspaces/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/bulk_classify?version=2018-02-16")
1443
+ .with(
1444
+ headers: {
1445
+ "Accept" => "application/json",
1446
+ "Content-Type" => "application/json",
1447
+ "Host" => "api.us-south.assistant.watson.cloud.ibm.com"
1448
+ }
1449
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
1450
+ service_response = service.bulk_classify(
1451
+ workspace_id: workspace_id
1452
+ )
1453
+ assert_equal(message_response, service_response.result)
1454
+ end
1404
1455
  end
@@ -222,4 +222,55 @@ class AssistantV2Test < Minitest::Test
222
222
  )
223
223
  assert_nil(service_response)
224
224
  end
225
+
226
+ def test_bulk_classify
227
+ skill_id = "f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec"
228
+ message_response = {
229
+ "context" => {
230
+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b",
231
+ "system" => {
232
+ "dialog_stack" => ["root"],
233
+ "dialog_turn_counter" => 1,
234
+ "dialog_request_counter" => 1
235
+ }
236
+ },
237
+ "intents" => [],
238
+ "entities" => [],
239
+ "input" => {},
240
+ "output" => {
241
+ "text" => "okay",
242
+ "log_messages" => []
243
+ }
244
+ }
245
+ headers = {
246
+ "Content-Type" => "application/json"
247
+ }
248
+ stub_request(:post, "https://api.us-south.assistant.watson.cloud.ibm.com/v2/skills/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/workspace/bulk_classify?version=2018-02-16")
249
+ .with(
250
+ body: "{\"input\":{\"text\":\"Turn on the lights\"}}",
251
+ headers: {
252
+ "Accept" => "application/json",
253
+ "Content-Type" => "application/json",
254
+ "Host" => "api.us-south.assistant.watson.cloud.ibm.com"
255
+ }
256
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
257
+ service_response = service.bulk_classify(
258
+ skill_id: skill_id,
259
+ input: { "text" => "Turn on the lights" }
260
+ )
261
+ assert_equal(message_response, service_response.result)
262
+
263
+ stub_request(:post, "https://api.us-south.assistant.watson.cloud.ibm.com/v2/skills/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/workspace/bulk_classify?version=2018-02-16")
264
+ .with(
265
+ headers: {
266
+ "Accept" => "application/json",
267
+ "Content-Type" => "application/json",
268
+ "Host" => "api.us-south.assistant.watson.cloud.ibm.com"
269
+ }
270
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
271
+ service_response = service.bulk_classify(
272
+ skill_id: skill_id
273
+ )
274
+ assert_equal(message_response, service_response.result)
275
+ end
225
276
  end
@@ -295,7 +295,7 @@ class DiscoveryV2Test < Minitest::Test
295
295
  end
296
296
 
297
297
  def test_analyze_document
298
- skip "not available yet"
298
+ # skip "not available yet"
299
299
 
300
300
  stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collid/analyze?version=2018-03-05")
301
301
  .with(
@@ -467,4 +467,33 @@ class DiscoveryV2Test < Minitest::Test
467
467
  )
468
468
  assert_nil(service_response)
469
469
  end
470
+
471
+ def test_delete_training_query
472
+ stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
473
+ .with(
474
+ headers: {
475
+ "Host" => "api.us-south.discovery.watson.cloud.ibm.com"
476
+ }
477
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
478
+ service_response = service.delete_training_query(
479
+ project_id: "project",
480
+ query_id: "queryid"
481
+ )
482
+ assert_nil(service_response)
483
+ end
484
+
485
+ def test_query_collection_notices
486
+ stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collection/notices?version=2018-03-05")
487
+ .with(
488
+ headers: {
489
+ "Accept" => "application/json",
490
+ "Host" => "api.us-south.discovery.watson.cloud.ibm.com"
491
+ }
492
+ ).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
493
+ service_response = service.query_collection_notices(
494
+ project_id: "project",
495
+ collection_id: "collection"
496
+ )
497
+ assert_equal({ "body" => "hello" }, service_response.result)
498
+ end
470
499
  end