ai 0.0.1
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 +7 -0
- data/bin/ai +6 -0
- data/lib/ai.rb +26 -0
- data/spec/ai_spec.rb +43 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0edef7f201e016d718ffb659af381c32c5eaae07
|
4
|
+
data.tar.gz: 2df14d968144d0f1b3bbd7d9c7f158c0f8f559ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2cb3d7ece962adb5b7aa640dc99798a4b9ff36457e04af2f1d147aa24b29704fdc21ba08f8c8ca7499424782e0a18861afe0be7e6045abc14d7499b7a0cfe23
|
7
|
+
data.tar.gz: fe2827f3d2a8be77e37a6cf7b7c0ae549bd857e76d263dfc645a5877ea70185bb0863e2710809a3c328b744b33caa7c2bc451ca7d4cb3e5d1c0fa6f003994b7b
|
data/bin/ai
ADDED
data/lib/ai.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class Ai
|
6
|
+
def self.process(utterance)
|
7
|
+
response = post(utterance)
|
8
|
+
if response['type'] == 'script'
|
9
|
+
Kernel.system response['script']
|
10
|
+
else
|
11
|
+
Kernel.puts response['text']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.post(utterance)
|
16
|
+
uri = URI.parse(ENV['REPLY_URL'] || "http://milligan-acceptance.herokuapp.com/milligans/reply")
|
17
|
+
|
18
|
+
data = { utterance: utterance }.to_json
|
19
|
+
|
20
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
21
|
+
response = https.request_post(uri.path, data, 'Content-Type' => 'application/json')
|
22
|
+
|
23
|
+
JSON.parse(response.body)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/spec/ai_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ai'
|
2
|
+
|
3
|
+
RSpec.describe Ai do
|
4
|
+
describe '#process' do
|
5
|
+
it 'makes a post request' do
|
6
|
+
http = double("Http")
|
7
|
+
expect(Net::HTTP).to receive(:new).and_return(http)
|
8
|
+
response = double('Response')
|
9
|
+
expect(response).to receive(:body).and_return({'type' => 'script', 'script' => 'ls -a'}.to_json)
|
10
|
+
expect(http).to receive(:request_post).and_return(response)
|
11
|
+
expect(Kernel).to receive(:system).with('ls -a').and_return(true)
|
12
|
+
# request = double('Response')
|
13
|
+
# expect(Net::HTTP::Post).to receive(:new).and_return(request)
|
14
|
+
# expect(request).to receive(:body=).with("{\"utterance\":\"show files\"}")
|
15
|
+
# expect(http).to receive(:request).and_return(response)
|
16
|
+
|
17
|
+
Ai.process('show files')
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'given acton response' do
|
21
|
+
it 'runs the command' do
|
22
|
+
response = {'type' => 'script', 'script' => 'ls -a'}
|
23
|
+
|
24
|
+
expect(Kernel).to receive(:system).with('ls -a').and_return(true)
|
25
|
+
expect(Ai).to receive(:post).and_return(response)
|
26
|
+
|
27
|
+
Ai.process('show files')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'given text response' do
|
32
|
+
it 'prints the response' do
|
33
|
+
response = {'type' => 'text', 'text' => 'hi'}
|
34
|
+
|
35
|
+
expect(Kernel).to_not receive(:system)
|
36
|
+
expect(Kernel).to receive(:puts).with('hi').and_return(true)
|
37
|
+
expect(Ai).to receive(:post).and_return(response)
|
38
|
+
|
39
|
+
Ai.process('Hello')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Pliszka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: PivotalAI is a artificial intelligence and natural language processing
|
14
|
+
platform optimized for user happines and productivity.
|
15
|
+
email: andy@pivotalai.com
|
16
|
+
executables:
|
17
|
+
- ai
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/ai
|
22
|
+
- lib/ai.rb
|
23
|
+
- spec/ai_spec.rb
|
24
|
+
homepage: http://pivotalai.com
|
25
|
+
licenses: []
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.5.1
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Command line client for PivotalAI
|
47
|
+
test_files:
|
48
|
+
- spec/ai_spec.rb
|