lara-sdk 1.9.2 → 1.11.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/lib/lara/client.rb +35 -4
- data/lib/lara/glossaries.rb +14 -0
- data/lib/lara/memories.rb +14 -0
- data/lib/lara/models/collection_result.rb +27 -0
- data/lib/lara/models/resource_query_options.rb +29 -0
- data/lib/lara/models/text.rb +67 -3
- data/lib/lara/styleguides.rb +14 -0
- data/lib/lara/translator.rb +4 -1
- data/lib/lara/version.rb +1 -1
- data/lib/lara.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d794b96f2ef4b205bf0b46706b9346af3659ee923870116341e87a3688220ee7
|
|
4
|
+
data.tar.gz: e460f4a73a7a25c94c2d57a99a8d6998c06625b9e27723594b9789b86d601061
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 722e1746da8b4735ee5b072b8168cef5996a1aeb7cc059b3ca651da46a0144808c93c7cde7583d300ea0adf02a1b812f24803072e399e35642560b82b10b272f
|
|
7
|
+
data.tar.gz: c3dec84e4e56eec0bbfa2f46ec05a688bbecf2ee76f17bd80c6f78273f33458595b33c42baa39d2cb2d76057c04c9ac16f8c03937847ab1e994aacd976bfdf94
|
data/lib/lara/client.rb
CHANGED
|
@@ -56,6 +56,22 @@ module Lara
|
|
|
56
56
|
request(:get, path, body: nil, headers: headers, params: params)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# Retrieves a collection using pagination metadata from the response headers.
|
|
60
|
+
# @yield [Hash] Converts each resource to its SDK model
|
|
61
|
+
# @return [Lara::Models::CollectionResult]
|
|
62
|
+
def get_collection(path, params: nil)
|
|
63
|
+
items, headers = request(:get, path, params: params, with_metadata: true)
|
|
64
|
+
total = integer_header(headers, "x-total-count", minimum: 0)
|
|
65
|
+
raise LaraError, "Missing or invalid X-Total-Count response header" if total.nil?
|
|
66
|
+
|
|
67
|
+
Lara::Models::CollectionResult.new(
|
|
68
|
+
items: block_given? ? items.map { |item| yield item } : items,
|
|
69
|
+
total: total,
|
|
70
|
+
page: integer_header(headers, "x-page", minimum: 1),
|
|
71
|
+
size: integer_header(headers, "x-page-size", minimum: 1)
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
59
75
|
# Sends a POST request to the Lara API.
|
|
60
76
|
# @param path [String] The path to send the request to.
|
|
61
77
|
# @param body [Hash,nil] The parameters to send with the request.
|
|
@@ -90,8 +106,19 @@ module Lara
|
|
|
90
106
|
|
|
91
107
|
private
|
|
92
108
|
|
|
109
|
+
def integer_header(headers, name, minimum:)
|
|
110
|
+
value = headers.find { |key, _| key.downcase == name }&.last
|
|
111
|
+
return nil unless value.is_a?(String)
|
|
112
|
+
|
|
113
|
+
value = value.gsub(/\A[ \t]+|[ \t]+\z/, "")
|
|
114
|
+
return nil unless value.match?(/\A[0-9]+\z/)
|
|
115
|
+
|
|
116
|
+
number = value.to_i
|
|
117
|
+
number if number >= minimum
|
|
118
|
+
end
|
|
119
|
+
|
|
93
120
|
def request(method, path, body: nil, files: nil, headers: nil, params: nil,
|
|
94
|
-
raw_response: false, &callback)
|
|
121
|
+
raw_response: false, with_metadata: false, &callback)
|
|
95
122
|
file_positions = (files || {}).each_with_object({}) do |(name, file), positions|
|
|
96
123
|
next unless file.respond_to?(:pos) && file.respond_to?(:seek)
|
|
97
124
|
|
|
@@ -104,7 +131,8 @@ module Lara
|
|
|
104
131
|
ensure_valid_token
|
|
105
132
|
|
|
106
133
|
make_request(method, path, body: body, files: files, headers: headers, params: params,
|
|
107
|
-
raw_response: raw_response,
|
|
134
|
+
raw_response: raw_response, with_metadata: with_metadata,
|
|
135
|
+
&callback)
|
|
108
136
|
rescue LaraApiError => e
|
|
109
137
|
raise unless e.status_code == 401
|
|
110
138
|
|
|
@@ -112,7 +140,8 @@ module Lara
|
|
|
112
140
|
# Multipart encoding consumed the files; replay their original bytes.
|
|
113
141
|
file_positions.each { |name, position| files[name].seek(position) }
|
|
114
142
|
make_request(method, path, body: body, files: files, headers: headers, params: params,
|
|
115
|
-
raw_response: raw_response,
|
|
143
|
+
raw_response: raw_response, with_metadata: with_metadata,
|
|
144
|
+
&callback)
|
|
116
145
|
end
|
|
117
146
|
|
|
118
147
|
def ensure_valid_token
|
|
@@ -204,7 +233,7 @@ module Lara
|
|
|
204
233
|
end
|
|
205
234
|
|
|
206
235
|
def make_request(method, path, body: nil, files: nil, headers: nil, params: nil,
|
|
207
|
-
raw_response: false, &callback)
|
|
236
|
+
raw_response: false, with_metadata: false, &callback)
|
|
208
237
|
path = "/#{path}" unless path.start_with?("/")
|
|
209
238
|
request_headers = build_request_headers(body, files, headers)
|
|
210
239
|
|
|
@@ -226,6 +255,8 @@ module Lara
|
|
|
226
255
|
|
|
227
256
|
raise LaraApiError.from_response(response) unless response.success?
|
|
228
257
|
|
|
258
|
+
return [parse_json(response.body), response.headers] if with_metadata
|
|
259
|
+
|
|
229
260
|
return response.body if raw_response
|
|
230
261
|
|
|
231
262
|
content_type = response.headers["content-type"] || response.headers["Content-Type"]
|
data/lib/lara/glossaries.rb
CHANGED
|
@@ -25,13 +25,27 @@ module Lara
|
|
|
25
25
|
@polling_interval = 2
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# @deprecated Use #list_paginated instead.
|
|
28
29
|
# @return [Array<Lara::Models::Glossary>]
|
|
29
30
|
def list
|
|
31
|
+
warn "[DEPRECATION] list is deprecated; use list_paginated instead.", uplevel: 1
|
|
30
32
|
(@client.get("/v2/glossaries") || []).map do |_h|
|
|
31
33
|
Lara::Models::Glossary.new(**_h.transform_keys(&:to_sym))
|
|
32
34
|
end
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
# Lists resources with optional name filtering and pagination.
|
|
38
|
+
# Without options, returns the complete collection without pagination.
|
|
39
|
+
# Any supplied option enables pagination; page and size default to 1 and 20.
|
|
40
|
+
# @param options [Lara::Models::ResourceQueryOptions,nil] Name filter and pagination
|
|
41
|
+
# @return [Lara::Models::CollectionResult] Collection containing Glossary objects
|
|
42
|
+
def list_paginated(options = nil)
|
|
43
|
+
params = options&.to_params || {}
|
|
44
|
+
@client.get_collection("/v2/glossaries", params: params) do |item|
|
|
45
|
+
Lara::Models::Glossary.new(**item.transform_keys(&:to_sym))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
35
49
|
# @return [Lara::Models::Glossary]
|
|
36
50
|
def create(name:)
|
|
37
51
|
Lara::Models::Glossary.new(**@client.post("/v2/glossaries",
|
data/lib/lara/memories.rb
CHANGED
|
@@ -24,13 +24,27 @@ module Lara
|
|
|
24
24
|
@polling_interval = 2
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# @deprecated Use #list_paginated instead.
|
|
27
28
|
# @return [Array<Lara::Models::Memory>]
|
|
28
29
|
def list
|
|
30
|
+
warn "[DEPRECATION] list is deprecated; use list_paginated instead.", uplevel: 1
|
|
29
31
|
(@client.get("/v2/memories") || []).map do |_h|
|
|
30
32
|
Lara::Models::Memory.new(**_h.transform_keys(&:to_sym))
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
|
|
36
|
+
# Lists resources with optional name filtering and pagination.
|
|
37
|
+
# Without options, returns the complete collection without pagination.
|
|
38
|
+
# Any supplied option enables pagination; page and size default to 1 and 20.
|
|
39
|
+
# @param options [Lara::Models::ResourceQueryOptions,nil] Name filter and pagination
|
|
40
|
+
# @return [Lara::Models::CollectionResult] Collection containing Memory objects
|
|
41
|
+
def list_paginated(options = nil)
|
|
42
|
+
params = options&.to_params || {}
|
|
43
|
+
@client.get_collection("/v2/memories", params: params) do |item|
|
|
44
|
+
Lara::Models::Memory.new(**item.transform_keys(&:to_sym))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
34
48
|
# @return [Lara::Models::Memory]
|
|
35
49
|
def create(name:, external_id: nil)
|
|
36
50
|
payload = { name: name, external_id: external_id }.compact
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Lara
|
|
6
|
+
module Models
|
|
7
|
+
# A resource collection and its server-provided pagination metadata.
|
|
8
|
+
class CollectionResult < Base
|
|
9
|
+
# @return [Array<Lara::Models::Memory,Lara::Models::Glossary,Lara::Models::Styleguide>]
|
|
10
|
+
attr_reader :items
|
|
11
|
+
# @return [Integer] Total number of matching resources
|
|
12
|
+
attr_reader :total
|
|
13
|
+
# @return [Integer,nil] Current page (1-based), or nil for an unbounded collection
|
|
14
|
+
attr_reader :page
|
|
15
|
+
# @return [Integer,nil] Page size, or nil for an unbounded collection
|
|
16
|
+
attr_reader :size
|
|
17
|
+
|
|
18
|
+
def initialize(items:, total:, page: nil, size: nil)
|
|
19
|
+
super()
|
|
20
|
+
@items = items
|
|
21
|
+
@total = total
|
|
22
|
+
@page = page
|
|
23
|
+
@size = size
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module Lara
|
|
6
|
+
module Models
|
|
7
|
+
# Optional name filtering and pagination for resource collections.
|
|
8
|
+
class ResourceQueryOptions < Base
|
|
9
|
+
# @return [String,nil] Filter by visible name (1-255 characters)
|
|
10
|
+
attr_reader :search
|
|
11
|
+
# @return [Integer,nil] Page number (1-based); enables pagination when supplied
|
|
12
|
+
attr_reader :page
|
|
13
|
+
# @return [Integer,nil] Page size (1-200); enables pagination when supplied
|
|
14
|
+
attr_reader :size
|
|
15
|
+
|
|
16
|
+
def initialize(search: nil, page: nil, size: nil)
|
|
17
|
+
super()
|
|
18
|
+
@search = search
|
|
19
|
+
@page = page
|
|
20
|
+
@size = size
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Hash] Supplied options; validation and defaults are handled by the API
|
|
24
|
+
def to_params
|
|
25
|
+
{ search: search, page: page, size: size }.compact
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/lara/models/text.rb
CHANGED
|
@@ -167,11 +167,73 @@ module Lara
|
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
|
|
170
|
+
class IntelligenceError < Base
|
|
171
|
+
attr_reader :status_code, :message
|
|
172
|
+
|
|
173
|
+
def initialize(status_code:, message:)
|
|
174
|
+
super()
|
|
175
|
+
@status_code = status_code
|
|
176
|
+
@message = message
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def self.from_hash(hash)
|
|
180
|
+
return nil if hash.nil?
|
|
181
|
+
|
|
182
|
+
new(status_code: hash["statusCode"] || hash["status_code"], message: hash["message"])
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
class IntelligenceFailure < Base
|
|
187
|
+
attr_reader :applied, :error
|
|
188
|
+
|
|
189
|
+
def initialize(applied:, error:)
|
|
190
|
+
super()
|
|
191
|
+
@applied = applied
|
|
192
|
+
@error = IntelligenceError.from_hash(error)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Applied is false or "partial" for reference retrieval failures.
|
|
197
|
+
class ReferenceRetrievalFailure < IntelligenceFailure
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
class ReasoningWarning < Base
|
|
201
|
+
attr_reader :code, :message
|
|
202
|
+
|
|
203
|
+
def initialize(code:, message:)
|
|
204
|
+
super()
|
|
205
|
+
@code = code
|
|
206
|
+
@message = message
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
class ReasoningFeedback < Base
|
|
211
|
+
attr_reader :applied, :error, :warnings
|
|
212
|
+
|
|
213
|
+
def initialize(applied:, error: nil, warnings: [])
|
|
214
|
+
super()
|
|
215
|
+
@applied = applied
|
|
216
|
+
@error = IntelligenceError.from_hash(error)
|
|
217
|
+
@warnings = warnings.map { |warning| ReasoningWarning.new(**warning.transform_keys(&:to_sym)) }
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
class TextWarnings < Base
|
|
222
|
+
attr_reader :reasoning, :references, :prosa
|
|
223
|
+
|
|
224
|
+
def initialize(reasoning: nil, references: nil, prosa: nil)
|
|
225
|
+
super()
|
|
226
|
+
@reasoning = ReasoningFeedback.new(**reasoning.transform_keys(&:to_sym)) if reasoning
|
|
227
|
+
@references = ReferenceRetrievalFailure.new(**references.transform_keys(&:to_sym)) if references
|
|
228
|
+
@prosa = IntelligenceFailure.new(**prosa.transform_keys(&:to_sym)) if prosa
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
170
232
|
class TextResult < Base
|
|
171
233
|
attr_reader :content_type, :source_language, :translation,
|
|
172
234
|
:adapted_to, :glossaries,
|
|
173
235
|
:adapted_to_matches, :glossaries_matches,
|
|
174
|
-
:profanities, :styleguide_results
|
|
236
|
+
:profanities, :styleguide_results, :warnings
|
|
175
237
|
|
|
176
238
|
def self.from_hash(hash)
|
|
177
239
|
return nil unless hash.is_a?(Hash)
|
|
@@ -198,13 +260,14 @@ module Lara
|
|
|
198
260
|
adapted_to_matches: adapted_to_matches,
|
|
199
261
|
glossaries_matches: glossaries_matches,
|
|
200
262
|
profanities: profanities,
|
|
201
|
-
styleguide_results: styleguide_results
|
|
263
|
+
styleguide_results: styleguide_results,
|
|
264
|
+
warnings: hash["warnings"] && TextWarnings.new(**hash["warnings"].transform_keys(&:to_sym))
|
|
202
265
|
)
|
|
203
266
|
end
|
|
204
267
|
|
|
205
268
|
def initialize(content_type:, source_language:, translation:, adapted_to: nil, glossaries: nil,
|
|
206
269
|
adapted_to_matches: nil, glossaries_matches: nil, profanities: nil,
|
|
207
|
-
styleguide_results: nil)
|
|
270
|
+
styleguide_results: nil, warnings: nil)
|
|
208
271
|
super()
|
|
209
272
|
@content_type = content_type
|
|
210
273
|
@source_language = source_language
|
|
@@ -215,6 +278,7 @@ module Lara
|
|
|
215
278
|
@glossaries_matches = glossaries_matches
|
|
216
279
|
@profanities = profanities
|
|
217
280
|
@styleguide_results = styleguide_results
|
|
281
|
+
@warnings = warnings
|
|
218
282
|
end
|
|
219
283
|
|
|
220
284
|
class << self
|
data/lib/lara/styleguides.rb
CHANGED
|
@@ -6,13 +6,27 @@ module Lara
|
|
|
6
6
|
@client = client
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
# @deprecated Use #list_paginated instead.
|
|
9
10
|
# @return [Array<Lara::Models::Styleguide>]
|
|
10
11
|
def list
|
|
12
|
+
warn "[DEPRECATION] list is deprecated; use list_paginated instead.", uplevel: 1
|
|
11
13
|
(@client.get("/v2/styleguides") || []).map do |h|
|
|
12
14
|
Lara::Models::Styleguide.new(**h.transform_keys(&:to_sym))
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
18
|
+
# Lists resources with optional name filtering and pagination.
|
|
19
|
+
# Without options, returns the complete collection without pagination.
|
|
20
|
+
# Any supplied option enables pagination; page and size default to 1 and 20.
|
|
21
|
+
# @param options [Lara::Models::ResourceQueryOptions,nil] Name filter and pagination
|
|
22
|
+
# @return [Lara::Models::CollectionResult] Collection containing Styleguide objects
|
|
23
|
+
def list_paginated(options = nil)
|
|
24
|
+
params = options&.to_params || {}
|
|
25
|
+
@client.get_collection("/v2/styleguides", params: params) do |item|
|
|
26
|
+
Lara::Models::Styleguide.new(**item.transform_keys(&:to_sym))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
16
30
|
# @return [Lara::Models::Styleguide]
|
|
17
31
|
def create(name:, content:)
|
|
18
32
|
Lara::Models::Styleguide.new(**@client.post("/v2/styleguides",
|
data/lib/lara/translator.rb
CHANGED
|
@@ -56,6 +56,8 @@ module Lara
|
|
|
56
56
|
# @param verbose [Boolean]
|
|
57
57
|
# @param style [String,nil]
|
|
58
58
|
# @param reasoning [Boolean] When true with a block, yields partial results during reasoning
|
|
59
|
+
# @param image_context [Hash,Array<Hash>,nil] One HTTPS or base64 PNG/JPEG/WebP image; requires reasoning when non-empty.
|
|
60
|
+
# Image validation is performed by the API. An empty array preserves text-only translation.
|
|
59
61
|
# @param headers [Hash,nil]
|
|
60
62
|
# @param metadata [String, Hash, nil]
|
|
61
63
|
# @param profanities_detect [String,nil] One of "target", "source_target"
|
|
@@ -65,7 +67,7 @@ module Lara
|
|
|
65
67
|
def translate(text, target:, source: nil, source_hint: nil, adapt_to: nil, glossaries: nil,
|
|
66
68
|
instructions: nil, content_type: nil, multiline: true, timeout_ms: nil,
|
|
67
69
|
priority: nil, use_cache: nil, cache_ttl_s: nil, no_trace: false, verbose: false,
|
|
68
|
-
style: nil, reasoning: false, headers: nil, metadata: nil,
|
|
70
|
+
style: nil, reasoning: false, image_context: nil, headers: nil, metadata: nil,
|
|
69
71
|
profanities_detect: nil, profanities_handling: nil,
|
|
70
72
|
styleguide_id: nil, styleguide_reasoning: nil,
|
|
71
73
|
styleguide_explanation_language: nil, &callback)
|
|
@@ -94,6 +96,7 @@ module Lara
|
|
|
94
96
|
verbose: verbose,
|
|
95
97
|
style: style,
|
|
96
98
|
reasoning: reasoning,
|
|
99
|
+
image_context: image_context,
|
|
97
100
|
metadata: metadata,
|
|
98
101
|
profanities_detect: profanities_detect,
|
|
99
102
|
profanities_handling: profanities_handling,
|
data/lib/lara/version.rb
CHANGED
data/lib/lara.rb
CHANGED
|
@@ -16,6 +16,8 @@ require_relative "lara/audio"
|
|
|
16
16
|
|
|
17
17
|
# Models
|
|
18
18
|
require_relative "lara/models/base"
|
|
19
|
+
require_relative "lara/models/collection_result"
|
|
20
|
+
require_relative "lara/models/resource_query_options"
|
|
19
21
|
require_relative "lara/models/text"
|
|
20
22
|
require_relative "lara/models/memories"
|
|
21
23
|
require_relative "lara/models/glossaries"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lara-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Translated
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -161,10 +161,12 @@ files:
|
|
|
161
161
|
- lib/lara/memories.rb
|
|
162
162
|
- lib/lara/models/audio.rb
|
|
163
163
|
- lib/lara/models/base.rb
|
|
164
|
+
- lib/lara/models/collection_result.rb
|
|
164
165
|
- lib/lara/models/documents.rb
|
|
165
166
|
- lib/lara/models/glossaries.rb
|
|
166
167
|
- lib/lara/models/images.rb
|
|
167
168
|
- lib/lara/models/memories.rb
|
|
169
|
+
- lib/lara/models/resource_query_options.rb
|
|
168
170
|
- lib/lara/models/shares.rb
|
|
169
171
|
- lib/lara/models/text.rb
|
|
170
172
|
- lib/lara/s3_client.rb
|