mistral_translator 0.3.2 → 0.5.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 +75 -1
- data/README.md +14 -2
- data/docs/api-reference/configuration.md +44 -4
- data/docs/api-reference/errors.md +15 -24
- data/docs/api-reference/methods.md +10 -4
- data/docs/getting-started.md +10 -2
- data/docs/installation.md +0 -2
- data/docs/rails-integration/setup.md +0 -1
- data/lib/mistral_translator/client.rb +18 -19
- data/lib/mistral_translator/client_helpers.rb +41 -23
- data/lib/mistral_translator/configuration.rb +34 -4
- data/lib/mistral_translator/data/languages.json +912 -0
- data/lib/mistral_translator/deprecated_options.rb +45 -0
- data/lib/mistral_translator/helpers.rb +15 -17
- data/lib/mistral_translator/helpers_extensions.rb +1 -59
- data/lib/mistral_translator/locale_helper.rb +19 -31
- data/lib/mistral_translator/prompt.rb +48 -0
- data/lib/mistral_translator/prompt_builder.rb +30 -144
- data/lib/mistral_translator/prompt_helpers.rb +21 -23
- data/lib/mistral_translator/prompt_metadata_helpers.rb +15 -17
- data/lib/mistral_translator/proxy.rb +75 -0
- data/lib/mistral_translator/response_parser.rb +138 -215
- data/lib/mistral_translator/retries.rb +50 -0
- data/lib/mistral_translator/summarizer.rb +33 -146
- data/lib/mistral_translator/translator.rb +33 -95
- data/lib/mistral_translator/translator_helpers.rb +21 -149
- data/lib/mistral_translator/version.rb +1 -1
- data/lib/mistral_translator.rb +1 -1
- metadata +6 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "proxy"
|
|
4
|
+
require_relative "deprecated_options"
|
|
5
|
+
|
|
3
6
|
module MistralTranslator
|
|
4
7
|
class Configuration
|
|
5
|
-
|
|
8
|
+
include DeprecatedOptions
|
|
9
|
+
|
|
10
|
+
attr_accessor :api_key, :model, :retry_delays,
|
|
6
11
|
:on_translation_start, :on_translation_complete, :on_translation_error,
|
|
7
12
|
:on_rate_limit, :on_batch_complete, :enable_metrics,
|
|
8
|
-
:ssl_verify_mode, :ssl_ca_file, :ssl_ca_path
|
|
9
|
-
attr_reader :api_url
|
|
13
|
+
:ssl_verify_mode, :ssl_ca_file, :ssl_ca_path
|
|
14
|
+
attr_reader :api_url, :proxy, :open_timeout, :read_timeout
|
|
10
15
|
|
|
11
16
|
def initialize
|
|
12
17
|
@api_key = nil
|
|
@@ -28,7 +33,13 @@ module MistralTranslator
|
|
|
28
33
|
@ssl_verify_mode = :peer # :peer, :none, or OpenSSL constant
|
|
29
34
|
@ssl_ca_file = nil # Path to CA certificate file
|
|
30
35
|
@ssl_ca_path = nil # Path to CA certificates directory
|
|
31
|
-
|
|
36
|
+
|
|
37
|
+
# Délais en secondes : ouverture de la connexion (TCP puis TLS), puis attente de la réponse
|
|
38
|
+
@open_timeout = 60
|
|
39
|
+
@read_timeout = 60
|
|
40
|
+
|
|
41
|
+
# Proxy : nil (aucun), URI ou String, ou :env (HTTPS_PROXY, HTTP_PROXY, NO_PROXY)
|
|
42
|
+
@proxy = nil
|
|
32
43
|
|
|
33
44
|
# Métriques intégrées (thread-safe avec mutex)
|
|
34
45
|
@metrics_mutex = Mutex.new
|
|
@@ -56,6 +67,19 @@ module MistralTranslator
|
|
|
56
67
|
@api_url = url
|
|
57
68
|
end
|
|
58
69
|
|
|
70
|
+
def proxy=(value)
|
|
71
|
+
Proxy.validate!(value)
|
|
72
|
+
@proxy = value
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def open_timeout=(seconds)
|
|
76
|
+
@open_timeout = positive_seconds!(:open_timeout, seconds)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def read_timeout=(seconds)
|
|
80
|
+
@read_timeout = positive_seconds!(:read_timeout, seconds)
|
|
81
|
+
end
|
|
82
|
+
|
|
59
83
|
# Méthodes pour les callbacks
|
|
60
84
|
def trigger_translation_start(from_locale, to_locale, text_length)
|
|
61
85
|
@on_translation_start&.call(from_locale, to_locale, text_length, Time.now)
|
|
@@ -166,6 +190,12 @@ module MistralTranslator
|
|
|
166
190
|
|
|
167
191
|
private
|
|
168
192
|
|
|
193
|
+
def positive_seconds!(name, seconds)
|
|
194
|
+
return seconds if seconds.is_a?(Numeric) && seconds.real? && seconds.positive?
|
|
195
|
+
|
|
196
|
+
raise ConfigurationError, "#{name} must be a positive number of seconds, got: #{seconds.inspect}"
|
|
197
|
+
end
|
|
198
|
+
|
|
169
199
|
def validate_api_url(url)
|
|
170
200
|
uri = parse_uri(url)
|
|
171
201
|
validate_uri_scheme(uri, url)
|