0.0
No commit activity in last 3 years
No release in over 3 years
REST API client for IBM Watson™ services. Conversation, Retrieve & Rank, Conversation enhanced services are available
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.55.0

Runtime

~> 0.55.0
 Project Readme

Watson-client

API client for watson IPBM services

Installation

Add this line to your application's Gemfile:

gem 'watson-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install watson-client

Usage

Conversation API

Initialize your own credentials for Conversation API

Watson::Conversation.configure(
  password: 'YOUR_CONVERSATION_PASSWORD',
  username: 'YOUR_CONVERSATION_USERNAME',
  url:      'https://gateway.watsonplatform.net/conversation/api',
  workspace_id: 'YOUR_CONVERSATION_WORKSPACE_ID'
)

Example: A simple response from your dialog model

require 'watson'

client = Watson::Conversation.new
client.send_message('message one')
  >> "Watson response one"
client.send_message('message two')
  >> "Watson response two"

Try something different

require 'watson'

puts 'Say Hi!'
user_input = nil
until user_input == 'q' || user_input == 'exit'
  print '> '
  user_input = gets.chomp
  return if user_input == 'q' || user_input == 'exit'
  r = client.send_message(user_input)
  puts r
  sleep 0.5
end

Retrieve and Rank API

Initialize your own credentials for Conversation API

Watson::RetrieveAndRank.configure(
  url:      'https://watson-api-explorer.mybluemix.net/retrieve-and-rank/api',
  password: 'YOUR_RETRIEVE_AND_RANK_PASSWORD',
  username: 'YOUR_RETRIEVE_AND_RANK_USERNAME',
  cluster_id: 'YOUR_RETRIEVE_AND_RANK_CLUSTER_ID',
  collection_name: 'YOUR_RETRIEVE_AND_RANK_COLLECTION_NAME'
)

Get the suggested answers

responses = Watson::RetrieveAndRank.send_message('message')

The response is returned as a JSON array.

Conversation Enhanced

Combination of Conversation API and Retrieve & Rank API. In order to get this class working you need to set both both configurations variables. If the Conversation class detects an unknown message, we call RetrieveAndRank with the intent name of that unknown message, so we need to set that intent name in the constructor of ConversationEnhanced class.

client = Watson::ConversationEnhanced.new('INTENT_NAME')
user_input = nil
until user_input == 'q' || user_input == 'exit'
  print '> '
  user_input = gets.chomp
  return if user_input == 'q' || user_input == 'exit'
  r = client.send_message(user_input)
  puts r
  sleep 0.5
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/katorres02/w-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.