wit 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 565021c60a45347a1b360edbcd0dc1736b03167b
4
- data.tar.gz: d3b26b07d70c5796bbef81fdbf710c5f04bd10b8
3
+ metadata.gz: 329b154a407970ed82314b1e600bab97cccb770d
4
+ data.tar.gz: 92c1f766cdf3de796044e2861cb62816970574ba
5
5
  SHA512:
6
- metadata.gz: 1183c5c974e9aec6d622311bf604db59a6fd3e6aaca8391839443f33c0cdd38c1f89ffd5aab949b9961f50b71e0f0d70d0b358e7714bbdf31f6824cdfd15bf52
7
- data.tar.gz: 76953d61b404a078322520469393ac9870361e7f942a2f5f751b80b0679f27a94254c96f2bcb002c1b109ededbce80ac6ab4b290b2d4a27a9a61d19d4aac5c04
6
+ metadata.gz: a623fcbc955b0c9d82bdf727bf8219b6087bd44bf696720dbce8cf767803f58d790d92994995901b60c447800a5a270de3edcaf0e34ef3b5ec7b955c0b69f1cb
7
+ data.tar.gz: 802f6789388f95542d5f3f84a186e2d606ae415051977d67adce303b3d4a41b71477681fb128023b446fcceef2af73afddc68a2f32121f635960a8ce6eff457d
data/CHANGES.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## v3.3
2
+
3
+ Unifying action parameters
4
+
5
+ ### breaking
6
+
7
+ - the `say` action now takes 3 parameters: `session_id`, `context`, `msg`
8
+ - the `error` action now takes 3 parameters: `session_id`, `context`, `error`
9
+
10
+ ## v3.2
11
+
12
+ Updating action parameters
13
+
14
+ ### breaking
15
+
16
+ - the `merge` action now takes 4 parameters: `session_id`, `context`, `entities`, `msg`
17
+ - the `error` action now takes `context` as second parameter
18
+ - custom actions now take 2 parameters: `session_id`, `context`
19
+
1
20
  ## v3.1
2
21
 
3
22
  - allows for custom logging
