Skip to content

Commit 1db37d9

Browse files
authored
Merge pull request #100 from watson-developer-cloud/release-4-2020
feat: New features in VR4 and assistant2
2 parents c5d33e3 + da3009c commit 1db37d9

File tree

8 files changed

+224
-16
lines changed

8 files changed

+224
-16
lines changed

lib/ibm_watson/assistant_v2.rb

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ def delete_session(assistant_id:, session_id:)
160160

161161
##
162162
# @!method message(assistant_id:, session_id:, input: nil, context: nil)
163-
# Send user input to assistant.
164-
# Send user input to an assistant and receive a response.
163+
# Send user input to assistant (stateful).
164+
# Send user input to an assistant and receive a response, with conversation state
165+
# (including context data) stored by Watson Assistant for the duration of the
166+
# session.
165167
#
166168
# There is no rate limit for this operation.
167169
# @param assistant_id [String] Unique identifier of the assistant. To find the assistant ID in the Watson
@@ -172,9 +174,12 @@ def delete_session(assistant_id:, session_id:)
172174
# **Note:** Currently, the v2 API does not support creating assistants.
173175
# @param session_id [String] Unique identifier of the session.
174176
# @param input [MessageInput] An input object that includes the input text.
175-
# @param context [MessageContext] State information for the conversation. The context is stored by the assistant on
176-
# a per-session basis. You can use this property to set or modify context variables,
177-
# which can also be accessed by dialog nodes.
177+
# @param context [MessageContext] Context data for the conversation. You can use this property to set or modify
178+
# context variables, which can also be accessed by dialog nodes. The context is
179+
# stored by the assistant on a per-session basis.
180+
#
181+
# **Note:** The total size of the context data stored for a stateful session cannot
182+
# exceed 100KB.
178183
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
179184
def message(assistant_id:, session_id:, input: nil, context: nil)
180185
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?
@@ -207,5 +212,57 @@ def message(assistant_id:, session_id:, input: nil, context: nil)
207212
)
208213
response
209214
end
215+
216+
##
217+
# @!method message_stateless(assistant_id:, input: nil, context: nil)
218+
# Send user input to assistant (stateless).
219+
# Send user input to an assistant and receive a response, with conversation state
220+
# (including context data) managed by your application.
221+
#
222+
# There is no rate limit for this operation.
223+
# @param assistant_id [String] Unique identifier of the assistant. To find the assistant ID in the Watson
224+
# Assistant user interface, open the assistant settings and click **API Details**.
225+
# For information about creating assistants, see the
226+
# [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-add#assistant-add-task).
227+
#
228+
# **Note:** Currently, the v2 API does not support creating assistants.
229+
# @param input [MessageInputStateless] An input object that includes the input text.
230+
# @param context [MessageContextStateless] Context data for the conversation. You can use this property to set or modify
231+
# context variables, which can also be accessed by dialog nodes. The context is not
232+
# stored by the assistant. To maintain session state, include the context from the
233+
# previous response.
234+
#
235+
# **Note:** The total size of the context data for a stateless session cannot exceed
236+
# 250KB.
237+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
238+
def message_stateless(assistant_id:, input: nil, context: nil)
239+
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?
240+
241+
headers = {
242+
}
243+
sdk_headers = Common.new.get_sdk_headers("conversation", "V2", "message_stateless")
244+
headers.merge!(sdk_headers)
245+
246+
params = {
247+
"version" => @version
248+
}
249+
250+
data = {
251+
"input" => input,
252+
"context" => context
253+
}
254+
255+
method_url = "/v2/assistants/%s/message" % [ERB::Util.url_encode(assistant_id)]
256+
257+
response = request(
258+
method: "POST",
259+
url: method_url,
260+
headers: headers,
261+
params: params,
262+
json: data,
263+
accept_json: true
264+
)
265+
response
266+
end
210267
end
211268
end

