wit 4.0.0 → 4.1.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.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/README.md +2 -0
- data/lib/wit.rb +32 -4
- data/wit.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a8e68599e29e35430b0cae7ed26691435dbd38
|
4
|
+
data.tar.gz: 5934e10cb348235ab7f619ef6030d5e1e4bce06d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a61fc72b671a939e0970487825ee000743ba14d3537f002e9455fc9841ea965db400294c5f230aefa6d7aef288e4f883a38647ecc32ebd3d4bc4c59e3e760904
|
7
|
+
data.tar.gz: 1b9c4d937a90aafc671282e88a5444b463fc6c71e7f81235f5084c0543813cea1ebf9ec57abfd7f1162959c2b5d2e1d881f99fe4b76f1fa667c29ac7a6f4f486
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## v4.1.0
|
2
|
+
|
3
|
+
- `converse` now takes `reset` as optional parameter.
|
4
|
+
|
5
|
+
### Breaking changes
|
6
|
+
|
7
|
+
- `run_actions` now resets the last turn on new messages and errors.
|
8
|
+
|
1
9
|
## v4.0.0
|
2
10
|
|
3
11
|
After a lot of internal dogfooding and bot building, we decided to change the API in a backwards-incompatible way. The changes are described below and aim to simplify user code and accommodate upcoming features.
|
data/README.md
CHANGED
@@ -77,6 +77,7 @@ puts("Yay, got Wit.ai response: #{rsp}")
|
|
77
77
|
### .run_actions()
|
78
78
|
|
79
79
|
A higher-level method to the Wit converse API.
|
80
|
+
`run_actions` resets the last turn on new messages and errors.
|
80
81
|
|
81
82
|
Takes the following parameters:
|
82
83
|
* `session_id` - a unique identifier describing the user session
|
@@ -102,6 +103,7 @@ Takes the following parameters:
|
|
102
103
|
* `session_id` - a unique identifier describing the user session
|
103
104
|
* `msg` - the text received from the user
|
104
105
|
* `context` - the `Hash` representing the session state
|
106
|
+
* `reset` - (optional) whether to reset the last turn
|
105
107
|
|
106
108
|
Example:
|
107
109
|
```ruby
|
data/lib/wit.rb
CHANGED
@@ -71,6 +71,8 @@ class Wit
|
|
71
71
|
if opts[:actions]
|
72
72
|
@actions = validate_actions(logger, opts[:actions])
|
73
73
|
end
|
74
|
+
|
75
|
+
@_sessions = {}
|
74
76
|
end
|
75
77
|
|
76
78
|
def logger
|
@@ -88,18 +90,19 @@ class Wit
|
|
88
90
|
return res
|
89
91
|
end
|
90
92
|
|
91
|
-
def converse(session_id, msg, context={})
|
93
|
+
def converse(session_id, msg, context={}, reset=nil)
|
92
94
|
if !context.is_a?(Hash)
|
93
95
|
raise WitException.new('context should be a Hash')
|
94
96
|
end
|
95
97
|
params = {}
|
96
98
|
params[:q] = msg unless msg.nil?
|
97
99
|
params[:session_id] = session_id
|
100
|
+
params[:reset] = true if reset
|
98
101
|
res = req(logger, @access_token, Net::HTTP::Post, '/converse', params, context)
|
99
102
|
return res
|
100
103
|
end
|
101
104
|
|
102
|
-
def __run_actions(session_id, message, context, i)
|
105
|
+
def __run_actions(session_id, current_request, message, context, i)
|
103
106
|
if i <= 0
|
104
107
|
raise WitException.new('Max steps reached, stopping.')
|
105
108
|
end
|
@@ -107,6 +110,9 @@ class Wit
|
|
107
110
|
if json['type'].nil?
|
108
111
|
raise WitException.new('Couldn\'t find type in Wit response')
|
109
112
|
end
|
113
|
+
if current_request != @_sessions[session_id]
|
114
|
+
return context
|
115
|
+
end
|
110
116
|
|
111
117
|
logger.debug("Context: #{context}")
|
112
118
|
logger.debug("Response type: #{json['type']}")
|
@@ -150,7 +156,11 @@ class Wit
|
|
150
156
|
raise WitException.new("unknown type: #{json['type']}")
|
151
157
|
end
|
152
158
|
|
153
|
-
|
159
|
+
if current_request != @_sessions[session_id]
|
160
|
+
return context
|
161
|
+
end
|
162
|
+
|
163
|
+
return __run_actions(session_id, current_request, nil, context, i - 1)
|
154
164
|
end
|
155
165
|
|
156
166
|
def run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
|
@@ -160,7 +170,25 @@ class Wit
|
|
160
170
|
if !context.is_a?(Hash)
|
161
171
|
raise WitException.new('context should be a Hash')
|
162
172
|
end
|
163
|
-
|
173
|
+
|
174
|
+
# Figuring out whether we need to reset the last turn.
|
175
|
+
# Each new call increments an index for the session.
|
176
|
+
# We only care about the last call to run_actions.
|
177
|
+
# All the previous ones are discarded (preemptive exit).
|
178
|
+
current_request = 1
|
179
|
+
if @_sessions.has_key?(session_id)
|
180
|
+
current_request = @_sessions[session_id] + 1
|
181
|
+
end
|
182
|
+
@_sessions[session_id] = current_request
|
183
|
+
|
184
|
+
context = __run_actions(session_id, current_request, message, context, max_steps)
|
185
|
+
|
186
|
+
# Cleaning up once the last call to run_actions finishes.
|
187
|
+
if current_request == @_sessions[session_id]
|
188
|
+
@_sessions.delete(session_id)
|
189
|
+
end
|
190
|
+
|
191
|
+
return context
|
164
192
|
end
|
165
193
|
|
166
194
|
def interactive(context={}, max_steps=DEFAULT_MAX_STEPS)
|
data/wit.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Wit Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby SDK for Wit.ai
|
14
14
|
email: help@wit.ai
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.5
|
49
|
+
rubygems_version: 2.4.5
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: Ruby SDK for Wit.ai
|