stealth-luis 1.0.0 → 1.2.1

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
  SHA256:
3
- metadata.gz: c94f820865869cc8b51140b58cd0795086098a105a2a809dbaadf962b5545252
4
- data.tar.gz: cca0d3584223c186d30c9795082c9a4e8eedf07d913c7cb318c9aaab040eaac2
3
+ metadata.gz: 26190207d9a05e1834bdc87a01e776086a2ebe42185721318da7dad8bb99d571
4
+ data.tar.gz: bf40713a23368020624fe4ece78672c5036cb6f024d97060c2c39a8e3b0af697
5
5
  SHA512:
6
- metadata.gz: c0507f391523b949dc419891cfa2a91840329284e000dcbcf0039abf4415ba519d9af05b75fdffccc325bbf843a6882bb81a2ad003aec4d4e9f89530fc87b730
7
- data.tar.gz: 8ef9b0dfbb967d143e8e6ba14c35d4305591aa610455eacc7103b53319a000df9819fb86b112da1764dff46ddb80173531d1d66f9aec140b85e2f10fe8cb7b0f
6
+ metadata.gz: 23605e8ac81023589db30ca9598d39086d2373b76785a97769a368aaf00cdca105706935e1001caf6705c2db792780ed4819bd70d99fbab93a87f0015f7f03c2
7
+ data.tar.gz: 82a1e7268c759dc2817b7d603f3de4dface711de5b37c41927f4a08c318f3381b739ea7429e80d5fb14f55909ddc857b9e7b6751e0603c41f443a60334955090
@@ -1,3 +1,22 @@
1
+ # Changelog 1.2.1
2
+
3
+ ## Features
4
+
5
+ * Updated gems
6
+
7
+ # Changelog 1.2.0
8
+
9
+ ## Bugfixes
10
+
11
+ * `datetimeReference` is not respected by LUIS when specified as a `GET`. Switched to `POST`
12
+ * Renamed `tz_offset` option to `datetime_reference` to more closely match the LUIS API
13
+
14
+ # Changelog 1.1.0
15
+
16
+ ## Features
17
+
18
+ * Added intent threshold option; intents with lower scores than the threshold are not matched.
19
+
1
20
  # Changelog 1.0.0
2
21
 
3
22
  ## Bugfixes
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'stealth', git: 'https://github.com/hellostealth/stealth', branch: 'master'
3
+ gem 'stealth', '>= 2.0.0.beta'
4
4
 
5
5
  gemspec
@@ -1,44 +1,31 @@
1
- GIT
2
- remote: https://github.com/hellostealth/stealth
3
- revision: d6d3c626d2faa951203da652f733c4a18162e1f5
4
- branch: master
5
- specs:
6
- stealth (2.0.0)
7
- activesupport (~> 6.0)
8
- multi_json (~> 1.12)
9
- puma (>= 4.2, < 5.0)
10
- sidekiq (~> 6.0)
11
- sinatra (~> 2.0)
12
- thor (~> 1.0)
13
-
14
1
  PATH
15
2
  remote: .
16
3
  specs:
17
- stealth-luis (0.9.0)
4
+ stealth-luis (1.2.1)
18
5
  http (~> 4)
19
- stealth (~> 2.0)
6
+ stealth (>= 2.0.0.beta)
20
7
 
21
8
  GEM
22
9
  remote: https://rubygems.org/
23
10
  specs:
24
- activesupport (6.0.2.1)
11
+ activesupport (6.0.3.3)
25
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
13
  i18n (>= 0.7, < 2)
27
14
  minitest (~> 5.1)
28
15
  tzinfo (~> 1.1)
29
- zeitwerk (~> 2.2)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
30
17
  addressable (2.7.0)
31
18
  public_suffix (>= 2.0.2, < 5.0)
32
- concurrent-ruby (1.1.6)
33
- connection_pool (2.2.2)
34
- diff-lcs (1.3)
19
+ concurrent-ruby (1.1.7)
20
+ connection_pool (2.2.3)
21
+ diff-lcs (1.4.4)
35
22
  domain_name (0.5.20190701)
36
23
  unf (>= 0.0.5, < 1.0.0)
37
- ffi (1.12.2)
24
+ ffi (1.13.1)
38
25
  ffi-compiler (1.0.1)
39
26
  ffi (>= 1.0.0)
40
27
  rake
41
- http (4.3.0)
28
+ http (4.4.1)
42
29
  addressable (~> 2.3)
43
30
  http-cookie (~> 1.0)
44
31
  http-form_data (~> 2.2)
@@ -48,62 +35,68 @@ GEM
48
35
  http-form_data (2.3.0)
49
36
  http-parser (1.2.1)
50
37
  ffi-compiler (>= 1.0, < 2.0)
