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.
@@ -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
- attr_accessor :api_key, :model, :default_max_tokens, :default_temperature, :retry_delays,
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, :ssl_timeout
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
- @ssl_timeout = 60 # SSL handshake timeout in seconds
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)