Skip to content

Commit 2f4c175

Browse files
WIP
1 parent d9e6da0 commit 2f4c175

File tree

13 files changed

+509
-0
lines changed

13 files changed

+509
-0
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: CI
2+
on:
3+
push:
4+
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: ruby/setup-ruby@v1
11+
with:
12+
ruby-version: 2.7
13+
bundler-cache: true

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release Gem
2+
on:
3+
# Triggers the workflow on push with a tag prefixed with v*
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: 2.7
19+
bundler-cache: true
20+
- name: Publish gem
21+
env:
22+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
23+
run: |
24+
mkdir -p $HOME/.gem
25+
touch $HOME/.gem/credentials
26+
chmod 0600 $HOME/.gem/credentials
27+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28+
gem build *.gemspec
29+
gem push *.gem

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# please add general patterns to your global ignore list
2+
# see https://github.com/github/gitignore#readme
3+
.DS_STORE
4+
*.swp
5+
*.rbc
6+
*.sass-cache
7+
/pkg
8+
/doc/api
9+
/coverage
10+
.yardoc
11+
doc/
12+
*.gem

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'stealth', '>= 2.0.0.beta'
4+
5+
gemspec

Gemfile.lock

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
PATH
2+
remote: .
3+
specs:
4+
stealth-clu (1.0.0)
5+
http (~> 4)
6+
stealth (>= 2.0.0.beta)
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
activesupport (6.1.7.10)
12+
concurrent-ruby (~> 1.0, >= 1.0.2)
13+
i18n (>= 1.6, < 2)
14+
minitest (>= 5.1)
15+
tzinfo (~> 2.0)
16+
zeitwerk (~> 2.3)
17+
addressable (2.8.7)
18+
public_suffix (>= 2.0.2, < 7.0)
19+
concurrent-ruby (1.3.5)
20+
connection_pool (2.5.3)
21+
diff-lcs (1.6.2)
22+
domain_name (0.6.20240107)
23+
ffi (1.17.2)
24+
ffi (1.17.2-arm64-darwin)
25+
ffi (1.17.2-x86_64-darwin)
26+
ffi-compiler (1.3.2)
27+
ffi (>= 1.15.5)
28+
rake
29+
http (4.4.1)
30+
addressable (~> 2.3)
31+
http-cookie (~> 1.0)
32+
http-form_data (~> 2.2)
33+
http-parser (~> 1.2.0)
34+
http-cookie (1.0.8)
35+
domain_name (~> 0.5)
36+
http-form_data (2.3.0)
37+
http-parser (1.2.3)
38+
ffi-compiler (>= 1.0, < 2.0)
39+
i18n (1.14.7)
40+
concurrent-ruby (~> 1.0)
41+
minitest (5.25.5)
42+
multi_json (1.15.0)
43+
mustermann (2.0.2)
44+
ruby2_keywords (~> 0.0.1)
45+
nio4r (2.7.4)
46+
public_suffix (6.0.2)
47+
puma (5.6.9)
48+
nio4r (~> 2.0)
49+
rack (2.2.14)
50+
rack-protection (2.2.4)
51+
rack
52+
rake (13.2.1)
53+
redis (4.8.1)
54+
rspec (3.13.0)
55+
rspec-core (~> 3.13.0)
56+
rspec-expectations (~> 3.13.0)
57+
rspec-mocks (~> 3.13.0)
58+
rspec-core (3.13.3)
59+
rspec-support (~> 3.13.0)
60+
rspec-expectations (3.13.4)
61+
diff-lcs (>= 1.2.0, < 2.0)
62+
rspec-support (~> 3.13.0)
63+
rspec-mocks (3.13.4)
64+
diff-lcs (>= 1.2.0, < 2.0)
65+
rspec-support (~> 3.13.0)
66+
rspec-support (3.13.3)
67+
ruby2_keywords (0.0.5)
68+
sidekiq (6.5.12)
69+
connection_pool (>= 2.2.5, < 3)
70+
rack (~> 2.0)
71+
redis (>= 4.5.0, < 5)
72+
sinatra (2.2.4)
73+
mustermann (~> 2.0)
74+
rack (~> 2.2)
75+
rack-protection (= 2.2.4)
76+
tilt (~> 2.0)
77+
stealth (2.0.0.beta7)
78+
activesupport (~> 6.0)
79+
multi_json (~> 1.12)
80+
puma (>= 4.2, < 6.0)
81+
sidekiq (< 7)
82+
sinatra (~> 2.0)
83+
thor (~> 1.0)
84+
thor (1.3.2)
85+
tilt (2.6.0)
86+
tzinfo (2.0.6)
87+
concurrent-ruby (~> 1.0)
88+
zeitwerk (2.6.18)
89+
90+
PLATFORMS
91+
arm64-darwin
92+
ruby
93+
x86_64-darwin
94+
95+
DEPENDENCIES
96+
rspec (~> 3)
97+
stealth (>= 2.0.0.beta)
98+
stealth-clu!
99+
100+
BUNDLED WITH
101+
2.6.3

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

lib/stealth-clu.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
3+
require 'stealth/nlp/clu'

lib/stealth/nlp/clu.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
require 'stealth/nlp/clu/result'
4+
require 'stealth/nlp/clu/client'

lib/stealth/nlp/clu/client.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
module Stealth
4+
module Nlp
5+
module Clu
6+
class Client < Stealth::Nlp::Client
7+
8+
def initialize(subscription_key: nil, project_name: nil, deployment_name: nil, endpoint: nil, datetime_ref: nil)
9+
begin
10+
@subscription_key = subscription_key || Stealth.config.clu.subscription_key
11+
@project_name = project_name || Stealth.config.clu.project_name
12+
@deployment_name = deployment_name || Stealth.config.clu.deployment_name
13+
@endpoint = endpoint || Stealth.config.clu.endpoint
14+
@datetime_ref = datetime_ref || Stealth.config.clu.datetime_reference
15+
rescue NoMethodError
16+
raise(
17+
Stealth::Errors::ConfigurationError,
18+
'A `clu` configuration key must be specified directly or in `services.yml`'
19+
)
20+
end
21+
end
22+
23+
def endpoint
24+
"https://#{@endpoint}/language/:analyze-conversations?api-version=2023-04-01"
25+
end
26+
27+
def client
28+
@client ||= begin
29+
headers = {
30+
'Content-Type' => 'application/json',
31+
'Ocp-Apim-Subscription-Key' => @subscription_key
32+
}
33+
HTTP.timeout(connect: 15, read: 60).headers(headers)
34+
end
35+
end
36+
37+
def understand(query:)
38+
body = MultiJson.dump({
39+
'kind' => 'Conversation',
40+
'analysisInput' => {
41+
'conversationItem' => {
42+
'participantId' => '1',
43+
'id' => '1',
44+
'modality' => 'text',
45+
'language' => 'en',
46+
'text' => query
47+
}
48+
},
49+
'parameters' => {
50+
'projectName' => @project_name,
51+
'deploymentName' => @deployment_name,
52+
'stringIndexType' => 'TextElement_V8',
53+
'verbose' => true
54+
}
55+
})
56+
57+
Stealth::Logger.l(
58+
topic: :nlp,
59+
message: 'Performing NLP lookup via Microsoft CLU'
60+
)
61+
62+
result = client.post(endpoint, body: body)
63+
Result.new(result: result)
64+
end
65+
66+
end
67+
end
68+
end
69+
end
70+
71+
ENTITY_TYPES = %i(number currency email percentage phone age
72+
url ordinal geo dimension temp datetime duration)

0 commit comments

Comments
 (0)