Class: AiClient

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

Class Method Summary collapse

Class Method Details

.import(path) ⇒ Object



5
6
7
8
9
# File 'lib/ai_client.rb', line 5

def self.import(path)
  data = { knowledge: JSON.parse(File.read(path)) }

  WebClient.post(BASE_URL + '/api/v1/direct_responses/import', data)
end

.learn_answer(utterances, response) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ai_client.rb', line 11

def self.learn_answer(utterances, response)
  body = { knowledge: {
    "knowledge" => [
      {
        "utterances" => utterances,
        "response": response
      }
    ]
  }
}

  WebClient.post(BASE_URL + '/api/v1/direct_responses/import', body)
end

.learn_script(utterances, script) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ai_client.rb', line 25

def self.learn_script(utterances, script)
  body = { knowledge: {
    "scripts" => [
      {
        "utterances" => utterances,
        "script": script
      }
    ]
  }
}

  WebClient.post(BASE_URL + '/api/v1/direct_responses/import', body)
end

.list_answersObject



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

def self.list_answers
  WebClient.get(BASE_URL + '/api/v1/direct_responses')
end

.list_scriptsObject



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

def self.list_scripts
  WebClient.get(BASE_URL + '/api/v1/script_responses')
end