51
- i18n (1.8.2)
38
+ i18n (1.8.5)
52
39
  concurrent-ruby (~> 1.0)
53
- minitest (5.14.0)
54
- multi_json (1.14.1)
40
+ minitest (5.14.2)
41
+ multi_json (1.15.0)
55
42
  mustermann (1.1.1)
56
43
  ruby2_keywords (~> 0.0.1)
57
- nio4r (2.5.2)
58
- public_suffix (4.0.3)
59
- puma (4.3.3)
44
+ nio4r (2.5.4)
45
+ public_suffix (4.0.6)
46
+ puma (4.3.6)
60
47
  nio4r (~> 2.0)
61
- rack (2.2.2)
62
- rack-protection (2.0.8.1)
48
+ rack (2.2.3)
49
+ rack-protection (2.1.0)
63
50
  rack
64
51
  rake (13.0.1)
65
- redis (4.1.3)
52
+ redis (4.2.2)
66
53
  rspec (3.9.0)
67
54
  rspec-core (~> 3.9.0)
68
55
  rspec-expectations (~> 3.9.0)
69
56
  rspec-mocks (~> 3.9.0)
70
- rspec-core (3.9.1)
71
- rspec-support (~> 3.9.1)
72
- rspec-expectations (3.9.0)
57
+ rspec-core (3.9.2)
58
+ rspec-support (~> 3.9.3)
59
+ rspec-expectations (3.9.2)
73
60
  diff-lcs (>= 1.2.0, < 2.0)
74
61
  rspec-support (~> 3.9.0)
75
62
  rspec-mocks (3.9.1)
76
63
  diff-lcs (>= 1.2.0, < 2.0)
77
64
  rspec-support (~> 3.9.0)
78
- rspec-support (3.9.2)
65
+ rspec-support (3.9.3)
79
66
  ruby2_keywords (0.0.2)
80
- sidekiq (6.0.5)
67
+ sidekiq (6.1.2)
81
68
  connection_pool (>= 2.2.2)
82
69
  rack (~> 2.0)
83
- rack-protection (>= 2.0.0)
84
- redis (>= 4.1.0)
85
- sinatra (2.0.8.1)
70
+ redis (>= 4.2.0)
71
+ sinatra (2.1.0)
86
72
  mustermann (~> 1.0)
87
- rack (~> 2.0)
88
- rack-protection (= 2.0.8.1)
73
+ rack (~> 2.2)
74
+ rack-protection (= 2.1.0)
89
75
  tilt (~> 2.0)
76
+ stealth (2.0.0.beta1)
77
+ activesupport (~> 6.0)
78
+ multi_json (~> 1.12)
79
+ puma (>= 4.2, < 5.0)
80
+ sidekiq (~> 6.0)
81
+ sinatra (~> 2.0)
82
+ thor (~> 1.0)
90
83
  thor (1.0.1)
91
84
  thread_safe (0.3.6)
92
85
  tilt (2.0.10)
93
- tzinfo (1.2.6)
86
+ tzinfo (1.2.7)
94
87
  thread_safe (~> 0.1)
95
88
  unf (0.1.4)
96
89
  unf_ext
97
- unf_ext (0.0.7.6)
98
- zeitwerk (2.3.0)
90
+ unf_ext (0.0.7.7)
91
+ zeitwerk (2.4.0)
99
92
 
100
93
  PLATFORMS
101
94
  ruby
102
95
 
103
96
  DEPENDENCIES
104
97
  rspec (= 3.9.0)
105
- stealth!
98
+ stealth (>= 2.0.0.beta)
106
99
  stealth-luis!
107
100
 
108
101
  BUNDLED WITH
109
- 2.1.2
102
+ 2.1.4
data/README.md CHANGED
@@ -16,6 +16,7 @@ default: &default
16
16
  app_id: 9434fbd8-420b-6d75-8a6f-b6c9a0ac5ec0
17
17
  subscription_key: 1b69a4b9db669805b4fcba5f1f2f87bb
18
18
  tz_offset: 0
19
+ intent_threshold: 0.2
19
20
 
20
21
  production:
21
22
  <<: *default
@@ -49,6 +50,10 @@ Otherwise, the intent named `yes` and the intent named `no` will attempt to be m
49
50
 
