Skip to content

Commit da3009c

Browse files
committed
feat: New features in VR4 and assistant2
feat: New features in VR4 and assistant2
1 parent c331aa2 commit da3009c

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

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)