Giter VIP home page Giter VIP logo

w-ruby's Introduction

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.

w-ruby's People

Contributors

katorres02 avatar

Stargazers

 avatar

Watchers

James Cloos avatar David Valderrama avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.