watson-conversation 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/hoge.rb +16 -0
- data/lib/watson/conversation.rb +16 -25
- data/lib/watson/conversation/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2142e0e26de065f9e76adbbc272924a0f0526715
|
4
|
+
data.tar.gz: b107b9e65ac9917cf51e1e9b7bcbcc0fa161c7f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8665af0822c083d99121f15571ce2bfbc104660e2007cffd6e65dcbed2fb91c287980bd44689bb9e4617fbe52a8df5f4aadea38d73053a5886299f44b4cb9df
|
7
|
+
data.tar.gz: 45d8eda8edf46f4513f01eb24b4e003447a131022e895893134ffd541a8aac020d7b4238be07f75a78fcca80dc8c5616cba8edbdd365c3cceea0a17fd00b53e1
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
```
|
23
|
+
```ruby
|
24
24
|
require 'watson/conversation'
|
25
25
|
|
26
26
|
manage = Watson::Conversation::ManageDialog.new(
|
@@ -30,10 +30,12 @@ manage = Watson::Conversation::ManageDialog.new(
|
|
30
30
|
)
|
31
31
|
|
32
32
|
# Get a greet message from a conversation system.
|
33
|
-
puts response1 = manage.talk("")
|
33
|
+
puts response1 = manage.talk("user1", "")
|
34
|
+
#=> "{user: user1, status_code: 200, output: [\"What would you like me to do?\"]}"
|
34
35
|
|
35
36
|
# Get a response to a user's input.
|
36
|
-
puts response2 = manage.talk("I would like you to
|
37
|
+
puts response2 = manage.talk("user1", "I would like you to ...")
|
38
|
+
#=> "{user: user1, status_code: 200, output: [\"I help you ...\"]}"
|
37
39
|
```
|
38
40
|
|
39
41
|
## Development
|
data/hoge.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require './lib/watson/conversation'
|
2
|
+
|
3
|
+
manage = Watson::Conversation::ManageDialog.new(
|
4
|
+
username: "2dc1e553-7caf-42a6-9566-7b09563973b6",
|
5
|
+
password: "scXHOmBTv5Po",
|
6
|
+
workspace_id: "3efc86e6-ba1b-425a-a3f1-3dd69d4f2432"
|
7
|
+
)
|
8
|
+
|
9
|
+
p response = manage.talk("Smith", "")
|
10
|
+
p response = manage.talk("Smith", "料金案内")
|
11
|
+
p response = manage.talk("Smith", "当月")
|
12
|
+
p response = manage.talk("Smith", "090-1234-1234")
|
13
|
+
p response = manage.talk("Smith", "1234")
|
14
|
+
p response = manage.talk("Smith2", "")
|
15
|
+
p response = manage.talk("Smith", "はい")
|
16
|
+
p response = manage.talk("Smith", "はい")
|
data/lib/watson/conversation.rb
CHANGED
@@ -15,13 +15,13 @@ module Watson
|
|
15
15
|
end
|
16
16
|
|
17
17
|
|
18
|
-
def talk(
|
19
|
-
if
|
18
|
+
def talk(question, context)
|
19
|
+
if context == ""
|
20
20
|
body = {}.to_json
|
21
21
|
else
|
22
22
|
body = {
|
23
23
|
input: {
|
24
|
-
text:
|
24
|
+
text: question
|
25
25
|
},
|
26
26
|
alternate_intents: true,
|
27
27
|
context: context,
|
@@ -50,38 +50,29 @@ module Watson
|
|
50
50
|
workspace_id: workspace_id
|
51
51
|
)
|
52
52
|
|
53
|
-
@
|
54
|
-
|
55
|
-
@context = {
|
56
|
-
context: {
|
57
|
-
conversation_id: @conversation_id,
|
58
|
-
dialog_stack: [
|
59
|
-
"root"
|
60
|
-
],
|
61
|
-
dialog_turn_counter: 1,
|
62
|
-
dialog_request_counter: 1
|
63
|
-
}
|
64
|
-
}
|
53
|
+
@users = {}
|
65
54
|
end
|
66
55
|
|
67
56
|
|
68
|
-
def talk(
|
69
|
-
|
57
|
+
def talk(user, question)
|
58
|
+
if @users.key?(user) == false
|
59
|
+
code, response = @cnv.talk("", "")
|
60
|
+
else
|
61
|
+
code, response = @cnv.talk(question, context = @users[user])
|
62
|
+
end
|
63
|
+
|
70
64
|
|
71
65
|
if code == 200
|
72
|
-
|
73
|
-
@
|
66
|
+
context = response["context"]
|
67
|
+
@users[user] = context
|
74
68
|
|
75
69
|
output_texts = Array.new
|
76
|
-
|
70
|
+
response["output"]["text"].each do | output_text |
|
77
71
|
output_texts.push(output_text)
|
78
72
|
end
|
79
|
-
|
80
|
-
return output_texts
|
81
|
-
else
|
82
|
-
return "#{code} #{body}"
|
83
73
|
end
|
84
|
-
|
74
|
+
|
75
|
+
return "{user: #{user}, status_code: #{code}, output: #{output_texts}}"
|
85
76
|
end
|
86
77
|
end
|
87
78
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watson-conversation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpha.netzilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- Rakefile
|
100
100
|
- bin/console
|
101
101
|
- bin/setup
|
102
|
+
- hoge.rb
|
102
103
|
- lib/watson/conversation.rb
|
103
104
|
- lib/watson/conversation/version.rb
|
104
105
|
- watson-conversation.gemspec
|