lib/ibm_watson/discovery_v2.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ def add_document(project_id:, collection_id:, file: nil, filename: nil, file_con
467467
# **Note:** This operation only works on collections created to accept direct file
468468
# uploads. It cannot be used to modify a collection that connects to an external
469469
# source such as Microsoft SharePoint.
470+
#
471+
# **Note:** If an uploaded document is segmented, all segments will be overwritten,
472+
# even if the updated version of the document has fewer segments.
470473
# @param project_id [String] The ID of the project. This information can be found from the deploy page of the
471474
# Discovery administrative tooling.
472475
# @param collection_id [String] The ID of the collection.
@@ -537,6 +540,9 @@ def update_document(project_id:, collection_id:, document_id:, file: nil, filena
537540
# **Note:** This operation only works on collections created to accept direct file
538541
# uploads. It cannot be used to modify a collection that connects to an external
539542
# source such as Microsoft SharePoint.
543+
#
544+
# **Note:** Segments of an uploaded document cannot be deleted individually. Delete
545+
# all segments by deleting using the `parent_document_id` of a segment result.
540546
# @param project_id [String] The ID of the project. This information can be found from the deploy page of the
541547
# Discovery administrative tooling.
542548
# @param collection_id [String] The ID of the collection.

lib/ibm_watson/text_to_speech_v1.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
# both, for each language. The audio is streamed back to the client with minimal delay.
2121
#
2222
# For speech synthesis, the service supports a synchronous HTTP Representational State
23-
# Transfer (REST) interface. It also supports a WebSocket interface that provides both
24-
# plain text and SSML input, including the SSML <mark> element and word timings.
25-
# SSML is an XML-based markup language that provides text annotation for speech-synthesis
26-
# applications.
23+
# Transfer (REST) interface and a WebSocket interface. Both interfaces support plain text
24+
# and SSML input. SSML is an XML-based markup language that provides text annotation for
25+
# speech-synthesis applications. The WebSocket interface also supports the SSML
26+
# <code>&lt;mark&gt;</code> element and word timings.
2727
#
28-
# The service also offers a customization interface. You can use the interface to define
29-
# sounds-like or phonetic translations for words. A sounds-like translation consists of
30-
# one or more words that, when combined, sound like the word. A phonetic translation is
31-
# based on the SSML phoneme format for representing a word. You can specify a phonetic
32-
# translation in standard International Phonetic Alphabet (IPA) representation or in the
33-
# proprietary IBM Symbolic Phonetic Representation (SPR). The Arabic, Chinese, Dutch, and
34-
# Korean languages support only IPA.
28+
# The service offers a customization interface that you can use to define sounds-like or
29+
# phonetic translations for words. A sounds-like translation consists of one or more words
30+
# that, when combined, sound like the word. A phonetic translation is based on the SSML
31+
# phoneme format for representing a word. You can specify a phonetic translation in
32+
# standard International Phonetic Alphabet (IPA) representation or in the proprietary IBM
33+
# Symbolic Phonetic Representation (SPR). The Arabic, Chinese, Dutch, and Korean languages
34+
# support only IPA.
3535

3636
require "concurrent"
3737
require "erb"

lib/ibm_watson/visual_recognition_v4.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,51 @@ def delete_collection(collection_id:)
325325
)
326326
nil
327327
end
328+
329+
##
330+
# @!method get_model_file(collection_id:, feature:, model_format:)
331+
# Get a model.
332+
# Download a model that you can deploy to detect objects in images. The collection
333+
# must include a generated model, which is indicated in the response for the
334+
# collection details as `"rscnn_ready": true`. If the value is `false`, train or
335+
# retrain the collection to generate the model.
336+
#
337+
# Currently, the model format is specific to Android apps. For more information
338+
# about how to deploy the model to your app, see the [Watson Visual Recognition on
339+
# Android](https://github.com/matt-ny/rscnn) project in GitHub.
340+
# @param collection_id [String] The identifier of the collection.
341+
# @param feature [String] The feature for the model.
342+
# @param model_format [String] The format of the returned model.
343+
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
344+
def get_model_file(collection_id:, feature:, model_format:)
345+
raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
346+
347+
raise ArgumentError.new("feature must be provided") if feature.nil?
348+
349+
raise ArgumentError.new("model_format must be provided") if model_format.nil?
350+
351+
headers = {
352+
}
353+
sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V4", "get_model_file")
354+
headers.merge!(sdk_headers)
355+
356+
params = {
357+
"version" => @version,
358+
"feature" => feature,
359+
"model_format" => model_format
360+
}
361+
362+
method_url = "/v4/collections/%s/model" % [ERB::Util.url_encode(collection_id)]
363+
364+
response = request(
365+
method: "GET",
366+
url: method_url,
367+
headers: headers,
368+
params: params,
369+
accept_json: false
370+
)
371+
response
372+
end
328373
#########################
329374
# Images
330375
#########################

test/integration/test_assistant_v2.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def test_create_delete_session_and_message
5252
)
5353
assert((200..299).cover?(service_response.status))
5454

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+
5562
service.delete_session(
5663
assistant_id: ENV["ASSISTANT_ASSISTANT_ID"],
5764
session_id: session_id

test/integration/test_visual_recognition_v4.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ def test_list_images
6868
).result
6969
refute(result.nil?)
7070
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
7180
end
7281
else
7382
class VisualRecognitionV4Test < Minitest::Test

test/unit/test_assistant_v2.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,70 @@ def test_delete_session
128128
)
129129
assert_nil(service_response)
130130
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
131197
end

test/unit/test_visual_recognition_v4.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,22 @@ def test_delete_object
401401
)
402402
assert_nil(service_response)
403403
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
404422
end

0 commit comments

Comments
 (0)