RecastAI 3.1.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/recastai.rb +2 -1
- data/lib/recastai/apis/build/build.rb +67 -0
- data/lib/recastai/apis/build/dialog_conversation.rb +13 -0
- data/lib/recastai/apis/build/dialog_message.rb +17 -0
- data/lib/recastai/apis/build/dialog_response.rb +16 -0
- data/lib/recastai/apis/request/analyse.rb +2 -2
- data/lib/recastai/apis/request/models/response.rb +1 -3
- data/lib/recastai/utils.rb +3 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3775640528153be33dbad2afa118676fae716a4d
|
4
|
+
data.tar.gz: 51715b59420d86284953a04a7683b4774a3c48a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f237a24246e81ffe3411a06de47c1564223d2db861533c7352715fe5ed2c1bb46b84d2e920410faecdd46da5f0a5f18a05b36e2ba42b28b66369b36bdfde489
|
7
|
+
data.tar.gz: 4658edfbc0fb383f441fb9f2b4b7e0daace19f3c147b47efe0bbbf1aae909ffb8ee56075b00ca04e417811c0b53333d83ff36295d8e6170f3a25e4330eb63a19
|
data/lib/recastai.rb
CHANGED
@@ -9,13 +9,14 @@ require 'httmultiparty'
|
|
9
9
|
require 'recastai/utils'
|
10
10
|
require 'recastai/apis/connect/connect'
|
11
11
|
require 'recastai/apis/request/request'
|
12
|
+
require 'recastai/apis/build/build'
|
12
13
|
|
13
14
|
module RecastAI
|
14
15
|
class Client
|
15
16
|
attr_reader :token, :language
|
16
17
|
|
17
18
|
def initialize(token = nil, language = nil)
|
18
|
-
[RecastAI::Request, RecastAI::Connect].each do |api|
|
19
|
+
[RecastAI::Request, RecastAI::Connect, RecastAI::Build].each do |api|
|
19
20
|
i = api.name.rindex('::')
|
20
21
|
name = i.nil? ? api.name : api.name[(i + 2)..-1]
|
21
22
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
require_relative 'dialog_response'
|
6
|
+
require_relative 'dialog_message'
|
7
|
+
require_relative 'dialog_conversation'
|
8
|
+
|
9
|
+
module RecastAI
|
10
|
+
class Build
|
11
|
+
attr_reader :token, :language
|
12
|
+
|
13
|
+
def initialize(token = nil, language = nil)
|
14
|
+
@token = token
|
15
|
+
@language = language
|
16
|
+
end
|
17
|
+
|
18
|
+
def headers
|
19
|
+
{ 'Authorization' => "Token #{@token}", 'Content-Type' => 'application/json' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def dialog(msg, conversation_id, language = nil)
|
23
|
+
raise RecastAI::RecastError.new('Token is missing') unless @token
|
24
|
+
|
25
|
+
language = @language if language.nil?
|
26
|
+
body = { message: msg, conversation_id: conversation_id, language: language }
|
27
|
+
|
28
|
+
response = HTTParty.post("#{RecastAI::Utils::BUILD_ENDPOINT}/dialog", body: body.to_json, headers: self.headers)
|
29
|
+
raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
|
30
|
+
|
31
|
+
res = JSON.parse(response.body)['results']
|
32
|
+
RecastAI::DialogResponse.new(res['messages'], res['conversation'], res['nlp'])
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_conversation(user, bot, conversation_id, opts)
|
36
|
+
raise RecastAI::RecastError.new('Token is missing') unless @token
|
37
|
+
|
38
|
+
body = opts
|
39
|
+
|
40
|
+
url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}"
|
41
|
+
response = HTTParty.put(url, body: body.to_json, headers: self.headers)
|
42
|
+
raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
|
43
|
+
|
44
|
+
RecastAI::DialogConversation.new(JSON.parse(response.body)['results'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_conversation(user, bot, conversation_id)
|
48
|
+
raise RecastAI::RecastError.new('Token is missing') unless @token
|
49
|
+
|
50
|
+
url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}"
|
51
|
+
response = HTTParty.get(url, headers: self.headers)
|
52
|
+
raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
|
53
|
+
|
54
|
+
RecastAI::DialogConversation.new(JSON.parse(response.body)['results'])
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_conversation(user, bot, conversation_id)
|
58
|
+
raise RecastAI::RecastError.new('Token is missing') unless @token
|
59
|
+
|
60
|
+
url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}"
|
61
|
+
response = HTTParty.delete(url, headers: self.headers)
|
62
|
+
raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 204
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RecastAI
|
2
|
+
class DialogConversation
|
3
|
+
attr_reader :id, :language, :memory, :skill, :skill_occurences
|
4
|
+
|
5
|
+
def initialize(conv)
|
6
|
+
@id = conv['conversation_id'] || conv['id']
|
7
|
+
@language = conv['language']
|
8
|
+
@memory = conv['memory']
|
9
|
+
@skill = conv['skill'] || conv['last_skill']
|
10
|
+
@skill_occurences = conv['skill_occurences'] || skill['last_skill_occurences']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RecastAI
|
2
|
+
class DialogMessage
|
3
|
+
attr_reader :type, :content
|
4
|
+
|
5
|
+
def initialize(msg)
|
6
|
+
raise RecastAI::RecastError('Invalid message format') unless message_is_valid(msg)
|
7
|
+
@type = msg['type']
|
8
|
+
@content = msg['content']
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def message_is_valid(msg)
|
14
|
+
msg.is_a?(Hash) && msg.key?('type') && msg.key?('content')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'dialog_message'
|
2
|
+
require_relative 'dialog_conversation'
|
3
|
+
require_relative '../request/models/response'
|
4
|
+
module RecastAI
|
5
|
+
class DialogResponse
|
6
|
+
attr_reader :messages, :conversation, :nlp
|
7
|
+
|
8
|
+
def initialize(messages, conversation, nlp)
|
9
|
+
raise RecastAI::RecastError("Invalid messages format: #{messages}") unless messages.is_a?(Array)
|
10
|
+
|
11
|
+
@messages = messages.map{ |m| RecastAI::DialogMessage.new(m) }
|
12
|
+
@conversation = DialogConversation.new(conversation)
|
13
|
+
@nlp = Response.new('results' => nlp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -21,7 +21,7 @@ module RecastAI
|
|
21
21
|
)
|
22
22
|
raise RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
|
23
23
|
|
24
|
-
Response.new(response.body)
|
24
|
+
Response.new(JSON.parse(response.body))
|
25
25
|
end
|
26
26
|
|
27
27
|
def analyse_file(file, token: nil, language: nil)
|
@@ -39,7 +39,7 @@ module RecastAI
|
|
39
39
|
)
|
40
40
|
raise RecastError.new(JSON.parse(response.body)['message']) if response.code != 200
|
41
41
|
|
42
|
-
Response.new(response.body)
|
42
|
+
Response.new(JSON.parse(response.body))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/recastai/utils.rb
CHANGED
@@ -4,8 +4,8 @@ module RecastAI
|
|
4
4
|
class Utils
|
5
5
|
# Versioning
|
6
6
|
MAJOR = '3'.freeze
|
7
|
-
MINOR = '
|
8
|
-
PATCH = '
|
7
|
+
MINOR = '2'.freeze
|
8
|
+
PATCH = '0'.freeze
|
9
9
|
VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
|
10
10
|
|
11
11
|
# Endpoints
|
@@ -13,5 +13,6 @@ module RecastAI
|
|
13
13
|
CONNECT_ENDPOINT = 'https://api.recast.ai/connect/v1/'.freeze
|
14
14
|
HOST_ENDPOINT = 'https://api.recast.ai/host/v1/'.freeze
|
15
15
|
MONITOR_ENDPOINT = 'https://api.recast.ai/monitor/v1/'.freeze
|
16
|
+
BUILD_ENDPOINT = 'https://api.recast.ai/build/v1'.freeze
|
16
17
|
end
|
17
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RecastAI
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Renvoisé
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -111,6 +111,10 @@ files:
|
|
111
111
|
- README.md
|
112
112
|
- bin/recastcli
|
113
113
|
- lib/recastai.rb
|
114
|
+
- lib/recastai/apis/build/build.rb
|
115
|
+
- lib/recastai/apis/build/dialog_conversation.rb
|
116
|
+
- lib/recastai/apis/build/dialog_message.rb
|
117
|
+
- lib/recastai/apis/build/dialog_response.rb
|
114
118
|
- lib/recastai/apis/connect/connect.rb
|
115
119
|
- lib/recastai/apis/connect/message.rb
|
116
120
|
- lib/recastai/apis/connect/models/message.rb
|