RecastAI 1.1.0 → 1.1.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 +4 -4
- data/README.md +165 -126
- data/lib/recastai.rb +0 -2
- data/lib/recastai/utils.rb +1 -1
- data/misc/recast-ai-tokens.png +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8ad1ab3c3644a475ee1ef6cb9d2fc1ff9cc2576
|
4
|
+
data.tar.gz: b8aa64148bc4fa52e834baa5f7e0a1519f198459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fbb4fba5c6df33976ba39903ec228e33c152e333879ef17a9b72e646d4d85bfaf543b3de1b4842c01fd03390e15cff0734a5eb565eeef676b9d6061ff67ae1a
|
7
|
+
data.tar.gz: 86ef258e86abcebf37bc945d3cc3cf58a634416e3eab53e12bc68ce1b5919b6f1eaa9e706a51337ed35a37e94f8f4e941142509e0664a904f8b5430869ebece3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Recast.AI - Ruby SDK
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/RecastAI)
|
4
4
|
|
@@ -19,63 +19,26 @@ This gem is a pure Ruby interface to the [Recast.AI](https://recast.ai) API. It
|
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
22
|
-
### Via Gemfile
|
23
|
-
|
24
|
-
From [rubygems.org](https://rubygems.org/):
|
25
|
-
|
26
|
-
```bash
|
27
|
-
gem 'RecastAI'
|
28
|
-
```
|
29
|
-
|
30
|
-
From [github.com](https://github.com/):
|
31
|
-
|
32
|
-
```bash
|
33
|
-
gem 'RecastAI', github: 'RecastAI/SDK-ruby'
|
34
|
-
```
|
35
|
-
|
36
|
-
### Via Terminal
|
37
|
-
|
38
|
-
From [rubygems.org](https://rubygems.org/):
|
39
|
-
|
40
22
|
```bash
|
41
23
|
gem install 'RecastAI'
|
42
24
|
```
|
43
25
|
|
44
|
-
From [github.com](https://github.com/):
|
45
|
-
|
46
|
-
```bash
|
47
|
-
git clone https://github.com/RecastAI/SDK-ruby
|
48
|
-
gem build recastai.gemspec
|
49
|
-
gem install RecastAI-*.gem
|
50
|
-
```
|
51
|
-
|
52
|
-
|
53
26
|
## Usage
|
54
27
|
|
55
|
-
### Gem
|
56
|
-
|
57
28
|
```ruby
|
58
29
|
require 'recastai'
|
59
30
|
|
60
31
|
client = RecastAI::Client.new(YOUR_TOKEN, YOUR_LANGUAGE)
|
61
|
-
response = client.text_request(YOUR_TEXT)
|
62
|
-
#response = client.file_request(File.new(File.join(File.dirname(__FILE__), YOUR_FILE)))
|
63
32
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
```
|
68
|
-
|
69
|
-
### CLI
|
33
|
+
# text request
|
34
|
+
responseFromText = client.text_request(YOUR_TEXT)
|
70
35
|
|
71
|
-
|
72
|
-
|
73
|
-
# => Recast.AI's response
|
74
|
-
```
|
36
|
+
# file request
|
37
|
+
responseFromFile = client.file_request(File.new(File.join(File.dirname(__FILE__), YOUR_FILE)))
|
75
38
|
|
76
|
-
|
77
|
-
|
78
|
-
|
39
|
+
if responseFromText.intent == YOUR_EXPECTED_INTENT
|
40
|
+
# Do your code...
|
41
|
+
end
|
79
42
|
```
|
80
43
|
|
81
44
|
## Specs
|
@@ -92,139 +55,215 @@ This gem contains 5 main classes, as follows:
|
|
92
55
|
|
93
56
|
Don't hesitate to dive into the code, it's commented ;)
|
94
57
|
|
95
|
-
|
58
|
+
## RecastAI::Client
|
96
59
|
|
97
|
-
The
|
60
|
+
The Client can be instanciated with a token and a language (both optional)
|
98
61
|
|
99
|
-
|
100
|
-
|
62
|
+
```ruby
|
63
|
+
client = RecastAI::Client.new(YOUR_TOKEN, YOUR_LANGUAGE)
|
64
|
+
```
|
101
65
|
|
102
|
-
|
66
|
+
__Your tokens__
|
103
67
|
|
104
|
-
|
68
|
+
[token]: https://github.com/RecastAI/SDK-NodeJs/blob/master/misc/recast-ai-tokens.png "Tokens"
|
105
69
|
|
106
|
-
|
107
|
-
* voice_request: your bot's primary language is used for processing as we do not provide language detection for speech.
|
70
|
+
![alt text][token]
|
108
71
|
|
109
|
-
|
72
|
+
*Copy paste your request access token from your bot's settings*
|
110
73
|
|
111
|
-
|
112
|
-
* voice_request: the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used
|
74
|
+
__Your language__
|
113
75
|
|
114
|
-
|
76
|
+
```ruby
|
77
|
+
client = RecastAI::Client.new(YOUR_TOKEN, 'en')
|
78
|
+
```
|
79
|
+
|
80
|
+
*The language is a lowercase 639-1 isocode.*
|
81
|
+
|
82
|
+
## Text Request
|
83
|
+
|
84
|
+
text_request(text, options = {})
|
85
|
+
|
86
|
+
If you pass a token or a language in the options parameter, it will override your default client language or token
|
115
87
|
|
116
88
|
```ruby
|
117
|
-
|
89
|
+
response = client.text_request(YOUR_TEXT)
|
118
90
|
|
119
|
-
|
91
|
+
if response.intent == YOUR_EXPECTED_INTENT
|
92
|
+
# Do your code...
|
93
|
+
end
|
94
|
+
```
|
120
95
|
|
121
|
-
|
96
|
+
```ruby
|
97
|
+
# With optional parameters
|
122
98
|
response = client.text_request(YOUR_TEXT, { token: YOUR_TOKEN, language: YOUR_LANGUAGE })
|
99
|
+
```
|
100
|
+
|
101
|
+
__If a language is provided:__ the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used.
|
102
|
+
|
103
|
+
__If no language is provided:__ the language of the text is detected and is used for processing if your bot has expressions for it, else your bot's primary language is used for processing.
|
104
|
+
|
105
|
+
## File request
|
106
|
+
|
107
|
+
file_request(file, options = {})
|
108
|
+
|
109
|
+
If you pass a token or a language in the option parameter, it will override your default client language or token.
|
110
|
+
|
111
|
+
__file format: .wav__
|
112
|
+
```ruby
|
113
|
+
response = client.file_request(File.new(File.join(File.dirname(__FILE__),YOUR_FILE)))
|
123
114
|
|
124
115
|
if response.intent == YOUR_EXPECTED_INTENT
|
125
116
|
# Do your code...
|
126
117
|
end
|
118
|
+
```
|
127
119
|
|
128
|
-
|
120
|
+
```ruby
|
121
|
+
# with optional parameters
|
129
122
|
response = client.file_request(File.new(File.join(File.dirname(__FILE__),YOUR_FILE)), { token: YOUR_TOKEN, language: YOUR_LANGUAGE })
|
123
|
+
```
|
124
|
+
|
125
|
+
__If a language is provided:__ the language you've given is used for processing if your bot has expressions for it, else your bot's primary language is used
|
126
|
+
|
127
|
+
__If no language is provided:__ your bot's primary language is used for processing as we do not provide language detection for speech.
|
128
|
+
|
129
|
+
|
130
|
+
## RecastAI::Response
|
131
|
+
|
132
|
+
The Response is generated after a call to either file_request or text_request.
|
133
|
+
|
134
|
+
### Get the first detected intent
|
135
|
+
|
136
|
+
| Method | Params | Return |
|
137
|
+
| ------------- |:------:| :-------------------------|
|
138
|
+
| intent() | | the first detected intent |
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
response = client.text_request(YOUR_TEXT)
|
130
142
|
|
131
143
|
if response.intent == YOUR_EXPECTED_INTENT
|
132
144
|
# Do your code...
|
133
145
|
end
|
134
146
|
```
|
135
147
|
|
136
|
-
###
|
137
|
-
|
138
|
-
The Recast.AI Response is generated after a call with the two previous methods and contains the following methods:
|
148
|
+
### Get the first sentence
|
139
149
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
* intent(\*) *Returns the first matched intent*
|
144
|
-
* sentences(\*) *Returns all the detected sentences*
|
145
|
-
* sentence(\*) *Returns the first detected sentence*
|
146
|
-
* get(name) *Returns the first entity matching -name-*
|
147
|
-
* all(name) *Returns all the entities matching -name-*
|
148
|
-
* entities(\*) *Returns all the entities*
|
149
|
-
* version(\*) *Returns the version of the JSON*
|
150
|
-
* timestamp(\*) *Returns the timestamp at the end of the processing*
|
151
|
-
* status(\*) *Returns the status of the response*
|
150
|
+
| Method | Params | Return |
|
151
|
+
| --------------- |:------:| :------------------|
|
152
|
+
| sentence() | | the first sentence |
|
152
153
|
|
153
154
|
```ruby
|
154
|
-
response = client.text_request(
|
155
|
+
response = client.text_request(YOUR_TEXT)
|
155
156
|
|
156
|
-
# Get the first sentence, aka 'Give me some recipes with potatoes'
|
157
157
|
first_sentence = response.sentence
|
158
|
+
```
|
158
159
|
|
159
|
-
|
160
|
-
if response.intent == 'recipe'
|
161
|
-
# ...get all the entities matching 'ingredient'
|
162
|
-
ingredients = response.all('ingredient')
|
160
|
+
### Get the first entity matching name
|
163
161
|
|
164
|
-
|
165
|
-
|
162
|
+
| Method | Params | Return |
|
163
|
+
| ---------- |:-------------:| :------------------------|
|
164
|
+
| get(name) | name: String | the first Entity matched |
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
response = client.text_request(YOUR_TEXT)
|
168
|
+
|
169
|
+
location = response.get('location')
|
166
170
|
```
|
167
171
|
|
168
|
-
###
|
172
|
+
### Get all entities matching name
|
173
|
+
|
174
|
+
| Method | Params | Return |
|
175
|
+
| ---------- |:-------------:| :------------------------|
|
176
|
+
| all(name) | name: String | all the Entities matched |
|
169
177
|
|
170
|
-
|
178
|
+
```ruby
|
179
|
+
response = client.text_request(YOUR_TEXT)
|
171
180
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
181
|
+
locations = response.all('location')
|
182
|
+
```
|
183
|
+
|
184
|
+
### Getters
|
185
|
+
|
186
|
+
Each of the following methods corresponds to a Response attribute
|
187
|
+
|
188
|
+
| Method | Params | Return |
|
189
|
+
| ------------- |:------:| :---------------------------------------------------|
|
190
|
+
| raw() | | String: the raw unparsed json response |
|
191
|
+
| source() | | String: the user input |
|
192
|
+
| intents() | | Array[object]: all the matched intents |
|
193
|
+
| sentences() | | Array[Sentence]: all the detected sentences |
|
194
|
+
| version() | | String: the version of the json |
|
195
|
+
| timestamp() | | String: the timestamp at the end of the processing |
|
196
|
+
| status() | | String: the status of the response |
|
197
|
+
| type() | | String: the type of the response |
|
198
|
+
|
199
|
+
|
200
|
+
## RecastAI::Sentence
|
201
|
+
|
202
|
+
The Sentence is generated by the Recast.AI Response initializer
|
203
|
+
|
204
|
+
### Get the first entity matching name
|
205
|
+
|
206
|
+
| Method | Params | Return |
|
207
|
+
| ---------- |:-------------:| :------------------------|
|
208
|
+
| get(name) | name: String | the first Entity matched |
|
180
209
|
|
181
210
|
```ruby
|
182
|
-
response = client.text_request(
|
183
|
-
|
211
|
+
response = client.text_request(YOUR_TEXT)
|
212
|
+
|
184
213
|
sentence = response.sentence
|
185
214
|
|
186
|
-
|
187
|
-
# Tell a joke...
|
188
|
-
end
|
215
|
+
location = sentence.get('location')
|
189
216
|
```
|
190
217
|
|
191
|
-
###
|
218
|
+
### Get all entities matching name
|
192
219
|
|
193
|
-
|
220
|
+
| Method | Params | Return |
|
221
|
+
| ---------- |:-------------:| :------------------------|
|
222
|
+
| all(name) | name: String | all the Entities matched |
|
194
223
|
|
195
|
-
|
196
|
-
|
224
|
+
```ruby
|
225
|
+
response = client.text_request(YOUR_TEXT)
|
197
226
|
|
198
|
-
|
227
|
+
sentence = response.sentence
|
199
228
|
|
200
|
-
|
201
|
-
|
202
|
-
* deg(\*)
|
203
|
-
* formated(\*)
|
204
|
-
* lng(\*)
|
205
|
-
* lat(\*)
|
206
|
-
* unit(\*)
|
207
|
-
* code(\*)
|
208
|
-
* person(\*)
|
209
|
-
* number(\*)
|
210
|
-
* gender(\*)
|
211
|
-
* next(\*)
|
212
|
-
* grain(\*)
|
213
|
-
* order(\*)
|
229
|
+
locations = sentence.all('location')
|
230
|
+
```
|
214
231
|
|
215
|
-
|
216
|
-
response = client.text_request('What can I cook with salmon ?')
|
232
|
+
### Getters
|
217
233
|
|
218
|
-
|
219
|
-
# Get the ingredient
|
220
|
-
ingredient = response.get('ingredient')
|
234
|
+
Each of the following methods corresponds to a Response attribute
|
221
235
|
|
222
|
-
|
223
|
-
|
236
|
+
| Method | Params | Return |
|
237
|
+
| ----------- |:------:| :----------------------------------------------------|
|
238
|
+
| source | | String: the source of the sentence |
|
239
|
+
| type | | String: the type of the sentence |
|
240
|
+
| action | | String: The action of the sentence |
|
241
|
+
| agent | | String: the agent of the sentence |
|
242
|
+
| polarity | | String: the polarity of the sentence |
|
243
|
+
| entities | | Array[Entity]: the entities detected in the sentence |
|
244
|
+
|
245
|
+
## RecastAI::Entity
|
246
|
+
|
247
|
+
Each of the following methods corresponds to a Response attribute
|
248
|
+
|
249
|
+
| Attributes | Description |
|
250
|
+
| ----------- |:--------------------------------------------------------------|
|
251
|
+
| name | String: the name of the entity |
|
252
|
+
| raw | String: the unparsed json value of the entity |
|
253
|
+
|
254
|
+
In addition to those methods, more attributes are generated depending of the nature of the entity.
|
255
|
+
The full list can be found there: [man.recast.ai](https://man.recast.ai/#list-of-entities)
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
response = client.text_request(YOUR_TEXT)
|
259
|
+
|
260
|
+
location = response.get('location')
|
224
261
|
|
262
|
+
puts location.raw
|
263
|
+
puts location.name
|
225
264
|
```
|
226
265
|
|
227
|
-
|
266
|
+
## RecastAI::RecastError
|
228
267
|
|
229
268
|
The Recast.AI Error is thrown when receiving an non-200 response from Recast.AI.
|
230
269
|
|
data/lib/recastai.rb
CHANGED
data/lib/recastai/utils.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RecastAI
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Renvoisé
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/recastai/utils.rb
|
122
122
|
- misc/.gitkeep
|
123
123
|
- misc/logo-inline.png
|
124
|
+
- misc/recast-ai-tokens.png
|
124
125
|
- recastai.gemspec
|
125
126
|
homepage: https://github.com/RecastAI/SDK-ruby
|
126
127
|
licenses:
|