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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4103f532e31d381a82ed32c049d72a21547b3fae676d97630db2b5d1fc66a8b
4
- data.tar.gz: ae4efc18758b6a37e439f7d999d47ecf6e0f4b3d44f6d30ba907d72bff6daa2a
3
+ metadata.gz: 0ee955956af27b2b001676c32496cd94f4c89db0ee3bd7c5d3717c22e955209e
4
+ data.tar.gz: e664c1ac7c731bbf5aa0c6fd9c81603674a489824fa1cdd475d123f6deade505
5
5
  SHA512:
6
- metadata.gz: 35f412b81b086f3b167e234453665cc8992514fd486b2271600245053d7cc2723cd50cf9b0076dd1f741753bbb79aede1d391c7f3e2c24259667f73ac9a727c9
7
- data.tar.gz: 07c989011fd502a8073e6513970d18a3701703cfe53a4b366352b918886e676d54770a952f4b7cba024b2a0ff3bf514429a5d30b0943a5c78d1c3f12ff95ae78
6
+ metadata.gz: 6ee21db904abbf80f6eb34edb3d9da0ffc19e4f7bb47e5ff846c137b874b7286857b63fae99913aaac388830d411e317ad54daf64aecf66c4f2de7823661b469
7
+ data.tar.gz: 1c0785b5c633dc95f3c32aa4af42bd42a9f53885a2b22c0473b661c58bf8d44bfb14783dab92027c61118405c58f95b7d5ec65c5bae9b43f232e99213efff977
data/.gitignore CHANGED
@@ -6,7 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
12
- Gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  # Disable all metrics.
2
2
  Metrics:
3
3
  Enabled: false
4
+ Style/Documentation:
5
+ Enabled: false
data/.travis.yml CHANGED
@@ -2,4 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
+ - 2.4.4
6
+ - 2.3.7
5
7
  before_install: gem install bundler -v 1.16.1
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # QnAMaker
2
2
 
3
- API wrapper for [QnA Maker](https://qnamaker.ai)
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
- # => #<QnAMaker::Client @knowledgebase_id="kb_id", @subscription_key="subscription_key", ...>
31
+ #=> #<QnAMaker::Client @knowledgebase_id="kb_id", @subscription_key="subscription_key", ...>
28
32
 
29
33
  answers = client.generate_answer('hi')
30
- # => [#<QnAMaker::Answer @answer="hello", @questions=["hi"], @score=100.0>]
34
+ #=> [#<QnAMaker::Answer @answer="hello", @questions=["hi"], @score=100.0>]
31
35
 
32
- puts answers.first.answer
33
- # => hello
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
- * [ ] Methods
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
- * [ ] **PATCH** - Train Knowledge Base
50
- * [ ] **PATCH** - Update Alterations
51
- * [ ] **PATCH** - Update Knowledge Base
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
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
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, 'Oh no!'
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, 'Oh no!'
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 QuotaExceededError, response.parse['error']['message'].join(' ')
16
+ raise ForbiddenError, response.parse['error']['message']
17
17
  when 404
18
- raise NotFoundError, response.parse['error']['message'].join(' ')
18
+ raise NotFoundError, response.parse['error']['message']
19
19
  when 409
20
- raise ConflictError, response.parse['error']['message'].join(' ')
20
+ raise ConflictError, response.parse['error']['message']
21
21
  else
22
- raise UnknownError, 'Oh no!'
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 QuotaExceededError, response.parse['error']['message'].join(' ')
39
+ raise ForbiddenError, response.parse['error']['message']
40
40
  when 404
41
- raise NotFoundError, response.parse['error']['message'].join(' ')
41
+ raise NotFoundError, response.parse['error']['message']
42
42
  when 409
43
- raise ConflictError, response.parse['error']['message'].join(' ')
43
+ raise ConflictError, response.parse['error']['message']
44
44
  else
45
- raise UnknownError, 'Oh no!'
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 QuotaExceededError, response.parse['error']['message'].join(' ')
21
+ raise ForbiddenError, response.parse['error']['message']
22
22
  when 404
23
- raise NotFoundError, response.parse['error']['message'].join(' ')
23
+ raise NotFoundError, response.parse['error']['message']
24
24
  else
25
- raise UnknownError, 'Oh no!'
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 QuotaExceededError, response.parse['error']['message'].join(' ')
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, 'Oh no!'
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'].join(' ')
23
+ raise QuotaExceededError, response.parse['error']['message']
24
24
  when 404
25
- raise NotFoundError, response.parse['error']['message'].join(' ')
25
+ raise NotFoundError, response.parse['error']['message']
26
26
  when 408
27
- raise OperationTimeOutError, response.parse['error']['message'].join(' ')
27
+ raise OperationTimeOutError, response.parse['error']['message']
28
28
  when 429
29
- raise RateLimitExceededError, response.parse['error']['message'].join(' ')
29
+ raise RateLimitExceededError, response.parse['error']['message']
30
30
  else
31
- raise UnknownError, 'Oh no!'
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 QuotaExceededError, response.parse['error']['message'].join(' ')
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'].join(' ')
20
+ raise ConflictError, response.parse['error']['message']
21
21
  else
22
- raise UnknownError, 'Oh no!'
22
+ raise UnknownError, "Oh no! (#{response.code})"
23
23
  end
24
24
  end
25
25
  end
@@ -1,19 +1,35 @@
1
- # def train_kb(user_question, kb_question, kb_answer)
2
- # response = HTTP.patch(
3
- # full_url(:train_kb),
4
- # json: {
5
- # feedbackRecords: [{
6
- # userId: '1',
7
- # userQuestion: user_question,
8
- # kbQuestion: kb_question,
9
- # kbAnswer: kb_answer
10
- # }]
11
- # }
12
- # )
13
- # case response.code
14
- # when 204
15
- # 'Success!'
16
- # else
17
- # response.code
18
- # end
19
- # end
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
- # def update_kb(add = [], delete = [])
2
- # response = HTTP.patch(
3
- # full_url(:update_kb),
4
- # json: { add: { qnaPairs: add }, delete: { qnaPairs: delete } }
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
- # case response.code
8
- # when 204
9
- # 'Success!'
10
- # else
11
- # response.code
12
- # end
13
- # end
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
@@ -20,6 +20,9 @@ module QnAMaker
20
20
  class ConflictError < StandardError
21
21
  end
22
22
 
23
+ class ForbiddenError < StandardError
24
+ end
25
+
23
26
  class UnknownError < StandardError
24
27
  end
25
28
  end
@@ -1,3 +1,3 @@
1
1
  module QnAMaker
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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
- # require 'qna_maker/endpoints/train_kb'
15
- # require 'qna_maker/endpoints/update_kb'
16
- # require 'qna_maker/endpoints/update_alterations'
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.1.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-09 00:00:00.000000000 Z
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