Giter Site home page Giter Site logo

wit-ruby's Introduction

wit-ruby

wit-ruby is the Ruby SDK for Wit.ai.

Install

From RubyGems:

gem install wit

From source:

git clone https://github.com/wit-ai/wit-ruby
gem build wit.gemspec
gem install wit-*.gem

Quickstart

Run in your terminal:

ruby examples/basic.rb <your_token>

See the examples folder for more examples.

API

Overview

wit-ruby provides a Wit class with the following methods:

  • message - the Wit message API
  • interactive - starts an interactive conversation with your bot

Wit class

The Wit constructor takes a Hash with the following symbol keys:

  • :access_token - the access token of your Wit instance

A minimal example looks like this:

require 'wit'

client = Wit.new(access_token: access_token)
client.message('set an alarm tomorrow at 7am')

Create new App Using the Access Token

Creates new app using the server token. See POST /apps.

new_app_payload = {name: "new-app-1", lang: "en", private: true}
# set_new_app_token will make the client use the new app's token.
# that flag is set to false by default.
client.create_new_app(new_app_payload, set_new_app_token = true)

Train the app programatically using '/utterances'

Trains and annotates an utterance or more. See POST /utterances.

# you have to create the intent and entity before using any of them.
utterance_payload = {
  text: "I want to fly to china",
  intent: "flight_request",
  entities: [
    {
      "entity": "wit$location:to",
      "start": 17,
      "end": 22,
      "body": "china",
      "entities": []
    }
  ],
  traits: []
}

# utterance payload can be a list of utterances or a single one
client.post_utterances(utterance_payload)

.message()

The Wit message API.

Takes the following parameters:

  • msg - the text you want Wit.ai to extract the information from

Example:

rsp = client.message('what is the weather in London?')
puts("Yay, got Wit.ai response: #{rsp}")

.interactive()

Starts an interactive conversation with your bot.

Example:

client.interactive

CRUD operations for intents

payload in the parameters is a hash containing API arguments.

.get_intents()

Returns a list of available intents for the app. See GET /intents.

.get_intent(intent)

Returns all available information about an intent. See GET /intents/:intent.

.post_intents(payload)

Creates a new intent. See POST /intents.

.delete_intents(intent)

Permanently deletes the intent. See DELETE /intents/:intent.

CRUD operations for entities

payload in the parameters is a hash containing API arguments.

.get_entities()

Returns a list of available entities for the app.
See GET /entities

.post_entities(payload)

Creates a new entity with the given attributes.
See POST /entities

.get_entity(entity)

Returns all the information available for an entity.
See GET /entities/:entity

.put_entities(entity, payload)

Updates an entity with the given attributes.
See PUT /entities/:entity

.delete_entities(entity)

Permanently removes the entity.
See DELETE /entities/:entity

.post_entities_keywords(entity, payload)

Adds a possible value into the list of keywords for the keywords entity. See POST /entities/:entity/keywords

.delete_entities_keywords(entity, keyword)

Deletes a keyword from the entity.
See DELETE /entities/:entity/keywords/:keyword

.post_entities_keywords_synonyms(entity, keyword, payload)

Creates a new synonym for the keyword of the entity.
See POST /entities/:entity/keywords/:keyword/synonyms

delete_entities_keywords_synonyms(entity, keyword, synonym)

Deletes a synonym of the keyword of the entity.
See DELETE /entities/:entity/keywords/:keyword/synonyms/:synonym

CRUD operations for traits

payload in the parameters is a hash containing API arguments.

.get_traits()

Returns a list of available traits for the app. See GET /traits.

.get_trait(trait)

Returns all available information about a trait. See GET /traits/:trait.

.post_traits(payload)

Creates a new trait. See POST /traits.

.post_traits_values(trait, payload)

Adds a new value to an existing trait. See POST /traits/:trait/values.

.delete_traits_values(trait, value)

Permanently deletes a value of an existing trait. See POST /traits/:trait/values.

.delete_traits(trait)

Permanently deletes the trait. See DELETE /traits/:trait.

See the docs for more information.

Logging

Default logging is to STDOUT with INFO level.

You can setup your logging level as follows:

Wit.logger.level = Logger::WARN

See the Logger class docs for more information.

Thanks

Thanks to Justin Workman for releasing a first version in October 2013. We really appreciate!

License

The license for wit-ruby can be found in LICENSE file in the root directory of this source tree.

Terms of Use

Our terms of use can be found at https://opensource.facebook.com/legal/terms.

Privacy Policy

Our privacy policy can be found at https://opensource.facebook.com/legal/privacy.

wit-ruby's People

Contributors

aneilbaboo avatar beneaston avatar bklang avatar blandinw avatar jtliao avatar justincampbell avatar lmangani avatar martinraison avatar oliviervaussy avatar oniken avatar patapizza avatar peakxu avatar socertis avatar stopachka avatar yunussasmaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wit-ruby's Issues

Unhandled Exception for null actions

