ai 0.0.1 → 0.0.2
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 +4 -4
- data/bin/ai-import +6 -0
- data/bin/ai-learn-answer +13 -0
- data/bin/ai-learn-script +13 -0
- data/lib/ai.rb +13 -0
- data/lib/ai_client.rb +38 -0
- data/lib/constants.rb +1 -0
- data/lib/web_client.rb +22 -0
- data/spec/ai_spec.rb +48 -32
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aa72c3d7d57c0ac6ee419dcba9852763d906a93
|
4
|
+
data.tar.gz: 24885f0576dc51585c41fa1a6968e71e6d1ce25d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac0361bc12ac255195918c7063a02da6e15b3668b8fa645f22f82340e7a93007d59cb854bcc5206692aac462e91d4fb1ff0184b6af6e5b599700eba43e660d8e
|
7
|
+
data.tar.gz: a688d7d6c7249549f97742fc5ccf7caa8e156ccfb4d8e1203e6feb21d6132561703eee5734e62eda3f8214166815a7050d303b3149e5af290e2ca67997239fbb
|
data/bin/ai-import
ADDED
data/bin/ai-learn-answer
ADDED
data/bin/ai-learn-script
ADDED
data/lib/ai.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
|
+
require 'ai_client'
|
4
5
|
|
5
6
|
class Ai
|
6
7
|
def self.process(utterance)
|
@@ -22,5 +23,17 @@ class Ai
|
|
22
23
|
|
23
24
|
JSON.parse(response.body)
|
24
25
|
end
|
26
|
+
|
27
|
+
def self.import(path)
|
28
|
+
::AiClient.import(path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.learn_answer(questions, answer)
|
32
|
+
::AiClient.learn_answer(questions, answer)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.learn_script(questions, answer)
|
36
|
+
::AiClient.learn_script(questions, answer)
|
37
|
+
end
|
25
38
|
end
|
26
39
|
|
data/lib/ai_client.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'web_client'
|
2
|
+
require 'constants'
|
3
|
+
|
4
|
+
class AiClient
|
5
|
+
def self.import(path)
|
6
|
+
data = { knowledge: JSON.parse(File.read(path)) }
|
7
|
+
|
8
|
+
WebClient.post(BASE_URL + '/api/v1/direct_responses/import', data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.learn_answer(utterances, response)
|
12
|
+
body = { knowledge: {
|
13
|
+
"knowledge" => [
|
14
|
+
{
|
15
|
+
"utterances" => utterances,
|
16
|
+
"response": response
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
WebClient.post(BASE_URL + '/api/v1/direct_responses/import', body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.learn_script(utterances, script)
|
26
|
+
body = { knowledge: {
|
27
|
+
"scripts" => [
|
28
|
+
{
|
29
|
+
"utterances" => utterances,
|
30
|
+
"script": script
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
WebClient.post(BASE_URL + '/api/v1/direct_responses/import', body)
|
37
|
+
end
|
38
|
+
end
|
data/lib/constants.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
BASE_URL=ENV['PIVOTAL_API_URL'] || "http://milligan-acceptance.herokuapp.com"
|
data/lib/web_client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class WebClient
|
5
|
+
def self.post(url, body)
|
6
|
+
uri = URI.parse(url)
|
7
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
8
|
+
|
9
|
+
request = Net::HTTP::Post.new(
|
10
|
+
uri.request_uri,
|
11
|
+
'Content-Type' => 'application/json'
|
12
|
+
)
|
13
|
+
request.body = body.to_json
|
14
|
+
|
15
|
+
response = http.request(request)
|
16
|
+
unless response.body.nil?
|
17
|
+
JSON.parse(response.body)
|
18
|
+
else
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/ai_spec.rb
CHANGED
@@ -1,43 +1,59 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# expect(http).to receive(:request).and_return(response)
|
16
|
-
|
17
|
-
Ai.process('show files')
|
1
|
+
require 'ai_client'
|
2
|
+
require 'web_client'
|
3
|
+
|
4
|
+
RSpec.describe AiClient do
|
5
|
+
describe 'self#import' do
|
6
|
+
it 'submits import file to the server' do
|
7
|
+
url = "http://localhost:4040/api/v1/direct_responses/import"
|
8
|
+
|
9
|
+
path = '/Users/apliszka/workspace/ai/spec/fixtures/import.json'
|
10
|
+
body = { knowledge: JSON.parse(File.read(path)) }
|
11
|
+
|
12
|
+
expect(WebClient).to receive(:post).with(url, body)
|
13
|
+
|
14
|
+
AiClient.import(path)
|
18
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'self#learn' do
|
19
|
+
it 'submits new utterance to server' do
|
20
|
+
url = "http://localhost:4040/api/v1/direct_responses/import"
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
body = {
|
23
|
+
"knowledge" => [
|
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
|
+
}
|
23
32
|
|
24
|
-
|
25
|
-
expect(Ai).to receive(:post).and_return(response)
|
33
|
+
expect(WebClient).to receive(:post).with(url, { knowledge: body })
|
26
34
|
|
27
|
-
|
28
|
-
end
|
35
|
+
AiClient.learn_answer(["What are the best AI courses?"], "Fast.ai MOOC http://course.fast.ai and Coursers")
|
29
36
|
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'self#learn_script' do
|
40
|
+
it 'submits new script to server' do
|
41
|
+
url = "http://localhost:4040/api/v1/direct_responses/import"
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
|
43
|
+
body = {
|
44
|
+
"scripts" => [
|
45
|
+
{
|
46
|
+
"utterances" => [
|
47
|
+
"show changes"
|
48
|
+
],
|
49
|
+
"script": "git diff"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
34
53
|
|
35
|
-
|
36
|
-
expect(Kernel).to receive(:puts).with('hi').and_return(true)
|
37
|
-
expect(Ai).to receive(:post).and_return(response)
|
54
|
+
expect(WebClient).to receive(:post).with(url, { knowledge: body })
|
38
55
|
|
39
|
-
|
40
|
-
end
|
56
|
+
AiClient.learn_script(["show changes"], "git diff")
|
41
57
|
end
|
42
58
|
end
|
43
59
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Pliszka
|
@@ -15,11 +15,20 @@ description: PivotalAI is a artificial intelligence and natural language process
|
|
15
15
|
email: andy@pivotalai.com
|
16
16
|
executables:
|
17
17
|
- ai
|
18
|
+
- ai-import
|
19
|
+
- ai-learn-script
|
20
|
+
- ai-learn-answer
|
18
21
|
extensions: []
|
19
22
|
extra_rdoc_files: []
|
20
23
|
files:
|
21
24
|
- bin/ai
|
25
|
+
- bin/ai-import
|
26
|
+
- bin/ai-learn-answer
|
27
|
+
- bin/ai-learn-script
|
22
28
|
- lib/ai.rb
|
29
|
+
- lib/ai_client.rb
|
30
|
+
- lib/constants.rb
|
31
|
+
- lib/web_client.rb
|
23
32
|
- spec/ai_spec.rb
|
24
33
|
homepage: http://pivotalai.com
|
25
34
|
licenses: []
|