watson-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75eb37d001cf07bb49a4719cd6ef33760dd51ef7
4
+ data.tar.gz: f23f072ec1f00124c73618f1eabd1a775b53997e
5
+ SHA512:
6
+ metadata.gz: bf10d1598cf074e77b59cb8ee78eaf9f9f42f50917d428ae5be724b336fce03bf6763c37d569c8fdee7203301b04038a1591e29e518c043139bde440e9b974d2
7
+ data.tar.gz: 9402bdc34541986e5070c79b6881a5634582a46f08e1da434fcc9fbcd5cb4a75a743933e88ca4d82dd780282f88c92435b9b4771011990efeb70f708363d9209
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # w-ruby
2
+ API client for watson IPBM services
3
+
4
+ # w-ruby
5
+ API client for watson IPBM services
6
+
7
+ ### Conversation API
8
+ Initialize your own credentials for Conversation API
9
+ ```ruby
10
+ Watson::Conversation.configure(
11
+ password: 'YOUR_CONVERSATION_PASSWORD',
12
+ username: 'YOUR_CONVERSATION_USERNAME',
13
+ url: 'https://gateway.watsonplatform.net/conversation/api',
14
+ workspace_id: 'YOUR_CONVERSATION_WORKSPACE_ID'
15
+ )
16
+ ```
17
+
18
+ **Example:**
19
+ A simple response from your dialog model
20
+ ```ruby
21
+ require 'watson-client'
22
+
23
+ client = Watson::Conversation.new
24
+ client.send_message('message one')
25
+ >> "Watson response one"
26
+ client.send_message('message two')
27
+ >> "Watson response two"
28
+ ```
29
+
30
+ Try something different
31
+ ```ruby
32
+ require 'watson-client'
33
+
34
+ puts 'Say Hi!'
35
+ user_input = nil
36
+ until user_input == 'q' || user_input == 'exit'
37
+ print '> '
38
+ user_input = gets.chomp
39
+ return if user_input == 'q' || user_input == 'exit'
40
+ client.send_message(user_input)
41
+ sleep 0.5
42
+ end
43
+ ```
44
+
45
+ ### Retrieve and Rank API
46
+ Initialize your own credentials for Conversation API
47
+ ```ruby
48
+ Watson::RetrieveAndRank.configure(
49
+ url: 'https://watson-api-explorer.mybluemix.net/retrieve-and-rank/api',
50
+ password: 'YOUR_RETRIEVE_AND_RANK_PASSWORD',
51
+ username: 'YOUR_RETRIEVE_AND_RANK_USERNAME',
52
+ cluster_id: 'YOUR_RETRIEVE_AND_RANK_CLUSTER_ID',
53
+ collection_name: 'YOUR_RETRIEVE_AND_RANK_COLLECTION_NAME'
54
+ )
55
+ ```
56
+ Get the suggested answers
57
+ ```ruby
58
+ responses = Watson::RetrieveAndRank.send_message('message')
59
+ ```
60
+
61
+ The response is returned as a JSON array.
@@ -0,0 +1,13 @@
1
+ module Watson
2
+ class Cluster
3
+ attr_reader :solr_cluster_id, :cluster_name, :cluster_size,
4
+ :solr_cluster_status
5
+
6
+ def initialize(options = {})
7
+ @solr_cluster_id = options['solr_cluster_id']
8
+ @cluster_name = options['cluster_name']
9
+ @cluster_size = options['cluster_size']
10
+ @solr_cluster_status = options['solr_cluster_status']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module Watson
2
+ class Conversation
3
+ def self.configure(options = {})
4
+ @@username = options[:username]
5
+ @@password = options[:password]
6
+ @@url = options[:url]
7
+ @@workspace_id = options[:workspace_id]
8
+ end
9
+
10
+ def conversation
11
+ @context['conversation_id']
12
+ end
13
+
14
+ def send_message(message = '')
15
+ params = { input: { text: message }, alternate_intents: true }
16
+ params.merge!(@context) unless @context.nil?
17
+
18
+ response = Excon.post(url,
19
+ body: params.to_json,
20
+ headers: {
21
+ 'Content-Type' => 'application/json',
22
+ 'Accept' => 'application/json'
23
+ },
24
+ user: @@username,
25
+ password: @@password)
26
+ result = JSON.parse(response.body)
27
+
28
+ @context = { context: result['context'] }
29
+ puts result['output']['text']
30
+ end
31
+
32
+ def url
33
+ @@url + '/v1/workspaces/' + @@workspace_id + '/message?version=2016-09-20'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ module Watson
2
+ class RetrieveAndRank
3
+ def self.configure(options = {})
4
+ @username = options[:username]
5
+ @password = options[:password]
6
+ @url = options[:url]
7
+ @cluster = options[:cluster_id]
8
+ @collection_name = options[:collection_name]
9
+ end
10
+
11
+ def self.send_message(message = '')
12
+ query = URI.encode(message)
13
+ response = Excon.post(url(query),
14
+ headers: {
15
+ 'Content-Type' => 'application/json',
16
+ 'Accept' => 'application/json'
17
+ },
18
+ user: @username,
19
+ password: @password)
20
+ result = JSON.parse(response.body)
21
+ answers(result['response']['docs'])
22
+ end
23
+
24
+ def self.answers(data)
25
+ data.each { |d| puts d['body'] }
26
+ end
27
+
28
+ def self.url(query)
29
+ @url + '/v1/solr_clusters/' + @cluster + '/solr/' + @collection_name +
30
+ '/select?q=' + query + '&wt=json'
31
+ end
32
+ end
33
+ end
data/lib/watson.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'excon'
2
+ require 'json'
3
+ require 'uri'
4
+ require_relative '../lib/watson/conversation'
5
+ require_relative '../lib/watson/retrieve_and_rank'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watson-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Andres Torres Cruz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Send and receive messages to Conversation or Retrieve and Rank services
28
+ email: carlosandrestorres28@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/watson.rb
35
+ - lib/watson/cluster.rb
36
+ - lib/watson/conversation.rb
37
+ - lib/watson/retrieve_and_rank.rb
38
+ homepage: https://github.com/katorres02/w-ruby
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.9.3
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: REST API client for IBM Watson™ services
62
+ test_files: []