ibm_watson 1.1.0 → 1.5.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.
@@ -52,6 +52,13 @@ if !ENV["ASSISTANT_APIKEY"].nil? && !ENV["ASSISTANT_URL"].nil?
52
52
  )
53
53
  assert((200..299).cover?(service_response.status))
54
54
 
55
+ service_response = service.message_stateless(
56
+ assistant_id: ENV["ASSISTANT_ASSISTANT_ID"],
57
+ input: { "text" => "Turn on the lights" },
58
+ context: nil
59
+ )
60
+ assert((200..299).cover?(service_response.status))
61
+
55
62
  service.delete_session(
56
63
  assistant_id: ENV["ASSISTANT_ASSISTANT_ID"],
57
64
  session_id: session_id
@@ -69,18 +69,7 @@ if !ENV["COMPARE_COMPLY_APIKEY"].nil?
69
69
  end
70
70
 
71
71
  def test_get_feedback
72
- @service_dup = IBMWatson::CompareComplyV1.new(
73
- iam_apikey: ENV["COMPARE_COMPLY_APIKEY"],
74
- version: "2018-10-15"
75
- )
76
- @service_dup.add_default_headers(
77
- headers: {
78
- "X-Watson-Learning-Opt-Out" => "1",
79
- "X-Watson-Test" => "1",
80
- "x-watson-metadata" => "customer_id=sdk-test-customer-id"
81
- }
82
- )
83
- response = @service_dup.get_feedback(
72
+ response = @service.get_feedback(
84
73
  feedback_id: ENV["COMPARE_COMPLY_FEEDBACK_ID"]
85
74
  ).result
86
75
  refute(response.nil?)
@@ -88,7 +88,7 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
88
88
  end
89
89
 
90
90
  def test_recognize_with_single_keyword
91
- file = File.open(Dir.getwd + "/resources/speech.wav")
91
+ file = File.open(Dir.getwd + "/resources/sound-with-pause.wav")
92
92
  output = nil
93
93
  File.open(file) do |audio_file|
94
94
  output = @service.recognize(
@@ -97,9 +97,12 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
97
97
  timestamps: true,
98
98
  word_alternatives_threshold: 0.9,
99
99
  keywords: %w"[colorado]",
100
- keywords_threshold: 0.5
100
+ keywords_threshold: 0.5,
101
+ split_transcript_at_phrase_end: true,
102
+ end_of_phrase_silence_time: nil
101
103
  )
102
104
  refute_nil(output.result["results"][0]["alternatives"][0]["transcript"])
105
+ assert(3, output.result["results"].length)
103
106
  end
104
107
  end
105
108
 
@@ -186,6 +189,7 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
186
189
  end
187
190
  thr = Thread.new { speech.start }
188
191
  thr.join
192
+ assert(atomic_boolean.false?)
189
193
  end
190
194
 
191
195
  def test_recognize_websocket
@@ -203,6 +207,7 @@ if !ENV["SPEECH_TO_TEXT_APIKEY"].nil? && !ENV["SPEECH_TO_TEXT_URL"].nil?
203
207
  )
204
208
  thr = Thread.new { speech.start }
205
209
  thr.join
210
+ assert(atomic_boolean.false?)
206
211
  end
207
212
 
208
213
  def test_inactivity_timeout_using_websocket
@@ -68,6 +68,15 @@ if !ENV["VISUAL_RECOGNITION_APIKEY"].nil? && !ENV["VISUAL_RECOGNITION_URL"].nil?
68
68
  ).result
69
69
  refute(result.nil?)
70
70
  end
71
+
72
+ def test_get_model_file
73
+ result = @service.get_model_file(
74
+ collection_id: @collection_id,
75
+ feature: "objects",
76
+ model_format: "rscnn"
77
+ ).result
78
+ refute(result.nil?)
79
+ end
71
80
  end
72
81
  else
73
82
  class VisualRecognitionV4Test < Minitest::Test
@@ -128,4 +128,70 @@ class AssistantV2Test < Minitest::Test
128
128
  )
129
129
  assert_nil(service_response)
130
130
  end
