aleph-alpha-ruby 0.0.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 +7 -0
- data/.editorconfig +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +26 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +291 -0
- data/Rakefile +6 -0
- data/lib/aleph-alpha/client.rb +67 -0
- data/lib/aleph-alpha/http.rb +56 -0
- data/lib/aleph-alpha/models.rb +11 -0
- data/lib/aleph-alpha/tokens.rb +19 -0
- data/lib/aleph-alpha/users.rb +19 -0
- data/lib/aleph-alpha/version.rb +3 -0
- data/lib/aleph-alpha.rb +46 -0
- metadata +78 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e249112ecb4fc8fd2f5e03c38011c806b663bbc73cf057205976a71ba7962cd3
|
|
4
|
+
data.tar.gz: e929f9628d68a6dc53d63dc25cd0ba7b193a48adb1fe398e7425b77b11540f1e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 02a9ddf75c2b9f79fe44d161af033b1d24111201a6e186f8e42540ace2442556301fd0a2e43f25911473f585dc1c3a484fd20ca351f158eb619711a007b8c3a9
|
|
7
|
+
data.tar.gz: c8e4161f1b032561b2e3c1a650e672d66d3aacab0315764288c8d95e4ee4ba0b6f0f4e21652db48285b024349e60d2211eb2ed8578f71eba1fc89cef01c628eb
|
data/.editorconfig
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.7
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Style/Documentation:
|
|
7
|
+
# Skips checking to make sure top level modules / classes have a comment.
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
Layout/LineLength:
|
|
11
|
+
Max: 100
|
|
12
|
+
Exclude:
|
|
13
|
+
- "**/*.gemspec"
|
|
14
|
+
|
|
15
|
+
Metrics/AbcSize:
|
|
16
|
+
Max: 20
|
|
17
|
+
|
|
18
|
+
Metrics/BlockLength:
|
|
19
|
+
Exclude:
|
|
20
|
+
- "spec/**/*"
|
|
21
|
+
|
|
22
|
+
Style/StringLiterals:
|
|
23
|
+
EnforcedStyle: double_quotes
|
|
24
|
+
|
|
25
|
+
Style/FrozenStringLiteralComment:
|
|
26
|
+
Enabled: false
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.7.6
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.0.1] - 2023-05-21
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initialise repository
|
|
13
|
+
- Add tests and cached responses
|
data/Gemfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem"s dependencies in aleph-alpha-ruby.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
gem "dotenv", "~> 2.8.1"
|
|
7
|
+
gem "rake", "~> 13.0"
|
|
8
|
+
gem "rspec", "~> 3.12"
|
|
9
|
+
gem "rubocop", "~> 1.51"
|
|
10
|
+
gem "vcr", "~> 6.1.0"
|
|
11
|
+
gem "webmock", "~> 3.18.1"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
aleph-alpha-ruby (0.0.1)
|
|
5
|
+
faraday (>= 1)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.8.4)
|
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
|
12
|
+
ast (2.4.2)
|
|
13
|
+
crack (0.4.5)
|
|
14
|
+
rexml
|
|
15
|
+
diff-lcs (1.5.0)
|
|
16
|
+
dotenv (2.8.1)
|
|
17
|
+
faraday (2.7.4)
|
|
18
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
19
|
+
ruby2_keywords (>= 0.0.4)
|
|
20
|
+
faraday-net_http (3.0.2)
|
|
21
|
+
hashdiff (1.0.1)
|
|
22
|
+
json (2.6.3)
|
|
23
|
+
parallel (1.23.0)
|
|
24
|
+
parser (3.2.2.1)
|
|
25
|
+
ast (~> 2.4.1)
|
|
26
|
+
public_suffix (5.0.1)
|
|
27
|
+
rainbow (3.1.1)
|
|
28
|
+
rake (13.0.6)
|
|
29
|
+
regexp_parser (2.8.0)
|
|
30
|
+
rexml (3.2.5)
|
|
31
|
+
rspec (3.12.0)
|
|
32
|
+
rspec-core (~> 3.12.0)
|
|
33
|
+
rspec-expectations (~> 3.12.0)
|
|
34
|
+
rspec-mocks (~> 3.12.0)
|
|
35
|
+
rspec-core (3.12.2)
|
|
36
|
+
rspec-support (~> 3.12.0)
|
|
37
|
+
rspec-expectations (3.12.3)
|
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
39
|
+
rspec-support (~> 3.12.0)
|
|
40
|
+
rspec-mocks (3.12.5)
|
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
|
+
rspec-support (~> 3.12.0)
|
|
43
|
+
rspec-support (3.12.0)
|
|
44
|
+
rubocop (1.51.0)
|
|
45
|
+
json (~> 2.3)
|
|
46
|
+
parallel (~> 1.10)
|
|
47
|
+
parser (>= 3.2.0.0)
|
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
50
|
+
rexml (>= 3.2.5, < 4.0)
|
|
51
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
52
|
+
ruby-progressbar (~> 1.7)
|
|
53
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
54
|
+
rubocop-ast (1.28.1)
|
|
55
|
+
parser (>= 3.2.1.0)
|
|
56
|
+
ruby-progressbar (1.13.0)
|
|
57
|
+
ruby2_keywords (0.0.5)
|
|
58
|
+
unicode-display_width (2.4.2)
|
|
59
|
+
vcr (6.1.0)
|
|
60
|
+
webmock (3.18.1)
|
|
61
|
+
addressable (>= 2.8.0)
|
|
62
|
+
crack (>= 0.3.2)
|
|
63
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
64
|
+
|
|
65
|
+
PLATFORMS
|
|
66
|
+
ruby
|
|
67
|
+
|
|
68
|
+
DEPENDENCIES
|
|
69
|
+
aleph-alpha-ruby!
|
|
70
|
+
dotenv (~> 2.8.1)
|
|
71
|
+
rake (~> 13.0)
|
|
72
|
+
rspec (~> 3.12)
|
|
73
|
+
rubocop (~> 1.51)
|
|
74
|
+
vcr (~> 6.1.0)
|
|
75
|
+
webmock (~> 3.18.1)
|
|
76
|
+
|
|
77
|
+
BUNDLED WITH
|
|
78
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Sascha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# Aleph Alpha Ruby Client
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://i.imgur.com/FSM2NNV.png" width="50%" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
### Bundler
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem "aleph-alpha-ruby"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
### Gem install
|
|
20
|
+
|
|
21
|
+
Or install with:
|
|
22
|
+
|
|
23
|
+
$ gem install aleph-alpha-ruby
|
|
24
|
+
|
|
25
|
+
and require with:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require "aleph-alpha"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
- Get your API token from [https://app.aleph-alpha.com/profile](https://app.aleph-alpha.com/profile)
|
|
34
|
+
|
|
35
|
+
### Quickstart
|
|
36
|
+
|
|
37
|
+
For a quick test you can pass your token directly to a new client:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
client = AlephAlpha::Client.new(access_token: "access_token_goes_here")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With Config
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
AlephAlpha.configure do |config|
|
|
47
|
+
config.access_token = ENV.fetch("ALEPH_ALPHA_ACCESS_TOKEN")
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Then you can create a client like this:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
client = AlephAlpha::Client.new
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Custom timeout or base URI
|
|
58
|
+
|
|
59
|
+
The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client. You can also change the base URI used for all requests.
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
client = AlephAlpha::Client.new(
|
|
63
|
+
access_token: "access_token_goes_here",
|
|
64
|
+
uri_base: "https://other-api-endpoint.aleph-alpha.com",
|
|
65
|
+
request_timeout: 240
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
or when configuring the gem:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
AlephAlpha.configure do |config|
|
|
73
|
+
config.access_token = ENV.fetch("ALEPH_ALPHA_ACCESS_TOKEN")
|
|
74
|
+
config.uri_base = "https://other-api-endpoint.aleph-alpha.com" # Optional
|
|
75
|
+
config.request_timeout = 240 # Optional
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Models
|
|
80
|
+
|
|
81
|
+
There are different models that can be used to generate text. For a full list:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
client.models.list
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Current API version
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
client.version
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Tokens
|
|
94
|
+
|
|
95
|
+
#### Get a list of issued API tokens
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
client.tokens.list
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Create a new API token
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
client.tokens.create(
|
|
105
|
+
parameters: {
|
|
106
|
+
description: "token used on my laptop"
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Delete an API token
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
client.tokens.delete(id: 123)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Users
|
|
118
|
+
|
|
119
|
+
#### Get settings for own user
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
client.users.me
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Change settings for own user
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
client.users.settings(
|
|
129
|
+
parameters: {
|
|
130
|
+
out_of_credits_threshold: 0
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Query Recent Usage
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
client.users.usage
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Tasks
|
|
142
|
+
|
|
143
|
+
#### Completion
|
|
144
|
+
|
|
145
|
+
```ruby
|
|
146
|
+
client.completions(
|
|
147
|
+
parameters: {
|
|
148
|
+
model: "model name",
|
|
149
|
+
prompt: "some text",
|
|
150
|
+
maximum_tokens: 64
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Embeddings
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
client.embeddings(
|
|
159
|
+
parameters: {
|
|
160
|
+
model: "model name",
|
|
161
|
+
prompt: "some text",
|
|
162
|
+
layers: [
|
|
163
|
+
0,
|
|
164
|
+
1
|
|
165
|
+
],
|
|
166
|
+
tokens: false,
|
|
167
|
+
pooling: [
|
|
168
|
+
"max"
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Semantic Embeddings
|
|
175
|
+
|
|
176
|
+
```ruby
|
|
177
|
+
client.semantic_embeddings(
|
|
178
|
+
parameters: {
|
|
179
|
+
model: "model name",
|
|
180
|
+
prompt: "some text",
|
|
181
|
+
representation: "symmetric",
|
|
182
|
+
compress_to_size: 128
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Evaluate
|
|
188
|
+
|
|
189
|
+
```ruby
|
|
190
|
+
client.evaluate(
|
|
191
|
+
parameters: {
|
|
192
|
+
model: "model name",
|
|
193
|
+
prompt: "some text",
|
|
194
|
+
completion_expected: "another text"
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### Explanation
|
|
200
|
+
|
|
201
|
+
```ruby
|
|
202
|
+
client.explain(
|
|
203
|
+
parameters: {
|
|
204
|
+
model: "model name",
|
|
205
|
+
hosting: "aleph-alpha",
|
|
206
|
+
prompt: "some text",
|
|
207
|
+
target: "string",
|
|
208
|
+
control_factor: 0.1,
|
|
209
|
+
contextual_control_threshold: 0,
|
|
210
|
+
control_log_additive: true,
|
|
211
|
+
postprocessing: "none",
|
|
212
|
+
normalize: false,
|
|
213
|
+
prompt_granularity: {
|
|
214
|
+
type: "token",
|
|
215
|
+
delimiter: "string"
|
|
216
|
+
},
|
|
217
|
+
target_granularity: "complete",
|
|
218
|
+
control_token_overlap: "partial"
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Tokenize
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
client.tokenize(
|
|
227
|
+
parameters: {
|
|
228
|
+
model: "model name",
|
|
229
|
+
prompt: "some text",
|
|
230
|
+
tokens: true,
|
|
231
|
+
token_ids: true
|
|
232
|
+
}
|
|
233
|
+
)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Detokenize
|
|
237
|
+
|
|
238
|
+
```ruby
|
|
239
|
+
client.detokenize(
|
|
240
|
+
parameters: {
|
|
241
|
+
model: model,
|
|
242
|
+
token_ids: [
|
|
243
|
+
556,
|
|
244
|
+
48_741,
|
|
245
|
+
247,
|
|
246
|
+
2983,
|
|
247
|
+
28_063,
|
|
248
|
+
301,
|
|
249
|
+
10_510,
|
|
250
|
+
5469,
|
|
251
|
+
17
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
#### Q&A
|
|
258
|
+
|
|
259
|
+
```ruby
|
|
260
|
+
client.qa(
|
|
261
|
+
parameters: {
|
|
262
|
+
query: "some text",
|
|
263
|
+
documents: [
|
|
264
|
+
{
|
|
265
|
+
text: "another text"
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Summarize
|
|
273
|
+
|
|
274
|
+
```ruby
|
|
275
|
+
client.summarize(
|
|
276
|
+
parameters: {
|
|
277
|
+
model: "model name",
|
|
278
|
+
document: {
|
|
279
|
+
text: "Text about something..."
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Initially, this gem is based on [ruby-openai](https://github.com/alexrudall/ruby-openai). I didn't want to reinvent the wheel and if possible have a similar API for convenience. Bug reports and pull requests are welcome on GitHub at <https://github.com/skorth/aleph-alpha-ruby>.
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module AlephAlpha
|
|
2
|
+
class Client
|
|
3
|
+
extend AlephAlpha::HTTP
|
|
4
|
+
|
|
5
|
+
def initialize(access_token: nil, uri_base: nil, request_timeout: nil)
|
|
6
|
+
AlephAlpha.configuration.access_token = access_token if access_token
|
|
7
|
+
AlephAlpha.configuration.uri_base = uri_base if uri_base
|
|
8
|
+
AlephAlpha.configuration.request_timeout = request_timeout if request_timeout
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def version
|
|
12
|
+
AlephAlpha::Client.get(path: "/version")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def tokens
|
|
16
|
+
@tokens ||= AlephAlpha::Tokens.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def models
|
|
20
|
+
@models ||= AlephAlpha::Models.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def users
|
|
24
|
+
@users ||= AlephAlpha::Users.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def completions(parameters: {}, nice: false)
|
|
28
|
+
AlephAlpha::Client.json_post(path: "/complete?nice=#{nice}", parameters: parameters)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def embeddings(parameters: {}, nice: false)
|
|
32
|
+
AlephAlpha::Client.json_post(path: "/embed?nice=#{nice}", parameters: parameters)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def semantic_embeddings(parameters: {}, nice: false)
|
|
36
|
+
AlephAlpha::Client.json_post(path: "/semantic_embed?nice=#{nice}", parameters: parameters)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def evaluate(parameters: {}, nice: false)
|
|
40
|
+
AlephAlpha::Client.json_post(path: "/evaluate?nice=#{nice}", parameters: parameters)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def explain(parameters: {}, nice: false)
|
|
44
|
+
AlephAlpha::Client.json_post(path: "/explain?nice=#{nice}", parameters: parameters)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def tokenize(parameters: {})
|
|
48
|
+
AlephAlpha::Client.json_post(path: "/tokenize", parameters: parameters)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def detokenize(parameters: {})
|
|
52
|
+
AlephAlpha::Client.json_post(path: "/detokenize", parameters: parameters)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def qa(parameters: {}, nice: false)
|
|
56
|
+
AlephAlpha::Client.json_post(path: "/qa?nice=#{nice}", parameters: parameters)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def summarize(parameters: {}, nice: false)
|
|
60
|
+
AlephAlpha::Client.json_post(path: "/summarize?nice=#{nice}", parameters: parameters)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def permissions(parameters: [])
|
|
64
|
+
AlephAlpha::Client.json_post(path: "/check_privileges", parameters: parameters)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module AlephAlpha
|
|
2
|
+
module HTTP
|
|
3
|
+
def get(path:)
|
|
4
|
+
to_json(conn.get(uri(path: path)) do |req|
|
|
5
|
+
req.headers = headers
|
|
6
|
+
end&.body)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def json_post(path:, parameters:)
|
|
10
|
+
to_json(conn.post(uri(path: path)) do |req|
|
|
11
|
+
req.headers = headers
|
|
12
|
+
req.body = parameters.to_json
|
|
13
|
+
end&.body)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def json_patch(path:, parameters:)
|
|
17
|
+
to_json(conn.patch(uri(path: path)) do |req|
|
|
18
|
+
req.headers = headers
|
|
19
|
+
req.body = parameters.to_json
|
|
20
|
+
end&.body)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def delete(path:)
|
|
24
|
+
to_json(conn.delete(uri(path: path)) do |req|
|
|
25
|
+
req.headers = headers
|
|
26
|
+
end&.body)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def headers
|
|
32
|
+
{
|
|
33
|
+
"Content-Type" => "application/json",
|
|
34
|
+
"Authorization" => "Bearer #{AlephAlpha.configuration.access_token}"
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def uri(path:)
|
|
39
|
+
AlephAlpha.configuration.uri_base + path
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_json(string)
|
|
43
|
+
return unless string
|
|
44
|
+
|
|
45
|
+
JSON.parse(string)
|
|
46
|
+
rescue JSON::ParserError
|
|
47
|
+
string
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def conn
|
|
51
|
+
Faraday.new do |f|
|
|
52
|
+
f.options[:timeout] = AlephAlpha.configuration.request_timeout
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module AlephAlpha
|
|
2
|
+
class Tokens
|
|
3
|
+
def initialize(access_token: nil)
|
|
4
|
+
AlephAlpha.configuration.access_token = access_token if access_token
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def list
|
|
8
|
+
AlephAlpha::Client.get(path: "/users/me/tokens")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create(parameters: {})
|
|
12
|
+
AlephAlpha::Client.json_post(path: "/users/me/tokens", parameters: parameters)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def delete(id:)
|
|
16
|
+
AlephAlpha::Client.delete(path: "/users/me/tokens/#{id}")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module AlephAlpha
|
|
2
|
+
class Users
|
|
3
|
+
def initialize(access_token: nil)
|
|
4
|
+
AlephAlpha.configuration.access_token = access_token if access_token
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def me
|
|
8
|
+
AlephAlpha::Client.get(path: "/users/me")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def usage
|
|
12
|
+
AlephAlpha::Client.get(path: "/users/me/requests")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def settings(parameters: {})
|
|
16
|
+
AlephAlpha::Client.json_patch(path: "/users/me", parameters: parameters)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/aleph-alpha.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "faraday"
|
|
2
|
+
|
|
3
|
+
require_relative "aleph-alpha/version"
|
|
4
|
+
require_relative "aleph-alpha/http"
|
|
5
|
+
require_relative "aleph-alpha/client"
|
|
6
|
+
require_relative "aleph-alpha/tokens"
|
|
7
|
+
require_relative "aleph-alpha/models"
|
|
8
|
+
require_relative "aleph-alpha/users"
|
|
9
|
+
|
|
10
|
+
module AlephAlpha
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
class ConfigurationError < Error; end
|
|
13
|
+
|
|
14
|
+
class Configuration
|
|
15
|
+
attr_writer :access_token
|
|
16
|
+
attr_accessor :uri_base, :request_timeout
|
|
17
|
+
|
|
18
|
+
DEFAULT_URI_BASE = "https://api.aleph-alpha.com".freeze
|
|
19
|
+
DEFAULT_REQUEST_TIMEOUT = 120
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@access_token = nil
|
|
23
|
+
@uri_base = DEFAULT_URI_BASE
|
|
24
|
+
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def access_token
|
|
28
|
+
return @access_token if @access_token
|
|
29
|
+
|
|
30
|
+
error_text = "AlephAlpha access token missing!"
|
|
31
|
+
raise ConfigurationError, error_text
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
attr_writer :configuration
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.configuration
|
|
40
|
+
@configuration ||= AlephAlpha::Configuration.new
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.configure
|
|
44
|
+
yield(configuration)
|
|
45
|
+
end
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: aleph-alpha-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sascha Korth
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-05-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1'
|
|
27
|
+
description:
|
|
28
|
+
email:
|
|
29
|
+
- korth.sascha@gmail.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".editorconfig"
|
|
35
|
+
- ".rspec"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- ".ruby-version"
|
|
38
|
+
- CHANGELOG.md
|
|
39
|
+
- Gemfile
|
|
40
|
+
- Gemfile.lock
|
|
41
|
+
- LICENSE.txt
|
|
42
|
+
- README.md
|
|
43
|
+
- Rakefile
|
|
44
|
+
- lib/aleph-alpha.rb
|
|
45
|
+
- lib/aleph-alpha/client.rb
|
|
46
|
+
- lib/aleph-alpha/http.rb
|
|
47
|
+
- lib/aleph-alpha/models.rb
|
|
48
|
+
- lib/aleph-alpha/tokens.rb
|
|
49
|
+
- lib/aleph-alpha/users.rb
|
|
50
|
+
- lib/aleph-alpha/version.rb
|
|
51
|
+
homepage: https://github.com/skorth/aleph-alpha-ruby
|
|
52
|
+
licenses:
|
|
53
|
+
- MIT
|
|
54
|
+
metadata:
|
|
55
|
+
homepage_uri: https://github.com/skorth/aleph-alpha-ruby
|
|
56
|
+
source_code_uri: https://github.com/skorth/aleph-alpha-ruby
|
|
57
|
+
changelog_uri: https://github.com/skorth/aleph-alpha-ruby/blob/main/CHANGELOG.md
|
|
58
|
+
rubygems_mfa_required: 'true'
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 2.7.0
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubygems_version: 3.1.6
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 4
|
|
77
|
+
summary: Aleph Alpha Ruby Client
|
|
78
|
+
test_files: []
|