qna_maker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rubocop.yml +2 -0
- data/.travis.yml +2 -0
- data/README.md +13 -9
- data/bin/console +2 -9
- data/lib/qna_maker/endpoints/create_kb.rb +2 -2
- data/lib/qna_maker/endpoints/delete_kb.rb +8 -8
- data/lib/qna_maker/endpoints/download_alterations.rb +3 -3
- data/lib/qna_maker/endpoints/download_kb.rb +2 -2
- data/lib/qna_maker/endpoints/generate_answer.rb +5 -5
- data/lib/qna_maker/endpoints/publish_kb.rb +5 -5
- data/lib/qna_maker/endpoints/train_kb.rb +35 -19
- data/lib/qna_maker/endpoints/update_alterations.rb +27 -0
- data/lib/qna_maker/endpoints/update_kb.rb +32 -12
- data/lib/qna_maker/errors.rb +3 -0
- data/lib/qna_maker/version.rb +1 -1
- data/lib/qna_maker.rb +3 -3
- data/qna_maker.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee955956af27b2b001676c32496cd94f4c89db0ee3bd7c5d3717c22e955209e
|
4
|
+
data.tar.gz: e664c1ac7c731bbf5aa0c6fd9c81603674a489824fa1cdd475d123f6deade505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee21db904abbf80f6eb34edb3d9da0ffc19e4f7bb47e5ff846c137b874b7286857b63fae99913aaac388830d411e317ad54daf64aecf66c4f2de7823661b469
|
7
|
+
data.tar.gz: 1c0785b5c633dc95f3c32aa4af42bd42a9f53885a2b22c0473b661c58bf8d44bfb14783dab92027c61118405c58f95b7d5ec65c5bae9b43f232e99213efff977
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# QnAMaker
|
2
2
|
|
3
|
-
|
3
|
+
![Gem](https://img.shields.io/gem/dv/qna_maker/stable.svg)
|
4
|
+
[![Build Status](https://travis-ci.org/Birdie0/qna_maker.svg?branch=master)](https://travis-ci.org/Birdie0/qna_maker)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/96bf3ebcfe21cd1b9359/maintainability)](https://codeclimate.com/github/Birdie0/qna_maker/maintainability)
|
6
|
+
|
7
|
+
API wrapper for [QnA Maker](https://qnamaker.ai)
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -24,13 +28,13 @@ Or install it yourself as:
|
|
24
28
|
require 'qna_maker'
|
25
29
|
|
26
30
|
client = QnAMaker::Client.new('kb_id' , 'subscription_key')
|
27
|
-
|
31
|
+
#=> #<QnAMaker::Client @knowledgebase_id="kb_id", @subscription_key="subscription_key", ...>
|
28
32
|
|
29
33
|
answers = client.generate_answer('hi')
|
30
|
-
|
34
|
+
#=> [#<QnAMaker::Answer @answer="hello", @questions=["hi"], @score=100.0>]
|
31
35
|
|
32
|
-
|
33
|
-
|
36
|
+
answers.first.answer
|
37
|
+
#=> "hello"
|
34
38
|
```
|
35
39
|
|
36
40
|
## Development status
|
@@ -39,16 +43,16 @@ Gem is under active development! It isn't finished yet!
|
|
39
43
|
|
40
44
|
### Todo list
|
41
45
|
|
42
|
-
* [
|
46
|
+
* [x] Methods
|
43
47
|
* [x] **POST** - Create Knowledge Base
|
44
48
|
* [x] **DELETE** - Delete Knowledge Base
|
45
49
|
* [x] **GET** - Download Alterations
|
46
50
|
* [x] **GET** - Download Knowledge Base
|
47
51
|
* [x] **POST** - Generate answer
|
48
52
|
* [x] **PUT** - Publish Knowledge Base
|
49
|
-
* [
|
50
|
-
* [
|
51
|
-
* [
|
53
|
+
* [x] **PATCH** - Train Knowledge Base
|
54
|
+
* [x] **PATCH** - Update Alterations
|
55
|
+
* [x] **PATCH** - Update Knowledge Base
|
52
56
|
* [ ] Documentation
|
53
57
|
* [ ] Tests
|
54
58
|
|
data/bin/console
CHANGED
@@ -3,12 +3,5 @@
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'qna_maker'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|
6
|
+
require 'pry'
|
7
|
+
Pry.start
|
@@ -22,7 +22,7 @@ module QnAMaker
|
|
22
22
|
when 401
|
23
23
|
raise UnauthorizedError, response.parse['error']['message']
|
24
24
|
else
|
25
|
-
raise UnknownError,
|
25
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -48,7 +48,7 @@ module QnAMaker
|
|
48
48
|
when 401
|
49
49
|
raise UnauthorizedError, response.parse['error']['message']
|
50
50
|
else
|
51
|
-
raise UnknownError,
|
51
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -13,13 +13,13 @@ module QnAMaker
|
|
13
13
|
when 401
|
14
14
|
raise UnauthorizedError, response.parse['error']['message']
|
15
15
|
when 403
|
16
|
-
raise
|
16
|
+
raise ForbiddenError, response.parse['error']['message']
|
17
17
|
when 404
|
18
|
-
raise NotFoundError, response.parse['error']['message']
|
18
|
+
raise NotFoundError, response.parse['error']['message']
|
19
19
|
when 409
|
20
|
-
raise ConflictError, response.parse['error']['message']
|
20
|
+
raise ConflictError, response.parse['error']['message']
|
21
21
|
else
|
22
|
-
raise UnknownError,
|
22
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -36,13 +36,13 @@ module QnAMaker
|
|
36
36
|
when 401
|
37
37
|
raise UnauthorizedError, response.parse['error']['message']
|
38
38
|
when 403
|
39
|
-
raise
|
39
|
+
raise ForbiddenError, response.parse['error']['message']
|
40
40
|
when 404
|
41
|
-
raise NotFoundError, response.parse['error']['message']
|
41
|
+
raise NotFoundError, response.parse['error']['message']
|
42
42
|
when 409
|
43
|
-
raise ConflictError, response.parse['error']['message']
|
43
|
+
raise ConflictError, response.parse['error']['message']
|
44
44
|
else
|
45
|
-
raise UnknownError,
|
45
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -18,11 +18,11 @@ module QnAMaker
|
|
18
18
|
when 401
|
19
19
|
raise UnauthorizedError, response.parse['error']['message']
|
20
20
|
when 403
|
21
|
-
raise
|
21
|
+
raise ForbiddenError, response.parse['error']['message']
|
22
22
|
when 404
|
23
|
-
raise NotFoundError, response.parse['error']['message']
|
23
|
+
raise NotFoundError, response.parse['error']['message']
|
24
24
|
else
|
25
|
-
raise UnknownError,
|
25
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -13,11 +13,11 @@ module QnAMaker
|
|
13
13
|
when 401
|
14
14
|
raise UnauthorizedError, response.parse['error']['message']
|
15
15
|
when 403
|
16
|
-
raise
|
16
|
+
raise ForbiddenError, response.parse['error']['message'].join(' ')
|
17
17
|
when 404
|
18
18
|
raise NotFoundError, response.parse['error']['message'].join(' ')
|
19
19
|
else
|
20
|
-
raise UnknownError,
|
20
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -20,15 +20,15 @@ module QnAMaker
|
|
20
20
|
when 401
|
21
21
|
raise UnauthorizedError, response.parse['error']['message']
|
22
22
|
when 403
|
23
|
-
raise QuotaExceededError, response.parse['error']['message']
|
23
|
+
raise QuotaExceededError, response.parse['error']['message']
|
24
24
|
when 404
|
25
|
-
raise NotFoundError, response.parse['error']['message']
|
25
|
+
raise NotFoundError, response.parse['error']['message']
|
26
26
|
when 408
|
27
|
-
raise OperationTimeOutError, response.parse['error']['message']
|
27
|
+
raise OperationTimeOutError, response.parse['error']['message']
|
28
28
|
when 429
|
29
|
-
raise RateLimitExceededError, response.parse['error']['message']
|
29
|
+
raise RateLimitExceededError, response.parse['error']['message']
|
30
30
|
else
|
31
|
-
raise UnknownError,
|
31
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -12,14 +12,14 @@ module QnAMaker
|
|
12
12
|
raise BadArgumentError, response.parse['error']['message'].join(' ')
|
13
13
|
when 401
|
14
14
|
raise UnauthorizedError, response.parse['error']['message']
|
15
|
-
when 404
|
16
|
-
raise NotFoundError, response.parse['error']['message'].join(' ')
|
17
15
|
when 403
|
18
|
-
raise
|
16
|
+
raise ForbiddenError, response.parse['error']['message']
|
17
|
+
when 404
|
18
|
+
raise NotFoundError, response.parse['error']['message']
|
19
19
|
when 409
|
20
|
-
raise ConflictError, response.parse['error']['message']
|
20
|
+
raise ConflictError, response.parse['error']['message']
|
21
21
|
else
|
22
|
-
raise UnknownError,
|
22
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,19 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
module QnAMaker
|
2
|
+
class Client
|
3
|
+
def train_kb(feedback_records = [])
|
4
|
+
feedback_records = feedback_records.map do |record|
|
5
|
+
{ userId: record[0],
|
6
|
+
userQuestion: record[1],
|
7
|
+
kbQuestion: record[2],
|
8
|
+
kbAnswer: record[3] }
|
9
|
+
end
|
10
|
+
response = @http.patch(
|
11
|
+
"#{BASE_URL}/#{@knowledgebase_id}/train",
|
12
|
+
json: { feedbackRecords: feedback_records }
|
13
|
+
)
|
14
|
+
|
15
|
+
case response.code
|
16
|
+
when 204
|
17
|
+
nil
|
18
|
+
when 400
|
19
|
+
raise BadArgumentError, response.parse['error']['message'].join(' ')
|
20
|
+
when 401
|
21
|
+
raise UnauthorizedError, response.parse['error']['message']
|
22
|
+
when 403
|
23
|
+
raise ForbiddenError, response.parse['error']['message']
|
24
|
+
when 404
|
25
|
+
raise NotFoundError, response.parse['error']['message']
|
26
|
+
when 408
|
27
|
+
raise OperationTimeOutError, response.parse['error']['message']
|
28
|
+
when 429
|
29
|
+
raise RateLimitExceededError, response.parse['error']['message']
|
30
|
+
else
|
31
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module QnAMaker
|
2
|
+
class Client
|
3
|
+
def update_alterations(add = [], delete = [])
|
4
|
+
response = @http.patch(
|
5
|
+
"#{BASE_URL}/#{@knowledgebase_id}/updateAlterations",
|
6
|
+
json: { add: add, delete: delete }
|
7
|
+
)
|
8
|
+
|
9
|
+
case response.code
|
10
|
+
when 204
|
11
|
+
nil
|
12
|
+
when 400
|
13
|
+
raise BadArgumentError, response.parse['error']['message'].join(' ')
|
14
|
+
when 401
|
15
|
+
raise UnauthorizedError, response.parse['error']['message']
|
16
|
+
when 403
|
17
|
+
raise ForbiddenError, response.parse['error']['message']
|
18
|
+
when 404
|
19
|
+
raise NotFoundError, response.parse['error']['message']
|
20
|
+
when 409
|
21
|
+
raise ConflictError, response.parse['error']['message']
|
22
|
+
else
|
23
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,13 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
1
|
+
module QnAMaker
|
2
|
+
class Client
|
3
|
+
def update_kb(add = [], delete = [], add_urls = [])
|
4
|
+
response = @http.patch(
|
5
|
+
"#{BASE_URL}/#{@knowledgebase_id}",
|
6
|
+
json: {
|
7
|
+
add: {
|
8
|
+
qnaPairs: add.map { |pair| { question: pair[0], answer: pair[1] } },
|
9
|
+
urls: add_urls
|
10
|
+
},
|
11
|
+
delete: { qnaPairs: delete.map { |pair| { question: pair[0], answer: pair[1] } } }
|
12
|
+
}
|
13
|
+
)
|
6
14
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
case response.code
|
16
|
+
when 204
|
17
|
+
nil
|
18
|
+
when 400
|
19
|
+
raise BadArgumentError, response.parse['error']['message'].join(' ')
|
20
|
+
when 401
|
21
|
+
raise UnauthorizedError, response.parse['error']['message']
|
22
|
+
when 403
|
23
|
+
raise ForbiddenError, response.parse['error']['message']
|
24
|
+
when 404
|
25
|
+
raise NotFoundError, response.parse['error']['message']
|
26
|
+
when 409
|
27
|
+
raise ConflictError, response.parse['error']['message']
|
28
|
+
else
|
29
|
+
raise UnknownError, "Oh no! (#{response.code})"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/qna_maker/errors.rb
CHANGED
data/lib/qna_maker/version.rb
CHANGED
data/lib/qna_maker.rb
CHANGED
@@ -11,9 +11,9 @@ require 'qna_maker/endpoints/download_alterations'
|
|
11
11
|
require 'qna_maker/endpoints/download_kb'
|
12
12
|
require 'qna_maker/endpoints/generate_answer'
|
13
13
|
require 'qna_maker/endpoints/publish_kb'
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
require 'qna_maker/endpoints/train_kb'
|
15
|
+
require 'qna_maker/endpoints/update_kb'
|
16
|
+
require 'qna_maker/endpoints/update_alterations'
|
17
17
|
|
18
18
|
require 'http'
|
19
19
|
|
data/qna_maker.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'http', '~> 3.0'
|
26
26
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0.11.3'
|
28
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qna_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Birdie0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '1.16'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.11.3
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.11.3
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: rake
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +128,7 @@ files:
|
|
114
128
|
- lib/qna_maker/endpoints/generate_answer.rb
|
115
129
|
- lib/qna_maker/endpoints/publish_kb.rb
|
116
130
|
- lib/qna_maker/endpoints/train_kb.rb
|
131
|
+
- lib/qna_maker/endpoints/update_alterations.rb
|
117
132
|
- lib/qna_maker/endpoints/update_kb.rb
|
118
133
|
- lib/qna_maker/errors.rb
|
119
134
|
- lib/qna_maker/string.rb
|