131
+
132
+ def test_message_stateless
133
+ # service.set_default_headers("x-watson-learning-opt-out" => true)
134
+ assistant_id = "f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec"
135
+ message_response = {
136
+ "context" => {
137
+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b",
138
+ "system" => {
139
+ "dialog_stack" => ["root"],
140
+ "dialog_turn_counter" => 1,
141
+ "dialog_request_counter" => 1
142
+ }
143
+ },
144
+ "intents" => [],
145
+ "entities" => [],
146
+ "input" => {},
147
+ "output" => {
148
+ "text" => "okay",
149
+ "log_messages" => []
150
+ }
151
+ }
152
+ headers = {
153
+ "Content-Type" => "application/json"
154
+ }
155
+ stub_request(:post, "https://gateway.watsonplatform.net/assistant/api/v2/assistants/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/message?version=2018-02-16")
156
+ .with(
157
+ body: "{\"input\":{\"text\":\"Turn on the lights\"}}",
158
+ headers: {
159
+ "Accept" => "application/json",
160
+ "Content-Type" => "application/json",
161
+ "Host" => "gateway.watsonplatform.net"
162
+ }
163
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
164
+ service_response = service.message_stateless(
165
+ assistant_id: assistant_id,
166
+ input: { "text" => "Turn on the lights" },
167
+ context: nil
168
+ )
169
+ assert_equal(message_response, service_response.result)
170
+
171
+ message_ctx = {
172
+ "context" => {
173
+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b",
174
+ "system" => {
175
+ "dialog_stack" => ["root"],
176
+ "dialog_turn_counter" => 2,
177
+ "dialog_request_counter" => 1
178
+ }
179
+ }
180
+ }
181
+ stub_request(:post, "https://gateway.watsonplatform.net/assistant/api/v2/assistants/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/message?version=2018-02-16")
182
+ .with(
183
+ body: "{\"input\":{\"text\":\"Turn on the lights\"},\"context\":\"{\\\"conversation_id\\\":\\\"1b7b67c0-90ed-45dc-8508-9488bc483d5b\\\",\\\"system\\\":{\\\"dialog_stack\\\":[\\\"root\\\"],\\\"dialog_turn_counter\\\":2,\\\"dialog_request_counter\\\":1}}\"}",
184
+ headers: {
185
+ "Accept" => "application/json",
186
+ "Content-Type" => "application/json",
187
+ "Host" => "gateway.watsonplatform.net"
188
+ }
189
+ ).to_return(status: 200, body: message_response.to_json, headers: headers)
190
+ service_response = service.message_stateless(
191
+ assistant_id: assistant_id,
192
+ input: { "text" => "Turn on the lights" },
193
+ context: message_ctx["context"].to_json
194
+ )
195
+ assert_equal(message_response, service_response.result)
196
+ end
131
197
  end
@@ -33,6 +33,7 @@ class PersonalityInsightsV3Test < Minitest::Test
33
33
  version: "2017-10-13",
34
34
  authenticator: authenticator
35
35
  )
36
+ service.service_url = "https://gateway.watsonplatform.net/personality-insights/api"
36
37
  service_response = service.profile(
37
38
  accept: "application/json",
38
39
  content: personality_text,
@@ -88,6 +89,7 @@ class PersonalityInsightsV3Test < Minitest::Test
88
89
  version: "2017-10-13",
89
90
  authenticator: authenticator
90
91
  )
92
+ service.service_url = "https://gateway.watsonplatform.net/personality-insights/api"
91
93
  service_response = service.profile(
92
94
  accept: "application/json",
93
95
  content: personality_text,
@@ -128,6 +130,7 @@ class PersonalityInsightsV3Test < Minitest::Test
128
130
  version: "2017-10-13",
129
131
  authenticator: authenticator
130
132
  )
133
+ service.service_url = "https://gateway.watsonplatform.net/personality-insights/api"
131
134
  service_response = service.profile(
132
135
  content: personality_text,
133
136
  content_type: "application/json",
@@ -171,6 +174,7 @@ class PersonalityInsightsV3Test < Minitest::Test
171
174
  version: "2017-10-13",
172
175
  authenticator: authenticator
173
176
  )
177
+ service.service_url = "https://gateway.watsonplatform.net/personality-insights/api"
174
178
  service_response = service.profile(
175
179
  accept: "application/json",
176
180
  content: personality_text,
@@ -332,4 +332,91 @@ class VisualRecognitionV4Test < Minitest::Test
332
332
  )
333
333
  assert_equal(response, service_response.result)
334
334
  end
