ai 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ai-list-answers +8 -0
- data/bin/ai-list-scripts +8 -0
- data/lib/ai.rb +9 -1
- data/lib/ai_client.rb +8 -0
- data/lib/web_client.rb +17 -0
- data/spec/ai_spec.rb +68 -40
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2321eb74fc2b7bc0ea2ee72d48742dfa9194db42
|
4
|
+
data.tar.gz: 7c21fa8cfa4629e9ed77d274bc59f407387fd2d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 976579cca8578a64ef0cb6fad2ffa13d20d63437378480ab61005619a57e12e6058074c21e8a7d2af1d6a2c9ed6f74fabff13993c7be877ac0ac82792c95d76d
|
7
|
+
data.tar.gz: c45b2c774393cc1a040b0c643a3dcffe8145b36a8f40d7377d753c1babec5d4dcf3da90bf1e5b7aa15e27c31d4a5804df19729e662d8067923755d293721be1a
|
data/bin/ai-list-answers
ADDED
data/bin/ai-list-scripts
ADDED
data/lib/ai.rb
CHANGED
@@ -14,7 +14,7 @@ class Ai
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.post(utterance)
|
17
|
-
uri = URI.parse(ENV['
|
17
|
+
uri = URI.parse((ENV['PIVOTAL_API_URL'] || "http://milligan-acceptance.herokuapp.com") + "/milligans/reply")
|
18
18
|
|
19
19
|
data = { utterance: utterance }.to_json
|
20
20
|
|
@@ -35,5 +35,13 @@ class Ai
|
|
35
35
|
def self.learn_script(questions, answer)
|
36
36
|
::AiClient.learn_script(questions, answer)
|
37
37
|
end
|
38
|
+
|
39
|
+
def self.list_answers
|
40
|
+
::AiClient.list_answers
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.list_scripts
|
44
|
+
::AiClient.list_scripts
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
data/lib/ai_client.rb
CHANGED
@@ -35,4 +35,12 @@ class AiClient
|
|
35
35
|
|
36
36
|
WebClient.post(BASE_URL + '/api/v1/direct_responses/import', body)
|
37
37
|
end
|
38
|
+
|
39
|
+
def self.list_answers
|
40
|
+
WebClient.get(BASE_URL + '/api/v1/direct_responses')
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.list_scripts
|
44
|
+
WebClient.get(BASE_URL + '/api/v1/script_responses')
|
45
|
+
end
|
38
46
|
end
|
data/lib/web_client.rb
CHANGED
@@ -19,4 +19,21 @@ class WebClient
|
|
19
19
|
{}
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
def self.get(url)
|
24
|
+
uri = URI.parse(url)
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
|
27
|
+
request = Net::HTTP::Get.new(
|
28
|
+
uri.request_uri,
|
29
|
+
'Content-Type' => 'application/json'
|
30
|
+
)
|
31
|
+
|
32
|
+
response = http.request(request)
|
33
|
+
unless response.body.nil?
|
34
|
+
JSON.parse(response.body)
|
35
|
+
else
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
end
|
22
39
|
end
|
data/spec/ai_spec.rb
CHANGED
@@ -1,59 +1,87 @@
|
|
1
|
+
require 'ai'
|
1
2
|
require 'ai_client'
|
2
|
-
require 'web_client'
|
3
3
|
|
4
|
-
RSpec.describe
|
5
|
-
describe '
|
6
|
-
|
7
|
-
|
4
|
+
RSpec.describe Ai do
|
5
|
+
describe '#process' do
|
6
|
+
context 'given general utterance' do
|
7
|
+
it 'makes a post request' do
|
8
|
+
http = double("Http")
|
9
|
+
expect(Net::HTTP).to receive(:new).and_return(http)
|
10
|
+
response = double('Response')
|
11
|
+
expect(response).to receive(:body).and_return({ 'type' => 'script', 'script' => 'ls -a' }.to_json)
|
12
|
+
expect(http).to receive(:request_post).and_return(response)
|
13
|
+
expect(Kernel).to receive(:system).with('ls -a').and_return(true)
|
8
14
|
|
9
|
-
|
10
|
-
|
15
|
+
Ai.process('show files')
|
16
|
+
end
|
11
17
|
|
12
|
-
|
18
|
+
context 'given acton response' do
|
19
|
+
it 'runs the command' do
|
20
|
+
response = { 'type' => 'script', 'script' => 'ls -a' }
|
13
21
|
|
14
|
-
|
22
|
+
expect(Kernel).to receive(:system).with('ls -a').and_return(true)
|
23
|
+
expect(Ai).to receive(:post).and_return(response)
|
24
|
+
|
25
|
+
Ai.process('show files')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'given text response' do
|
30
|
+
it 'prints the response' do
|
31
|
+
response = { 'type' => 'text', 'text' => 'hi' }
|
32
|
+
|
33
|
+
expect(Kernel).to_not receive(:system)
|
34
|
+
expect(Kernel).to receive(:puts).with('hi').and_return(true)
|
35
|
+
expect(Ai).to receive(:post).and_return(response)
|
36
|
+
|
37
|
+
Ai.process('Hello')
|
38
|
+
end
|
39
|
+
end
|
15
40
|
end
|
16
|
-
end
|
17
41
|
|
18
|
-
|
19
|
-
|
20
|
-
|
42
|
+
context 'given import' do
|
43
|
+
it 'calls AI client' do
|
44
|
+
path = '/tmp/import.json'
|
45
|
+
expect(AiClient).to receive(:import).with(path)
|
21
46
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"utterances" => [
|
26
|
-
"What are the best AI courses?"
|
27
|
-
],
|
28
|
-
"response": "Fast.ai MOOC http://course.fast.ai and Coursers"
|
29
|
-
}
|
30
|
-
]
|
31
|
-
}
|
47
|
+
Ai.import(path)
|
48
|
+
end
|
49
|
+
end
|
32
50
|
|
33
|
-
|
51
|
+
context 'given learn' do
|
52
|
+
it 'calls AI client' do
|
53
|
+
utterance = 'What is TDD?'
|
54
|
+
response = "TDD stands for Test Driven Development"
|
55
|
+
expect(AiClient).to receive(:learn_answer).with([utterance], response)
|
34
56
|
|
35
|
-
|
57
|
+
Ai.learn_answer([utterance], response)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'given learn script' do
|
62
|
+
it 'calls AI client' do
|
63
|
+
utterance = 'show changes'
|
64
|
+
script = 'git diff'
|
65
|
+
expect(AiClient).to receive(:learn_script).with(utterance, script)
|
66
|
+
|
67
|
+
Ai.learn_script(utterance, script)
|
68
|
+
end
|
36
69
|
end
|
37
70
|
end
|
38
71
|
|
39
|
-
describe '
|
40
|
-
it '
|
41
|
-
|
72
|
+
describe '#list_answers' do
|
73
|
+
it 'calls AI client' do
|
74
|
+
expect(AiClient).to receive(:list_answers)
|
42
75
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
"utterances" => [
|
47
|
-
"show changes"
|
48
|
-
],
|
49
|
-
"script": "git diff"
|
50
|
-
}
|
51
|
-
]
|
52
|
-
}
|
76
|
+
Ai.list_answers
|
77
|
+
end
|
78
|
+
end
|
53
79
|
|
54
|
-
|
80
|
+
describe '#list_scripts' do
|
81
|
+
it 'calls AI client' do
|
82
|
+
expect(AiClient).to receive(:list_scripts)
|
55
83
|
|
56
|
-
|
84
|
+
Ai.list_scripts
|
57
85
|
end
|
58
86
|
end
|
59
87
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Pliszka
|
@@ -18,6 +18,8 @@ executables:
|
|
18
18
|
- ai-import
|
19
19
|
- ai-learn-script
|
20
20
|
- ai-learn-answer
|
21
|
+
- ai-list-answers
|
22
|
+
- ai-list-scripts
|
21
23
|
extensions: []
|
22
24
|
extra_rdoc_files: []
|
23
25
|
files:
|
@@ -25,6 +27,8 @@ files:
|
|
25
27
|
- bin/ai-import
|
26
28
|
- bin/ai-learn-answer
|
27
29
|
- bin/ai-learn-script
|
30
|
+
- bin/ai-list-answers
|
31
|
+
- bin/ai-list-scripts
|
28
32
|
- lib/ai.rb
|
29
33
|
- lib/ai_client.rb
|
30
34
|
- lib/constants.rb
|