watson-conversation 0.1.7 → 0.1.8
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 +6 -6
- data/lib/watson/conversation.rb +53 -48
- data/lib/watson/conversation/version.rb +1 -1
- data/watson-conversation.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8500f42f435bf34b7533cf729703621dff4e367
|
4
|
+
data.tar.gz: 867e0c1def23362ab8fdc668964e96cda7fe1706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f79b51b8b56e1ab25592d394affb42f6ee7aa0b0c00a446b7ea6420296d87576380b373cce154b2be95abaccaa8fd8d58da3cdc89ebb52b1f98dee9c9cd34f
|
7
|
+
data.tar.gz: 355c63ca5868c884bc540dd934eb6e1a228035bfe9d20ecb3f5134fcff288936e0e5f0afdfc7fac1d8d55f67f5baf3920a93db8aae3fdda2317314dcd9e29d44
|
data/README.md
CHANGED
@@ -26,10 +26,12 @@ require 'watson/conversation'
|
|
26
26
|
manage = Watson::Conversation::ManageDialog.new(
|
27
27
|
username: [username],
|
28
28
|
password: [password],
|
29
|
-
workspace_id: [workspace_id]
|
29
|
+
workspace_id: [workspace_id],
|
30
|
+
# Where to link the freely-selected user name with the conversation_id
|
31
|
+
storage: "hash" or "uri for redis like 'redis://127.0.0.1:6379'"
|
30
32
|
)
|
31
33
|
|
32
|
-
# Get a greet message from a conversation
|
34
|
+
# Get a greet message from a conversation service.
|
33
35
|
puts response1 = manage.talk("user1", "")
|
34
36
|
#=> {user: user1, status_code: 200, output: [\"What would you like me to do?\"]}
|
35
37
|
|
@@ -38,12 +40,10 @@ puts response2 = manage.talk("user1", "I would like you to ...")
|
|
38
40
|
#=> {user: user1, status_code: 200, output: [\"I help you ...\"]}
|
39
41
|
|
40
42
|
# Check if the user exists
|
41
|
-
puts manage.
|
42
|
-
#=> {"code":true, "description":"shinya exists."}
|
43
|
+
puts manage.has_key?("user1")
|
43
44
|
|
44
45
|
# Delete the user
|
45
|
-
puts manage.
|
46
|
-
#=> {"code":0,"description":"user1 was deleted."}
|
46
|
+
puts manage.delete("user1")
|
47
47
|
```
|
48
48
|
|
49
49
|
## Development
|
data/lib/watson/conversation.rb
CHANGED
@@ -2,6 +2,8 @@ require "watson/conversation/version"
|
|
2
2
|
require 'rest-client'
|
3
3
|
require "json"
|
4
4
|
require "thread"
|
5
|
+
require "redis"
|
6
|
+
|
5
7
|
|
6
8
|
|
7
9
|
module Watson
|
@@ -11,7 +13,6 @@ module Watson
|
|
11
13
|
def initialize(username: "", password: "", workspace_id: "")
|
12
14
|
url = "https://#{username}:#{password}@gateway.watsonplatform.net/conversation/api"
|
13
15
|
version="2016-07-11"
|
14
|
-
|
15
16
|
@endpoint = "#{url}/v1/workspaces/#{workspace_id}/message?version=#{version}"
|
16
17
|
end
|
17
18
|
|
@@ -30,7 +31,6 @@ module Watson
|
|
30
31
|
context: context,
|
31
32
|
}.to_json
|
32
33
|
end
|
33
|
-
|
34
34
|
|
35
35
|
Thread.start do
|
36
36
|
begin
|
@@ -41,14 +41,14 @@ module Watson
|
|
41
41
|
code = e.response.code
|
42
42
|
body = e.response.body
|
43
43
|
end
|
44
|
-
future_data.
|
44
|
+
future_data.set_real_data(code, body)
|
45
45
|
end
|
46
46
|
|
47
47
|
return future_data
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
def
|
51
|
+
def get_data()
|
52
52
|
return code, body
|
53
53
|
end
|
54
54
|
end
|
@@ -64,9 +64,9 @@ module Watson
|
|
64
64
|
end
|
65
65
|
|
66
66
|
|
67
|
-
def
|
67
|
+
def set_real_data(code, body)
|
68
68
|
@mutex.synchronize do
|
69
|
-
if
|
69
|
+
if @is_ready == true
|
70
70
|
return
|
71
71
|
end
|
72
72
|
end
|
@@ -78,9 +78,9 @@ module Watson
|
|
78
78
|
end
|
79
79
|
|
80
80
|
|
81
|
-
def
|
81
|
+
def get_data()
|
82
82
|
@mutex.synchronize do
|
83
|
-
while
|
83
|
+
while @is_ready == false
|
84
84
|
@cv.wait(@mutex)
|
85
85
|
end
|
86
86
|
end
|
@@ -88,56 +88,64 @@ module Watson
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
91
|
|
93
|
-
class ManageDialog
|
94
|
-
def initialize(username: "", password: "", workspace_id: "")
|
95
|
-
@mutex = Mutex.new
|
96
92
|
|
93
|
+
|
94
|
+
class Redis < ::Redis
|
95
|
+
def fetch(user)
|
96
|
+
JSON.parse(get(user))
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def store(user, data)
|
101
|
+
set(user, data.to_json)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def delete(user)
|
106
|
+
del(user)
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def has_key?(user)
|
111
|
+
exists(user)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
class ManageDialog
|
118
|
+
def initialize(username: "", password: "", workspace_id: "", storage: "hash")
|
97
119
|
@cnv = Dialog.new(
|
98
120
|
username: username,
|
99
121
|
password: password,
|
100
122
|
workspace_id: workspace_id
|
101
123
|
)
|
102
124
|
|
103
|
-
|
104
|
-
|
125
|
+
if storage == "hash"
|
126
|
+
@users = Hash.new
|
127
|
+
else
|
128
|
+
@users = Redis.new(:url => storage)
|
129
|
+
end
|
105
130
|
|
131
|
+
@mutex = Mutex.new
|
132
|
+
end
|
106
133
|
|
107
|
-
def
|
108
|
-
@
|
109
|
-
if @users.has_key?(user)
|
110
|
-
{code: true, description: "#{user} exists."}.to_json
|
111
|
-
else
|
112
|
-
{code: false, description: "#{user} does not exists."}.to_json
|
113
|
-
end
|
114
|
-
end
|
134
|
+
def users
|
135
|
+
@users
|
115
136
|
end
|
116
137
|
|
117
138
|
|
118
|
-
def delete_user(user)
|
119
|
-
if @users.has_key?(user)
|
120
|
-
@mutex.synchronize do
|
121
|
-
@users.delete(user)
|
122
|
-
end
|
123
|
-
{code: 0, description: "#{user} was deleted."}.to_json
|
124
|
-
else
|
125
|
-
{code: 1, description: "#{user} does not exist."}.to_json
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
139
|
def talk(user, question)
|
131
140
|
future_data = nil
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
141
|
+
|
142
|
+
if @users.has_key?(user) == false
|
143
|
+
future_data = @cnv.talk("", "")
|
144
|
+
else
|
145
|
+
future_data = @cnv.talk(question, context = @users.fetch(user))
|
138
146
|
end
|
139
147
|
|
140
|
-
code, response = future_data.
|
148
|
+
code, response = future_data.get_data()
|
141
149
|
|
142
150
|
output_texts = []
|
143
151
|
if code == 200
|
@@ -147,13 +155,10 @@ module Watson
|
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
else
|
155
|
-
@users.delete(user)
|
156
|
-
end
|
158
|
+
if code == 200
|
159
|
+
@users.store(user, context)
|
160
|
+
else
|
161
|
+
@users.delete(user)
|
157
162
|
end
|
158
163
|
|
159
164
|
return {user: user, status_code: code, output: output_texts}.to_json
|
data/watson-conversation.gemspec
CHANGED
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpha.netzilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.3'
|
83
97
|
description: Client library to use the IBM Watson Conversation service
|
84
98
|
email:
|
85
99
|
- alpha.netzilla@gmail.com
|