Class: Ai

Inherits:
Object
  • Object
show all
Defined in:
lib/ai.rb

Class Method Summary collapse

Class Method Details

.import(path) ⇒ Object



27
28
29
# File 'lib/ai.rb', line 27

def self.import(path)
  ::AiClient.import(path)
end

.learn_answer(questions, answer) ⇒ Object



31
32
33
# File 'lib/ai.rb', line 31

def self.learn_answer(questions, answer)
  ::AiClient.learn_answer(questions, answer)
end

.learn_script(questions, answer) ⇒ Object



35
36
37
# File 'lib/ai.rb', line 35

def self.learn_script(questions, answer)
  ::AiClient.learn_script(questions, answer)
end

.list_answersObject



39
40
41
# File 'lib/ai.rb', line 39

def self.list_answers
  ::AiClient.list_answers
end

.list_scriptsObject



43
44
45
# File 'lib/ai.rb', line 43

def self.list_scripts
  ::AiClient.list_scripts
end

.post(utterance) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ai.rb', line 16

def self.post(utterance)
  uri = URI.parse((ENV['PIVOTAL_API_URL'] || "http://milligan-acceptance.herokuapp.com") + "/milligans/reply")

  data = { utterance: utterance }.to_json

  https = Net::HTTP.new(uri.host, uri.port)
  response = https.request_post(uri.path, data, 'Content-Type' => 'application/json')

  JSON.parse(response.body)
end

.process(utterance) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/ai.rb', line 7

def self.process(utterance)
  response = post(utterance)
  if response['type'] == 'script'
    Kernel.system response['script']
  else
    Kernel.puts response['text']
  end
end