data/README.md CHANGED
@@ -45,16 +45,17 @@ actions = {
45
45
  :say => -> (session_id, msg) {
46
46
  p msg
47
47
  },
48
- :merge => -> (context, entities) {
48
+ :merge => -> (session_id, context, entities, msg) {
49
49
  return context
50
50
  },
51
- :error => -> (session_id, msg) {
51
+ :error => -> (session_id, context) {
52
52
  p 'Oops I don\'t know what to do.'
53
53
  },
54
54
  }
55
55
  ```
56
56
 
57
- A custom action takes one parameter:
57
+ A custom action takes the following parameters:
58
+ * `session_id` - a unique identifier describing the user session
58
59
  * `context` - the `Hash` representing the session state
59
60
 
60
61
  Example:
data/examples/joke.rb CHANGED
@@ -27,26 +27,24 @@ all_jokes = {
27
27
  }
28
28
 
29
29
  actions = {
30
- :say => -> (session_id, msg) {
30
+ :say => -> (session_id, context, msg) {
31
31
  p msg
32
32
  },
33
33
  :merge => -> (session_id, context, entities, msg) {
34
- new_context = context.clone
35
- new_context.delete 'joke'
36
- new_context.delete 'ack'
34
+ context.delete 'joke'
35
+ context.delete 'ack'
37
36
  category = first_entity_value entities, 'category'
38
- new_context['category'] = category unless category.nil?
37
+ context['category'] = category unless category.nil?
39
38
  sentiment = first_entity_value entities, 'sentiment'
40
- new_context['ack'] = sentiment == 'positive' ? 'Glad you liked it.' : 'Hmm.' unless sentiment.nil?
41
- return new_context
39
+ context['ack'] = sentiment == 'positive' ? 'Glad you liked it.' : 'Hmm.' unless sentiment.nil?
40
+ return context
42
41
  },
43
- :error => -> (session_id, context) {
44
- p 'Oops I don\'t know what to do.'
42
+ :error => -> (session_id, context, error) {
43
+ p error.message
45
44
  },
46
45
  :'select-joke' => -> (session_id, context) {
47
- new_context = context.clone
48
- new_context['joke'] = all_jokes[new_context['cat'] || 'default'].sample
49
- return new_context
46
+ context['joke'] = all_jokes[context['cat'] || 'default'].sample
47
+ return context
50
48
  },
51
49
  }
52
50
  client = Wit.new access_token, actions
@@ -3,7 +3,7 @@ require 'wit'
3
3
  # Quickstart example
4
4
  # See https://wit.ai/l5t/Quickstart
5
5
 
6
- access_token = 'HEIIUUUJDPXL6YROX5NVLSCGLCVDN3EY'
6
+ access_token = 'YOUR_ACCESS_TOKEN'
7
7
 
8
8
  def first_entity_value(entities, entity)
9
9
  return nil unless entities.has_key? entity
@@ -13,22 +13,20 @@ def first_entity_value(entities, entity)
13
13
  end
14
14
 
15
15
  actions = {
16
- :say => -> (session_id, msg) {
16
+ :say => -> (session_id, context, msg) {
17
17
  p msg
18
18
  },
19
19
  :merge => -> (session_id, context, entities, msg) {
20
- new_context = context.clone
21
20
  loc = first_entity_value entities, 'location'
22
- new_context['loc'] = loc unless loc.nil?
23
- return new_context
21
+ context['loc'] = loc unless loc.nil?
22
+ return context
24
23
  },
25
- :error => -> (session_id, context) {
26
- p 'Oops I don\'t know what to do.'
24
+ :error => -> (session_id, context, error) {
25
+ p error.message
27
26
  },
28
27
  :'fetch-weather' => -> (session_id, context) {
29
- new_context = context.clone
30
- new_context['forecast'] = 'sunny'
31
- return new_context
28
+ context['forecast'] = 'sunny'
29
+ return context
32
30
  },
33
31
  }
34
32
  client = Wit.new access_token, actions
data/examples/template.rb CHANGED
@@ -3,14 +3,14 @@ require 'wit'
3
3
  access_token = 'YOUR_ACCESS_TOKEN'
4
4
 
5
5
  actions = {
6
- :say => -> (session_id, msg) {
6
+ :say => -> (session_id, context, msg) {
7
7
  p msg
8
8
  },
9
9
  :merge => -> (session_id, context, entities, msg) {
10
10
  return context
11
11
  },
12
- :error => -> (session_id, context) {
13
- p 'Oops I don\'t know what to do.'
12
+ :error => -> (session_id, context, error) {
13
+ p error.message
14
14
  },
15
15
  }
16
16
  client = Wit.new access_token, actions
data/lib/wit.rb CHANGED
@@ -36,9 +36,9 @@ def validate_actions(actions)
36
36
  actions.each_pair do |k, v|
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
- raise WitException.new "The \'say\' action should take 2 arguments: session_id, msg. #{learn_more}" if k == :say and v.arity != 2
39
+ raise WitException.new "The \'say\' action should take 3 arguments: session_id, context, msg. #{learn_more}" if k == :say and v.arity != 3
40
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
41
+ raise WitException.new "The \'error\' action should take 3 arguments: session_id, context, error. #{learn_more}" if k == :error and v.arity != 3
42
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
@@ -91,11 +91,11 @@ class Wit
91
91
  raise WitException.new 'unknown action: say' unless @actions.has_key? :say
92
92
  msg = rst['msg']
93
93
  logger.info "Executing say with: #{msg}"
94
- @actions[:say].call session_id, msg
94
+ @actions[:say].call session_id, context.clone, msg
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 session_id, context, rst['entities'], user_message
98
+ context = @actions[:merge].call session_id, context.clone, 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 session_id, context
107
+ context = @actions[action].call session_id, context.clone
108
108
  if context.nil?
109
109
  logger.warn 'missing context - did you forget to return it?'
110
110
  context = {}
@@ -112,7 +112,7 @@ 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, context
115
+ @actions[:error].call session_id, context.clone, WitException.new('Oops, I don\'t know what to do.')
116
116
  else
117
117
  raise WitException.new "unknown type: #{type}"
118
118
  end
data/wit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wit'
3
- s.version = '3.2.0'
3
+ s.version = '3.3.0'
4
4
  s.date = Date.today.to_s
5
5
  s.summary = 'Ruby SDK for Wit.ai'
6
6
  s.description = 'Ruby SDK for Wit.ai'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Wit Team