50
51
  For more info about how intents are matched, please see the [Stealth NLP documentation](https://github.com/hellostealth/stealth/wiki/NLP).
51
52
 
53
+ ### intent_threshold
54
+
55
+ This is the real number that respresents the minimum threshold required for an intent to match. So if for example your `intent_threshold` is set to `0.2`, if the top intent scores `0.09`, it will not be returned as a match.
56
+
52
57
  ## Entities
53
58
 
54
59
  The entity types listed below are named using their corresponding Stealth type. The equivalent type used by Microsoft LUIS is also listed. For each code sample, the sample query is first provided followed by the array of entities extracted from the queries (for the given type).
@@ -5,12 +5,12 @@ module Stealth
5
5
  module Luis
6
6
  class Client < Stealth::Nlp::Client
7
7
 
8
- def initialize(subscription_key: nil, app_id: nil, endpoint: nil, tz_offset: 0)
8
+ def initialize(subscription_key: nil, app_id: nil, endpoint: nil, datetime_ref: nil)
9
9
  begin
10
10
  @subscription_key = subscription_key || Stealth.config.luis.subscription_key
11
11
  @app_id = app_id || Stealth.config.luis.app_id
12
12
  @endpoint = endpoint || Stealth.config.luis.endpoint
13
- @tz_offset = tz_offset || Stealth.config.luis.tz_offset
13
+ @datetime_ref = datetime_ref || Stealth.config.luis.datetime_reference
14
14
  @slot = Stealth.env.development? ? 'staging' : 'production'
15
15
  rescue NoMethodError
16
16
  raise(
@@ -35,16 +35,21 @@ module Stealth
35
35
 
36
36
  def understand(query:)
37
37
  params = {
38
- 'datetimeReference' => @tz_offset,
39
- 'subscription-key' => @subscription_key,
40
- 'query' => query
38
+ 'subscription-key' => @subscription_key
41
39
  }
42
40
 
41
+ body = MultiJson.dump({
42
+ 'query' => query,
43
+ 'options' => {
44
+ 'datetimeReference' => @datetime_ref,
45
+ }
46
+ })
47
+
43
48
  Stealth::Logger.l(
44
49
  topic: :nlp,
45
50
  message: 'Performing NLP lookup via Microsoft LUIS'
46
51
  )
47
- result = client.get(endpoint, params: params)
52
+ result = client.post(endpoint, params: params, body: body)
48
53
  Result.new(result: result)
49
54
  end
50
55
 
@@ -71,7 +71,7 @@ module Stealth
71
71
  end
72
72
 
73
73
  def intent_score
74
- parsed_result&.dig('prediction', 'intents', top_intent)
74
+ parsed_result&.dig('prediction', 'intents', top_intent, 'score')
75
75
  end
76
76
 
77
77
  def raw_entities
@@ -105,7 +105,24 @@ module Stealth
105
105
  private
106
106
 
107
107
  def top_intent
108
- parsed_result&.dig('prediction', 'topIntent')
108
+ @top_intent ||= begin
109
+ matched_intent = parsed_result&.dig('prediction', 'topIntent')
110
+ _intent_score = parsed_result&.dig('prediction', 'intents', matched_intent, 'score')
111
+
112
+ if Stealth.config.luis.intent_threshold.is_a?(Numeric)
113
+ if _intent_score > Stealth.config.luis.intent_threshold
114
+ matched_intent
115
+ else
116
+ Stealth::Logger.l(
117
+ topic: :nlp,
118
+ message: "Ignoring intent match. Does not meet threshold (#{Stealth.config.luis.intent_threshold})"
119
+ )
120
+ 'None' # can't be nil or this doesn't get memoized
121
+ end
122
+ else
123
+ matched_intent
124
+ end
125
+ end
109
126
  end
110
127
 
111
128
  end
@@ -1,17 +1,22 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'stealth-luis'
3
- s.version = '1.0.0'
5
+ s.version = '1.2.1'
4
6
  s.summary = "Stealth LUIS"
5
7
  s.description = "Built-in NLP for Stealth bots via Microsoft's Language Understanding (LUIS)."
6
8
  s.authors = ["Mauricio Gomes"]
7
9
  s.email = 'mauricio@edge14.com'
8
- s.files = `git ls-files`.split("\n")
9
10
  s.homepage = 'http://github.com/hellostealth/stealth-luis'
10
11
  s.license = 'MIT'
11
12
 
12
- s.add_dependency 'stealth', '~> 2.0'
13
+ s.add_dependency 'stealth', '>= 2.0.0.beta'
13
14
  s.add_dependency 'http', '~> 4'
14
15
 
15
16
  s.add_development_dependency "rspec", "= 3.9.0"
16
17
 
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.require_paths = ['lib']
17
22
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stealth-luis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Gomes
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stealth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: 2.0.0.beta
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: 2.0.0.beta
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: http
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ homepage: http://github.com/hellostealth/stealth-luis
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
78
- post_install_message:
78
+ post_install_message:
79
79
  rdoc_options: []
80
80
  require_paths:
81
81
  - lib
@@ -91,7 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubygems_version: 3.1.2
94
- signing_key:
94
+ signing_key:
95
95
  specification_version: 4
96
96
  summary: Stealth LUIS
97
- test_files: []
97
+ test_files:
98
+ - spec/spec_helper.rb