wit 3.1.0 → 3.2.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/examples/joke.rb +3 -3
- data/examples/quickstart.rb +4 -4
- data/examples/template.rb +2 -2
- data/lib/wit.rb +13 -7
- data/wit.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 565021c60a45347a1b360edbcd0dc1736b03167b
|
4
|
+
data.tar.gz: d3b26b07d70c5796bbef81fdbf710c5f04bd10b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1183c5c974e9aec6d622311bf604db59a6fd3e6aaca8391839443f33c0cdd38c1f89ffd5aab949b9961f50b71e0f0d70d0b358e7714bbdf31f6824cdfd15bf52
|
7
|
+
data.tar.gz: 76953d61b404a078322520469393ac9870361e7f942a2f5f751b80b0679f27a94254c96f2bcb002c1b109ededbce80ac6ab4b290b2d4a27a9a61d19d4aac5c04
|
data/examples/joke.rb
CHANGED
@@ -30,7 +30,7 @@ actions = {
|
|
30
30
|
:say => -> (session_id, msg) {
|
31
31
|
p msg
|
32
32
|
},
|
33
|
-
:merge => -> (context, entities) {
|
33
|
+
:merge => -> (session_id, context, entities, msg) {
|
34
34
|
new_context = context.clone
|
35
35
|
new_context.delete 'joke'
|
36
36
|
new_context.delete 'ack'
|
@@ -40,10 +40,10 @@ actions = {
|
|
40
40
|
new_context['ack'] = sentiment == 'positive' ? 'Glad you liked it.' : 'Hmm.' unless sentiment.nil?
|
41
41
|
return new_context
|
42
42
|
},
|
43
|
-
:error => -> (session_id,
|
43
|
+
:error => -> (session_id, context) {
|
44
44
|
p 'Oops I don\'t know what to do.'
|
45
45
|
},
|
46
|
-
:'select-joke' => -> (context) {
|
46
|
+
:'select-joke' => -> (session_id, context) {
|
47
47
|
new_context = context.clone
|
48
48
|
new_context['joke'] = all_jokes[new_context['cat'] || 'default'].sample
|
49
49
|
return new_context
|
data/examples/quickstart.rb
CHANGED
@@ -3,7 +3,7 @@ require 'wit'
|
|
3
3
|
# Quickstart example
|
4
4
|
# See https://wit.ai/l5t/Quickstart
|
5
5
|
|
6
|
-
access_token = '
|
6
|
+
access_token = 'HEIIUUUJDPXL6YROX5NVLSCGLCVDN3EY'
|
7
7
|
|
8
8
|
def first_entity_value(entities, entity)
|
9
9
|
return nil unless entities.has_key? entity
|
@@ -16,16 +16,16 @@ actions = {
|
|
16
16
|
:say => -> (session_id, msg) {
|
17
17
|
p msg
|
18
18
|
},
|
19
|
-
:merge => -> (context, entities) {
|
19
|
+
:merge => -> (session_id, context, entities, msg) {
|
20
20
|
new_context = context.clone
|
21
21
|
loc = first_entity_value entities, 'location'
|
22
22
|
new_context['loc'] = loc unless loc.nil?
|
23
23
|
return new_context
|
24
24
|
},
|
25
|
-
:error => -> (session_id,
|
25
|
+
:error => -> (session_id, context) {
|
26
26
|
p 'Oops I don\'t know what to do.'
|
27
27
|
},
|
28
|
-
:'fetch-weather' => -> (context) {
|
28
|
+
:'fetch-weather' => -> (session_id, context) {
|
29
29
|
new_context = context.clone
|
30
30
|
new_context['forecast'] = 'sunny'
|
31
31
|
return new_context
|
data/examples/template.rb
CHANGED
@@ -6,10 +6,10 @@ actions = {
|
|
6
6
|
:say => -> (session_id, msg) {
|
7
7
|
p msg
|
8
8
|
},
|
9
|
-
:merge => -> (context, entities) {
|
9
|
+
:merge => -> (session_id, context, entities, msg) {
|
10
10
|
return context
|
11
11
|
},
|
12
|
-
:error => -> (session_id,
|
12
|
+
:error => -> (session_id, context) {
|
13
13
|
p 'Oops I don\'t know what to do.'
|
14
14
|
},
|
15
15
|
}
|
data/lib/wit.rb
CHANGED
@@ -37,9 +37,9 @@ def validate_actions(actions)
|
|
37
37
|
raise WitException.new "The '#{k}' action name should be a symbol" unless k.is_a? Symbol
|
38
38
|
raise WitException.new "The '#{k}' action should be a lambda function" unless v.respond_to? :call and v.lambda?
|
39
39
|
raise WitException.new "The \'say\' action should take 2 arguments: session_id, msg. #{learn_more}" if k == :say and v.arity != 2
|
40
|
-
raise WitException.new "The \'merge\' action should take
|
41
|
-
raise WitException.new "The \'error\' action should take 2 arguments: session_id,
|
42
|
-
raise WitException.new "The '#{k}' action should take
|
40
|
+
raise WitException.new "The \'merge\' action should take 4 arguments: session_id, context, entities, msg. #{learn_more}" if k == :merge and v.arity != 4
|
41
|
+
raise WitException.new "The \'error\' action should take 2 arguments: session_id, context. #{learn_more}" if k == :error and v.arity != 2
|
42
|
+
raise WitException.new "The '#{k}' action should take 2 arguments: session_id, context. #{learn_more}" if k != :say and k != :merge and k != :error and v.arity != 2
|
43
43
|
end
|
44
44
|
return actions
|
45
45
|
end
|
@@ -78,7 +78,7 @@ class Wit
|
|
78
78
|
req @access_token, Net::HTTP::Post, '/converse', params, context
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def run_actions_(session_id, message, context, max_steps, user_message)
|
82
82
|
raise WitException.new 'max iterations reached' unless max_steps > 0
|
83
83
|
|
84
84
|
rst = converse session_id, message, context
|
@@ -95,7 +95,7 @@ class Wit
|
|
95
95
|
elsif type == 'merge'
|
96
96
|
raise WitException.new 'unknown action: merge' unless @actions.has_key? :merge
|
97
97
|
logger.info 'Executing merge'
|
98
|
-
context = @actions[:merge].call context, rst['entities']
|
98
|
+
context = @actions[:merge].call session_id, context, rst['entities'], user_message
|
99
99
|
if context.nil?
|
100
100
|
logger.warn 'missing context - did you forget to return it?'
|
101
101
|
context = {}
|
@@ -104,7 +104,7 @@ class Wit
|
|
104
104
|
action = rst['action'].to_sym
|
105
105
|
raise WitException.new "unknown action: #{action}" unless @actions.has_key? action
|
106
106
|
logger.info "Executing action #{action}"
|
107
|
-
context = @actions[action].call context
|
107
|
+
context = @actions[action].call session_id, context
|
108
108
|
if context.nil?
|
109
109
|
logger.warn 'missing context - did you forget to return it?'
|
110
110
|
context = {}
|
@@ -112,10 +112,16 @@ class Wit
|
|
112
112
|
elsif type == 'error'
|
113
113
|
raise WitException.new 'unknown action: error' unless @actions.has_key? :error
|
114
114
|
logger.info 'Executing error'
|
115
|
-
@actions[:error].call session_id,
|
115
|
+
@actions[:error].call session_id, context
|
116
116
|
else
|
117
117
|
raise WitException.new "unknown type: #{type}"
|
118
118
|
end
|
119
119
|
return run_actions session_id, nil, context, max_steps - 1
|
120
120
|
end
|
121
|
+
|
122
|
+
def run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
|
123
|
+
return run_actions_ session_id, message, context, max_steps, message
|
124
|
+
end
|
125
|
+
|
126
|
+
private :run_actions_
|
121
127
|
end
|
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: 3.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby SDK for Wit.ai
|
14
14
|
email: help@wit.ai
|