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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8346c258aff676710321e7452750f3ea6eff3a56
4
- data.tar.gz: 625b24dc2223fef2500303d98c409deea91b3f43
3
+ metadata.gz: 565021c60a45347a1b360edbcd0dc1736b03167b
4
+ data.tar.gz: d3b26b07d70c5796bbef81fdbf710c5f04bd10b8
5
5
  SHA512:
6
- metadata.gz: fe28aba17bdb04e4a4614edc99bad441434c7c6f5056273e9c0092e6f1d38783202d74e7c040a199cc47314cfcd98fd4b8291b0395a4f7f17dd4dd98979147a4
7
- data.tar.gz: d4b6ee270ca08b5f0f367bd06dae05e9e4eb3d5aa4b9d8e35cb085ab184dd9a12069e5baaeab50d9cf97f18ade9e7042cf4ee2bc501231339acce9c5a6974263
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, msg) {
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
@@ -3,7 +3,7 @@ require 'wit'
3
3
  # Quickstart example
4
4
  # See https://wit.ai/l5t/Quickstart
5
5
 
6
- access_token = 'YOUR_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, msg) {
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, msg) {
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 2 arguments: context, entities. #{learn_more}" if k == :merge and v.arity != 2
41
- raise WitException.new "The \'error\' action should take 2 arguments: session_id, msg. #{learn_more}" if k == :error and v.arity != 2
42
- raise WitException.new "The '#{k}' action should take 1 argument: context. #{learn_more}" if k != :say and k != :merge and k != :error and v.arity != 1
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 run_actions(session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS)
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, 'unknown action: error'
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
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wit'
3
- s.version = '3.1.0'
4
- s.date = '2014-12-05'
3
+ s.version = '3.2.0'
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'
7
7
  s.authors = ['The Wit Team']
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.1.0
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: 2014-12-05 00:00:00.000000000 Z
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