335
+
336
+ def test_list_object_metadata
337
+ response = {
338
+ "objects" => []
339
+ }
340
+ stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/objects?version=2018-03-19")
341
+ .with(
342
+ headers: {
343
+ "Accept" => "application/json",
344
+ "Host" => "gateway.watsonplatform.net"
345
+ }
346
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
347
+ service_response = service.list_object_metadata(
348
+ collection_id: "collid"
349
+ )
350
+ assert_equal(response, service_response.result)
351
+ end
352
+
353
+ def test_update_object_metadata
354
+ response = {
355
+ "objects" => []
356
+ }
357
+ stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/objects/old_object?version=2018-03-19")
358
+ .with(
359
+ headers: {
360
+ "Accept" => "application/json",
361
+ "Host" => "gateway.watsonplatform.net"
362
+ }
363
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
364
+ service_response = service.update_object_metadata(
365
+ collection_id: "collid",
366
+ object: "old_object",
367
+ new_object: "new_object"
368
+ )
369
+ assert_equal(response, service_response.result)
370
+ end
371
+
372
+ def test_get_object_metadata
373
+ response = {
374
+ "objects" => []
375
+ }
376
+ stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/objects/object?version=2018-03-19")
377
+ .with(
378
+ headers: {
379
+ "Accept" => "application/json",
380
+ "Host" => "gateway.watsonplatform.net"
381
+ }
382
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
383
+ service_response = service.get_object_metadata(
384
+ collection_id: "collid",
385
+ object: "object"
386
+ )
387
+ assert_equal(response, service_response.result)
388
+ end
389
+
390
+ def test_delete_object
391
+ stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/objects/object?version=2018-03-19")
392
+ .with(
393
+ headers: {
394
+ "Accept" => "application/json",
395
+ "Host" => "gateway.watsonplatform.net"
396
+ }
397
+ ).to_return(status: 200, body: {}.to_json, headers: { "Content-Type" => "application/json" })
398
+ service_response = service.delete_object(
399
+ collection_id: "collid",
400
+ object: "object"
401
+ )
402
+ assert_nil(service_response)
403
+ end
404
+
405
+ def test_get_model_file
406
+ response = {
407
+ "binary" => []
408
+ }
409
+ stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/model?feature=objects&model_format=rscnn_ready&version=2018-03-19")
410
+ .with(
411
+ headers: {
412
+ "Host" => "gateway.watsonplatform.net"
413
+ }
414
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
415
+ service_response = service.get_model_file(
416
+ collection_id: "collid",
417
+ feature: "objects",
418
+ model_format: "rscnn_ready"
419
+ )
420
+ assert_equal(response, service_response.result)
421
+ end
335
422
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_watson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Nussbaum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-27 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
75
+ version: 1.1.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: 1.1.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: jwt
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -322,7 +322,6 @@ files:
322
322
  - test/unit/test_speech_to_text_v1.rb
323
323
  - test/unit/test_text_to_speech_v1.rb
324
324
  - test/unit/test_tone_analyzer_v3.rb
325
- - test/unit/test_vcap_using_personality_insights.rb
326
325
  - test/unit/test_visual_recognition_v3.rb
327
326
  - test/unit/test_visual_recognition_v4.rb
328
327
  homepage: https://www.github.com/watson-developer-cloud
@@ -347,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
346
  - !ruby/object:Gem::Version
348
347
  version: '0'
349
348
  requirements: []
350
- rubygems_version: 3.0.6
349
+ rubygems_version: 3.1.4
351
350
  signing_key:
352
351
  specification_version: 4
353
352
  summary: Official client library to use the IBM Watson Services
@@ -1,161 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("webmock/minitest")
6
-
7
- WebMock.disable_net_connect!(allow_localhost: true)
8
-
9
- ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
10
-
11
- # Unit tests for VCAP Services using the Personality Insights V3 Service
12
- class VcapPersonalityInsightsV3Test < Minitest::Test
13
- def test_plain_to_json
14
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect1.txt")
15
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
16
- headers = {
17
- "Content-Type" => "application/json"
18
- }
19
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: JSON.parse(profile_response), headers: headers)
20
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
21
- .with(
22
- body: personality_text,
23
- headers: {
24
- "Accept" => "application/json",
25
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
26
- "Content-Type" => "text/plain;charset=utf-8",
27
- "Host" => "gateway.watsonplatform.net"
28
- }
29
- ).to_return(status: 200, body: profile_response, headers: headers)
30
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
31
- service = IBMWatson::PersonalityInsightsV3.new(
32
- version: "2017-10-13",
33
- authenticator: authenticator
34
- )
35
- service_response = service.profile(
36
- accept: "application/json",
37
- content: personality_text,
38
- content_type: "text/plain;charset=utf-8"
39
- )
40
- assert_equal(expected_response.status, service_response.status)
41
- assert_equal(expected_response.result, service_response.result)
42
- expected_response.headers.each_key do |key|
43
- assert(service_response.headers.key?(key))
44
- assert(expected_response.headers[key] == service_response.headers[key])
45
- end
46
- end
47
-
48
- def test_json_to_json
49
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect2.txt")
50
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
51
- headers = {
52
- "Content-Type" => "applicaiton/json"
53
- }
54
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
55
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&raw_scores=true&version=2017-10-13")
56
- .with(
57
- body: personality_text,
58
- headers: {
59
- "Accept" => "application/json",
60
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
61
- "Content-Type" => "application/json",
62
- "Host" => "gateway.watsonplatform.net"
63
- }
64
- ).to_return(status: 200, body: profile_response, headers: headers)
65
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
66
- service = IBMWatson::PersonalityInsightsV3.new(
67
- version: "2017-10-13",
68
- authenticator: authenticator
69
- )
70
- service_response = service.profile(
71
- accept: "application/json",
72
- content: personality_text,
73
- content_type: "application/json",
74
- raw_scores: true,
75
- consumption_preferences: true
76
- )
77
- assert_equal(expected_response.status, service_response.status)
78
- assert_equal(expected_response.result, service_response.result)
79
- expected_response.headers.each_key do |key|
80
- assert(service_response.headers.key?(key))
81
- assert(expected_response.headers[key] == service_response.headers[key])
82
- end
83
- end
84
-
85
- def test_json_to_csv
86
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect3.txt")
87
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
88
- headers = {
89
- "Content-Type" => "text/csv"
90
- }
91
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
92
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&csv_headers=true&raw_scores=true&version=2017-10-13")
93
- .with(
94
- body: personality_text,
95
- headers: {
96
- "Accept" => "text/csv",
97
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
98
- "Content-Type" => "application/json",
99
- "Host" => "gateway.watsonplatform.net"
100
- }
101
- ).to_return(status: 200, body: profile_response, headers: headers)
102
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
103
- service = IBMWatson::PersonalityInsightsV3.new(
104
- version: "2017-10-13",
105
- authenticator: authenticator
106
- )
107
- service_response = service.profile(
108
- content: personality_text,
109
- content_type: "application/json",
110
- accept: "text/csv",
111
- csv_headers: true,
112
- raw_scores: true,
113
- consumption_preferences: true
114
- )
115
- assert_equal(expected_response.status, service_response.status)
116
- assert_equal(expected_response.result, service_response.result)
117
- expected_response.headers.each_key do |key|
118
- assert(service_response.headers.key?(key))
119
- assert(expected_response.headers[key] == service_response.headers[key])
120
- end
121
- end
122
-
123
- def test_plain_to_json_es
124
- profile_response = JSON.parse(File.read(Dir.getwd + "/resources/personality-v3-expect4.txt"))
125
- personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
126
- headers = {
127
- "Content-Type" => "application/json"
128
- }
129
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
130
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
131
- .with(
132
- body: personality_text,
133
- headers: {
134
- "Accept" => "application/json",
135
- "Accept-Language" => "es",
136
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
137
- "Content-Language" => "es",
138
- "Content-Type" => "text/plain;charset=utf-8",
139
- "Host" => "gateway.watsonplatform.net"
140
- }
141
- ).to_return(status: 200, body: profile_response.to_json, headers: headers)
142
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
143
- service = IBMWatson::PersonalityInsightsV3.new(
144
- version: "2017-10-13",
145
- authenticator: authenticator
146
- )
147
- service_response = service.profile(
148
- accept: "application/json",
149
- content: personality_text,
150
- content_type: "text/plain;charset=utf-8",
151
- content_language: "es",
152
- accept_language: "es"
153
- )
154
- assert_equal(expected_response.status, service_response.status)
155
- assert_equal(expected_response.result, service_response.result)
156
- expected_response.headers.each_key do |key|
157
- assert(service_response.headers.key?(key))
158
- assert(expected_response.headers[key] == service_response.headers[key])
159
- end
160
- end
161
- end