ruby examples/quickstart.rb TOZOS7QIT6TUQXOK326CU2LPGVZ4VG2K
hello
I, [2016-05-10T13:15:28.446386 #6346] INFO -- : Executing merge
/var/lib/gems/2.1.0/gems/wit-3.3.1/lib/wit.rb:112:in run_actions_': undefined methodto_sym' for nil:NilClass (NoMethodError)
from /var/lib/gems/2.1.0/gems/wit-3.3.1/lib/wit.rb:128:in run_actions_' from /var/lib/gems/2.1.0/gems/wit-3.3.1/lib/wit.rb:133:inrun_actions'
from /var/lib/gems/2.1.0/gems/wit-3.3.1/lib/wit.rb:144:in interactive' from examples/quickstart.rb:37:in

'

atr

GAWAD-W
Do you want to request a feature, report a bug, or ask a question about wit-ruby?

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

If applicable, what is the App ID where you are experiencing this issue? If you do not provide this, we cannot help.

Wrong documentation

WitException: The 'say' action should take 3 arguments: session_id, context, msg.
WitException: The 'error' action should take 3 arguments: session_id, context, error.

actions = {
:say => -> (session_id, msg) {
p msg
},
:merge => -> (session_id, context, entities, msg) {
return context
},
:error => -> (session_id, context) {
p 'Oops I don't know what to do.'
},
}
should be
actions = {
:say => -> (session_id, context, msg) {
p msg
},
:merge => -> (session_id, context, entities, msg) {
return context
},
:error => -> (session_id, context, error) {
p 'Oops I don't know what to do.'
},
}

I do not have access to the online Wit.ai API from my localhost

I am trying to develop a chatbot using wit.ai to mount it on my website, but from my localhost I do not have access to the online API ... I use Ruby on Rails and when I try the basic example of the repository Git the answer is' SocketError: Failed to open TCP connection to api.wit.ai:443 (getaddrinfo: Temporary failure in name resolution) ', use the' savon 'gem to verify if it had connection and it works for me, I do not know why wit does not do it. This is the example:

require 'wit'
def call
    client = Wit.new(access_token: 'Y3Q......')
    rsp = client.message('cuestion???')
    puts("Yay, got Wit.ai response: #{rsp}")
  end

Then in my console:

$ rails c
Running via Spring preloader in process 5322
Loading development environment (Rails 5.1.5)
2.3.1 :001 > obj = MessageController.new
 => #<MessageController:0x00000003624280 @_action_has_layout=true, @_routes=nil, @_request=nil, @_response=nil> 
2.3.1 :002 > obj.call
SocketError: Failed to open TCP connection to api.wit.ai:443 (getaddrinfo: Temporary failure in name resolution)
        from app/controllers/message_controller.rb:9:in `call'
        from (irb):2
2.3.1 :003 > 

Context not returned for run_actions

When I use this example from the Readme:

actions = {
  :say => -> (session_id, context, msg) {
    p msg
  },
  :merge => -> (session_id, context, entities, msg) {
    return context
  },
  :error => -> (session_id, context, error) {
    p 'Oops I don\'t know what to do.'
  },
}

client = Wit.new access_token, actions
session = 'my-user-session-42'
context0 = ""
context1 = client.run_actions(session, 'what is the weather in London?', context0)
p "The session state is now: #{context1}"

Then the output is "The session state is now: "

It seems like the input context is always returned, not the output-context.

یاقوت سرخ/ بذله گویی

Do you want to request a feature, report a bug, or ask a question about wit-ruby?

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

If applicable, what is the App ID where you are experiencing this issue? If you do not provide this, we cannot help.

adding timeout in options

Hi @blandinw
I just added the timout option in the constructor so that users can take care of the cases that an API response is delayed.
Please review the #23

224

,

حذف ,
حذف ریلیم ,
قوانین ,
توضیحات ,
تنظیم نام ,
تنظیم عکس ,
ترفیع ,
تنزل ,
راهنما ,
پاک کردن ,
kill chat ,
kill realm ,
تنزل ,
تنزل ,
تنظیم ,
قفل ,
دارنده ,
دارنده ,
صاحب ,
آیدی ,
صاحب ,
باز کردن ,
تنظیم حساسیت ,
تنظیمات ,
لیست مدیران ,
لینک جدید ,
لینک ,
لینک خصوصی ,
حذف غیرفعالین ,
حذف غیرفعالین ,

Changing the log level throws error

Changing the log level throws the error:

Wit.logger.level = Logger::WARN
=> undefined method `logger' for Wit:Class

Also, a different error when setting the log level in the instance

Wit.new(logger: Logger::WARN, ...
=> undefined method `debug' for 2:Fixnum

Converse api type response is always value

Hello guys,
Let's say I have this story:
Users says: Bye
Bot says: Have a good one!
Bots says: ByeBye

it work in the wit testing dashboard.
Now when I'm trying to get that by converse method repeatedly till I get the type stop, but the type is always "value"
client.converse("session_id", "Bye") returns
{"confidence"=>0.0010324002873500187, "type"=>"msg", "msg"=>"Have a good one!", "entities"=>{"goodbye"=>[{"confidence"=>0.9514085768812446, "type"=>"value", "value"=>"Bye"}]}}
and then I do it again it returns:
{"confidence"=>0.0008932824968469721, "type"=>"msg", "msg"=>"ByeBye", "entities"=>{"goodbye"=>[{"confidence"=>0.9514085768812446, "type"=>"value", "value"=>"Bye"}]}}

I tried passing the session as an empty hash for the first call and then fill it in with entities for the second time but nothing changes.

Pls help

Thanks

GitHubBot

Do you want to request a feature, report a bug, or ask a question about wit-ruby?

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

If applicable, what is the App ID where you are experiencing this issue? If you do not provide this, we cannot help.

Slight confusion with converse and mixed responses

When I:

rsp = client.message('I need to add two numbers')

I get a response by asking the user a question, then I send to wit the reply:

rsp = client.converse('<what-is this...really?', 'two and two', {})

Two things happened here:

If the user replies within few seconds, my rsp will have "type" => "msg",, if the user takes long to reply, say 1min, my rsp will be "type" => "action",. I'm lost. Why not include a session id with all message responses? Am I conversing properly? I'm lost with that "unique_session_id". Is that some random string generated by the my server? If so, why?

Maybe bug?

basic.rb:19:in `block in <main>': undefined method `first_entity_value' for main:Object (NoMethodError)

I used the example, absolutely same

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.