deepl-rb 3.0.2 → 3.1.0
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/CHANGELOG.md +11 -0
- data/README.md +17 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +3 -3
- data/lib/deepl/requests/translate.rb +2 -2
- data/lib/deepl/resources/text.rb +3 -2
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +132 -0
- data/spec/requests/translate_spec.rb +27 -0
- data/spec/resources/text_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de43b1593c5b5d4236c0b064c08436ab57fe13bf3fdc29069220fd899ca8e1d
|
4
|
+
data.tar.gz: a486d446fa3bebddbf3fd6aa468300bead03eafe8bc075c33a28d80be6e555b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca167089f7a190915436fb316a8a82aa69bf8093316b4074c6536bb21e002811d9bdd57fc8711eeb634025b094a9fe17e2b057eee5ea5d2499539060e09b8ebd
|
7
|
+
data.tar.gz: 1c63cd745170652f01a2335cc064ceb0266c1584a19bd1fcd6683c6d461241b646d33df0b3e36f516e1dff6a1d6158e706994b862b6bd8d671b1db399cabfa03
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
7
|
|
8
|
+
## [3.1.0]
|
9
|
+
### Added
|
10
|
+
* Added `model_type` option to `translate()` to use models with higher
|
11
|
+
translation quality (available for some language pairs), or better latency.
|
12
|
+
Options are `'quality_optimized'`, `'latency_optimized'`, and `'prefer_quality_optimized'`
|
13
|
+
* Added the `model_type_used` field to the `translate()` response, that
|
14
|
+
indicates the translation model used when the `model_type` option is
|
15
|
+
specified.
|
16
|
+
|
17
|
+
|
8
18
|
## [3.0.2] - 2024-10-02
|
9
19
|
### Added
|
10
20
|
* Added doc example and tests for context parameter
|
@@ -41,6 +51,7 @@ The change in major version is only due to the change in maintainership, there i
|
|
41
51
|
* Make RequestEntityTooLarge error message more clear
|
42
52
|
|
43
53
|
|
54
|
+
[3.1.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.2...v3.1.0
|
44
55
|
[3.0.2]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.1...v3.0.2
|
45
56
|
[3.0.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.0...v3.0.1
|
46
57
|
[3.0.0]: https://github.com/DeepLcom/deepl-rb/compare/v2.5.3...v3.0.0
|
data/README.md
CHANGED
@@ -137,6 +137,23 @@ puts translation.text
|
|
137
137
|
# => "¡Eso es picante!"
|
138
138
|
```
|
139
139
|
|
140
|
+
To specify a type of translation model to use, you can use the `model_type` option:
|
141
|
+
|
142
|
+
```rb
|
143
|
+
translation = DeepL.translate 'That is hot!', 'EN', 'DE',
|
144
|
+
model_type: 'quality_optimized'
|
145
|
+
```
|
146
|
+
|
147
|
+
This would use next-gen translation models for the translation. The available values are
|
148
|
+
|
149
|
+
- `'quality_optimized'`: use a translation model that maximizes translation quality, at the
|
150
|
+
cost of response time. This option may be unavailable for some language pairs.
|
151
|
+
- `'prefer_quality_optimized'`: use the highest-quality translation model for the given
|
152
|
+
language pair.
|
153
|
+
- `'latency_optimized'`: use a translation model that minimizes response time, at the cost
|
154
|
+
of translation quality.
|
155
|
+
|
156
|
+
|
140
157
|
The following parameters will be automatically converted:
|
141
158
|
|
142
159
|
| Parameter | Conversion
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0
|
1
|
+
3.1.0
|
data/deepl-rb.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deepl-rb 3.0
|
5
|
+
# stub: deepl-rb 3.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "3.0
|
9
|
+
s.version = "3.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.metadata = { "bug_tracker_uri" => "https://github.com/DeepLcom/deepl-rb/issues", "changelog_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md", "documentation_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/README.md", "homepage_uri" => "https://github.com/DeepLcom/deepl-rb" } if s.respond_to? :metadata=
|
13
13
|
s.require_paths = ["lib".freeze]
|
14
14
|
s.authors = ["DeepL SE".freeze]
|
15
|
-
s.date = "2024-
|
15
|
+
s.date = "2024-11-15"
|
16
16
|
s.description = "Official Ruby library for the DeepL language translation API (v2). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
|
17
17
|
s.email = "open-source@deepl.com".freeze
|
18
18
|
s.extra_rdoc_files = [
|
@@ -27,7 +27,7 @@ module DeepL
|
|
27
27
|
}.freeze
|
28
28
|
|
29
29
|
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
|
30
|
-
:non_splitting_tags
|
30
|
+
:non_splitting_tags, :model_type
|
31
31
|
|
32
32
|
def initialize(api, text, source_lang, target_lang, options = {})
|
33
33
|
super(api, options)
|
@@ -68,7 +68,7 @@ module DeepL
|
|
68
68
|
|
69
69
|
texts = data['translations'].map do |translation|
|
70
70
|
Resources::Text.new(translation['text'], translation['detected_source_language'],
|
71
|
-
request, response)
|
71
|
+
translation['model_type_used'], request, response)
|
72
72
|
end
|
73
73
|
|
74
74
|
texts.size == 1 ? texts.first : texts
|
data/lib/deepl/resources/text.rb
CHANGED
@@ -6,13 +6,14 @@
|
|
6
6
|
module DeepL
|
7
7
|
module Resources
|
8
8
|
class Text < Base
|
9
|
-
attr_reader :text, :detected_source_language
|
9
|
+
attr_reader :text, :detected_source_language, :model_type_used
|
10
10
|
|
11
|
-
def initialize(text, detected_source_language, *args)
|
11
|
+
def initialize(text, detected_source_language, model_type_used, *args)
|
12
12
|
super(*args)
|
13
13
|
|
14
14
|
@text = text
|
15
15
|
@detected_source_language = detected_source_language
|
16
|
+
@model_type_used = model_type_used
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_s
|
@@ -10237,4 +10237,136 @@ http_interactions:
|
|
10237
10237
|
string: !binary |-
|
10238
10238
|
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IsKhRXNvIGVzIHBpY2FudGUhIn1dfQ==
|
10239
10239
|
recorded_at: Wed, 25 Sep 2024 16:08:00 GMT
|
10240
|
+
- request:
|
10241
|
+
method: post
|
10242
|
+
uri: https://api.deepl.com/v2/translate
|
10243
|
+
body:
|
10244
|
+
encoding: UTF-8
|
10245
|
+
string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"quality_optimized"}'
|
10246
|
+
headers:
|
10247
|
+
Authorization:
|
10248
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10249
|
+
User-Agent:
|
10250
|
+
- deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
|
10251
|
+
Content-Type:
|
10252
|
+
- application/json
|
10253
|
+
Accept-Encoding:
|
10254
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10255
|
+
Accept:
|
10256
|
+
- "*/*"
|
10257
|
+
response:
|
10258
|
+
status:
|
10259
|
+
code: 200
|
10260
|
+
message: OK
|
10261
|
+
headers:
|
10262
|
+
Date:
|
10263
|
+
- Fri, 08 Nov 2024 15:57:39 GMT
|
10264
|
+
Content-Type:
|
10265
|
+
- application/json
|
10266
|
+
Transfer-Encoding:
|
10267
|
+
- chunked
|
10268
|
+
Vary:
|
10269
|
+
- Accept-Encoding
|
10270
|
+
Access-Control-Allow-Origin:
|
10271
|
+
- "*"
|
10272
|
+
Strict-Transport-Security:
|
10273
|
+
- max-age=63072000; includeSubDomains; preload
|
10274
|
+
Server-Timing:
|
10275
|
+
- l7_lb_tls;dur=89, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=165
|
10276
|
+
Access-Control-Expose-Headers:
|
10277
|
+
- Server-Timing, X-Trace-ID
|
10278
|
+
X-Trace-Id:
|
10279
|
+
- 7d71b768eebc41da8c5b820c33e7cdc1
|
10280
|
+
body:
|
10281
|
+
encoding: ASCII-8BIT
|
10282
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Mustertext","model_type_used":"quality_optimized"}]}'
|
10283
|
+
recorded_at: Fri, 08 Nov 2024 15:57:39 GMT
|
10284
|
+
- request:
|
10285
|
+
method: post
|
10286
|
+
uri: https://api.deepl.com/v2/translate
|
10287
|
+
body:
|
10288
|
+
encoding: UTF-8
|
10289
|
+
string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"prefer_quality_optimized"}'
|
10290
|
+
headers:
|
10291
|
+
Authorization:
|
10292
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10293
|
+
User-Agent:
|
10294
|
+
- deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
|
10295
|
+
Content-Type:
|
10296
|
+
- application/json
|
10297
|
+
Accept-Encoding:
|
10298
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10299
|
+
Accept:
|
10300
|
+
- "*/*"
|
10301
|
+
response:
|
10302
|
+
status:
|
10303
|
+
code: 200
|
10304
|
+
message: OK
|
10305
|
+
headers:
|
10306
|
+
Date:
|
10307
|
+
- Mon, 11 Nov 2024 10:58:59 GMT
|
10308
|
+
Content-Type:
|
10309
|
+
- application/json
|
10310
|
+
Transfer-Encoding:
|
10311
|
+
- chunked
|
10312
|
+
Vary:
|
10313
|
+
- Accept-Encoding
|
10314
|
+
Access-Control-Allow-Origin:
|
10315
|
+
- "*"
|
10316
|
+
Strict-Transport-Security:
|
10317
|
+
- max-age=63072000; includeSubDomains; preload
|
10318
|
+
Server-Timing:
|
10319
|
+
- l7_lb_tls;dur=98, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=320
|
10320
|
+
Access-Control-Expose-Headers:
|
10321
|
+
- Server-Timing, X-Trace-ID
|
10322
|
+
X-Trace-Id:
|
10323
|
+
- 0fa07be47b3b458ebf50268ca2efe7fe
|
10324
|
+
body:
|
10325
|
+
encoding: ASCII-8BIT
|
10326
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Mustertext","model_type_used":"quality_optimized"}]}'
|
10327
|
+
recorded_at: Mon, 11 Nov 2024 10:58:59 GMT
|
10328
|
+
- request:
|
10329
|
+
method: post
|
10330
|
+
uri: https://api.deepl.com/v2/translate
|
10331
|
+
body:
|
10332
|
+
encoding: UTF-8
|
10333
|
+
string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"latency_optimized"}'
|
10334
|
+
headers:
|
10335
|
+
Authorization:
|
10336
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10337
|
+
User-Agent:
|
10338
|
+
- deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
|
10339
|
+
Content-Type:
|
10340
|
+
- application/json
|
10341
|
+
Accept-Encoding:
|
10342
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
10343
|
+
Accept:
|
10344
|
+
- "*/*"
|
10345
|
+
response:
|
10346
|
+
status:
|
10347
|
+
code: 200
|
10348
|
+
message: OK
|
10349
|
+
headers:
|
10350
|
+
Date:
|
10351
|
+
- Fri, 15 Nov 2024 11:35:22 GMT
|
10352
|
+
Content-Type:
|
10353
|
+
- application/json
|
10354
|
+
Transfer-Encoding:
|
10355
|
+
- chunked
|
10356
|
+
Vary:
|
10357
|
+
- Accept-Encoding
|
10358
|
+
Access-Control-Allow-Origin:
|
10359
|
+
- "*"
|
10360
|
+
Strict-Transport-Security:
|
10361
|
+
- max-age=63072000; includeSubDomains; preload
|
10362
|
+
Server-Timing:
|
10363
|
+
- l7_lb_tls;dur=136, l7_lb_idle;dur=2, l7_lb_receive;dur=0, l7_lb_total;dur=156
|
10364
|
+
Access-Control-Expose-Headers:
|
10365
|
+
- Server-Timing, X-Trace-ID
|
10366
|
+
X-Trace-Id:
|
10367
|
+
- de2645cb65c3418db54e3bdefd35fe52
|
10368
|
+
body:
|
10369
|
+
encoding: ASCII-8BIT
|
10370
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Beispieltext","model_type_used":"latency_optimized"}]}'
|
10371
|
+
recorded_at: Fri, 15 Nov 2024 11:35:22 GMT
|
10240
10372
|
recorded_with: VCR 6.2.0
|
@@ -190,6 +190,18 @@ describe DeepL::Requests::Translate do
|
|
190
190
|
expect(request.options[:formality]).to eq('more')
|
191
191
|
end
|
192
192
|
end
|
193
|
+
|
194
|
+
context 'when using `model_type` options' do
|
195
|
+
it 'works with a nil value' do
|
196
|
+
request = described_class.new(api, nil, nil, nil, model_type: nil)
|
197
|
+
expect(request.options[:model_type]).to be_nil
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'works with a string' do
|
201
|
+
request = described_class.new(api, nil, nil, nil, model_type: 'latency_optimized')
|
202
|
+
expect(request.options[:model_type]).to eq('latency_optimized')
|
203
|
+
end
|
204
|
+
end
|
193
205
|
end
|
194
206
|
|
195
207
|
describe '#request' do
|
@@ -316,6 +328,21 @@ describe DeepL::Requests::Translate do
|
|
316
328
|
end
|
317
329
|
end
|
318
330
|
|
331
|
+
context 'when performing a request with a model type' do
|
332
|
+
let(:target_lang) { 'DE' }
|
333
|
+
|
334
|
+
%w[quality_optimized latency_optimized prefer_quality_optimized].each do |model_type_str|
|
335
|
+
it "translates correctly with #{model_type_str} models" do
|
336
|
+
options = { model_type: model_type_str }
|
337
|
+
translate = described_class.new(api, text, source_lang, target_lang, options)
|
338
|
+
res = translate.request
|
339
|
+
expect(res).to be_a(DeepL::Resources::Text)
|
340
|
+
expected_model_type = model_type_str.sub(/^prefer_/, '')
|
341
|
+
expect(res.model_type_used).to eq(expected_model_type)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
319
346
|
context 'when performing a bad request' do
|
320
347
|
context 'when using an invalid token' do
|
321
348
|
let(:api) do
|
data/spec/resources/text_spec.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
require 'spec_helper'
|
7
7
|
|
8
8
|
describe DeepL::Resources::Text do
|
9
|
-
subject(:text) { described_class.new('Target', 'es', nil, nil) }
|
9
|
+
subject(:text) { described_class.new('Target', 'es', nil, nil, nil) }
|
10
10
|
|
11
11
|
describe '#initialize' do
|
12
12
|
context 'when building a basic object' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deepl-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DeepL SE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|