# wit-ruby
`wit-ruby` is the Ruby SDK for [Wit.ai](http://wit.ai).
## Install
From RubyGems:
```bash
gem install wit
```
From source:
```bash
git clone https://github.com/wit-ai/wit-ruby
gem build wit.gemspec
gem install wit-*.gem
```
## Quickstart
Run in your terminal:
```bash
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](https://wit.ai/docs/http/20200513#get-intent-via-text-link)
* `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:
```ruby
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](https://wit.ai/docs/http/20200513#post__apps_link).
```ruby
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](https://wit.ai/docs/http/20200513#post__utterances_link).
```ruby
# 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](https://wit.ai/docs/http/20200513#get-intent-via-text-link).
Takes the following parameters:
* `msg` - the text you want Wit.ai to extract the information from
Example:
```ruby
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:
```ruby
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](https://wit.ai/docs/http/20200513#get__intents_link).
#### .get_intent(intent)
Returns all available information about an intent.
See [GET /intents/:intent](https://wit.ai/docs/http/20200513#get__intents__intent_link).
#### .post_intents(payload)
Creates a new intent.
See [POST /intents](https://wit.ai/docs/http/20200513#post__intents_link).
#### .delete_intents(intent)
Permanently deletes the intent.
See [DELETE /intents/:intent](https://wit.ai/docs/http/20200513#delete__intents__intent_link).
### 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](https://wit.ai/docs/http/20200513#get--entities-link)
#### .post_entities(payload)
Creates a new entity with the given attributes.
See [POST /entities](https://wit.ai/docs/http/20200513#post--entities-link)
#### .get_entity(entity)
Returns all the information available for an entity.
See [GET /entities/:entity](https://wit.ai/docs/http/20200513#get--entities-:entity-link)
#### .put_entities(entity, payload)
Updates an entity with the given attributes.
See [PUT /entities/:entity](https://wit.ai/docs/http/20200513#put--entities-:entity-link)
#### .delete_entities(entity)
Permanently removes the entity.
See [DELETE /entities/:entity](https://wit.ai/docs/http/20200513#delete--entities-:entity-link)
#### .post_entities_keywords(entity, payload)
Adds a possible value into the list of keywords for the keywords entity.
See [POST /entities/:entity/keywords](https://wit.ai/docs/http/20160526#post--entities-:entity-id-values-link)
#### .delete_entities_keywords(entity, keyword)
Deletes a keyword from the entity.
See [DELETE /entities/:entity/keywords/:keyword](https://wit.ai/docs/http/20200513#delete--entities-:entity-keywords-link)
#### .post_entities_keywords_synonyms(entity, keyword, payload)
Creates a new synonym for the keyword of the entity.
See [POST /entities/:entity/keywords/:keyword/synonyms](https://wit.ai/docs/http/20200513#post--entities-:entity-keywords-:keyword-synonyms-link)
#### delete_entities_keywords_synonyms(entity, keyword, synonym)
Deletes a synonym of the keyword of the entity.
See [DELETE /entities/:entity/keywords/:keyword/synonyms/:synonym](https://wit.ai/docs/http/20200513#delete--entities-:entity-keywords-:keyword-synonyms-link)
### 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](https://wit.ai/docs/http/20200513#get__traits_link).
#### .get_trait(trait)
Returns all available information about a trait.
See [GET /traits/:trait](https://wit.ai/docs/http/20200513#get__traits__trait_link).
#### .post_traits(payload)
Creates a new trait.
See [POST /traits](https://wit.ai/docs/http/20200513#post__traits_link).
#### .post_traits_values(trait, payload)
Adds a new value to an existing trait.
See [POST /traits/:trait/values](https://wit.ai/docs/http/20200513#post__traits__trait_values_link).
#### .delete_traits_values(trait, value)
Permanently deletes a value of an existing trait.
See [POST /traits/:trait/values](https://wit.ai/docs/http/20200513#delete__traits__trait_values_link).
#### .delete_traits(trait)
Permanently deletes the trait.
See [DELETE /traits/:trait](https://wit.ai/docs/http/20200513#delete__traits__trait_link).
See the [docs](https://wit.ai/docs) for more information.
### Logging
Default logging is to `STDOUT` with `INFO` level.
You can setup your logging level as follows:
```ruby
Wit.logger.level = Logger::WARN
```
See the [Logger class](http://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html) docs for more information.
## Thanks
Thanks to [Justin Workman](http://github.com/xtagon) 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 库_Ruby_代码_下载
共15个文件
md:5个
rb:4个
zip:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 115 浏览量
2022-07-02
21:54:11
上传
评论
收藏 15KB ZIP 举报
温馨提示
机智红宝石 wit-ruby是Wit.ai的 Ruby SDK 。
资源推荐
资源详情
资源评论
收起资源包目录
wit-ruby-main.zip (15个子文件)
wit-ruby-main
wit.gemspec 476B
.github
ISSUE_TEMPLATE.md 409B
LICENSE 1KB
CONTRIBUTING.md 1KB
Gemfile 8B
CHANGES.md 3KB
examples
basic.rb 263B
wit-example-celebrities.zip 1KB
wit-example-joke-bot.zip 2KB
celebrities.rb 2KB
joke.rb 1KB
.gitignore 38B
lib
wit.rb 7KB
CODE_OF_CONDUCT.md 3KB
README.md 7KB
共 15 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功