ruby_llm-agents 3.15.0 → 3.15.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 +4 -4
- data/lib/ruby_llm/agents/audio/transcriber.rb +7 -121
- data/lib/ruby_llm/agents/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 50ffc9d68f60773bb6d86c42addae6911999d703eadd295bd30b5e4fcc5858f6
|
|
4
|
+
data.tar.gz: b6c40aa4a3f1ef6ac52e4d2beeb27871038a48d8c80ba71b37dcbd43f21394de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3f02b1ff28adcb9b102acdcbed8e31470130c1763470af992a501750681ae0c9ebe86b3a2bf5152dcd40216b7f3fe2298c5d1959e54957dba947084d14317a9
|
|
7
|
+
data.tar.gz: 8f8c8a9942c6123a92d0e9f0a2f7424fd2d655ca27689cf58faf7358ce2964fca9f4d155527990392f22b89d2127b7c54c90bb43e11c41f695c87baaedb12550
|
|
@@ -117,37 +117,10 @@ module RubyLLM
|
|
|
117
117
|
|
|
118
118
|
# @!endgroup
|
|
119
119
|
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
-
# @yield Block for configuring reliability options
|
|
125
|
-
# @return [ReliabilityConfig] The reliability configuration
|
|
126
|
-
def reliability(&block)
|
|
127
|
-
@reliability_config ||= ReliabilityConfig.new
|
|
128
|
-
@reliability_config.instance_eval(&block) if block_given?
|
|
129
|
-
@reliability_config
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Returns reliability configuration
|
|
133
|
-
#
|
|
134
|
-
# @return [ReliabilityConfig, nil] The reliability configuration
|
|
135
|
-
def reliability_config
|
|
136
|
-
@reliability_config || inherited_or_default(:reliability_config, nil)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
# Sets fallback models directly (shorthand for reliability block)
|
|
140
|
-
#
|
|
141
|
-
# @param models [Array<String>] Model identifiers to try on failure
|
|
142
|
-
# @return [Array<String>] The fallback models
|
|
143
|
-
def fallback_models(*models)
|
|
144
|
-
if models.any?
|
|
145
|
-
@fallback_models = models.flatten
|
|
146
|
-
end
|
|
147
|
-
@fallback_models || inherited_or_default(:fallback_models, [])
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# @!endgroup
|
|
120
|
+
# Reliability (retries, fallbacks, circuit breakers) comes from the
|
|
121
|
+
# shared DSL::Reliability on BaseAgent and is executed by the
|
|
122
|
+
# Reliability middleware — the middleware expects the Hash config that
|
|
123
|
+
# DSL produces, so Transcriber must not shadow it with its own object.
|
|
151
124
|
|
|
152
125
|
# Factory method to instantiate and execute transcription
|
|
153
126
|
#
|
|
@@ -197,40 +170,6 @@ module RubyLLM
|
|
|
197
170
|
end
|
|
198
171
|
end
|
|
199
172
|
|
|
200
|
-
# Configuration class for reliability options
|
|
201
|
-
class ReliabilityConfig
|
|
202
|
-
attr_accessor :max_retries, :backoff, :fallback_models_list, :total_timeout_seconds
|
|
203
|
-
|
|
204
|
-
def initialize
|
|
205
|
-
@max_retries = 3
|
|
206
|
-
@backoff = :exponential
|
|
207
|
-
@fallback_models_list = []
|
|
208
|
-
@total_timeout_seconds = nil
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def retries(max: 3, backoff: :exponential)
|
|
212
|
-
@max_retries = max
|
|
213
|
-
@backoff = backoff
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def fallback_models(*models)
|
|
217
|
-
@fallback_models_list = models.flatten
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def total_timeout(seconds)
|
|
221
|
-
@total_timeout_seconds = seconds
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
def to_h
|
|
225
|
-
{
|
|
226
|
-
max_retries: max_retries,
|
|
227
|
-
backoff: backoff,
|
|
228
|
-
fallback_models: fallback_models_list,
|
|
229
|
-
total_timeout: total_timeout_seconds
|
|
230
|
-
}
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
173
|
# @!attribute [r] audio
|
|
235
174
|
# @return [String, File, IO] Audio input
|
|
236
175
|
# @!attribute [r] audio_format
|
|
@@ -308,8 +247,9 @@ module RubyLLM
|
|
|
308
247
|
audio_input = normalize_audio_input(@audio, @audio_format)
|
|
309
248
|
validate_audio_input!(audio_input)
|
|
310
249
|
|
|
311
|
-
#
|
|
312
|
-
|
|
250
|
+
# context.model is set per-attempt by the Reliability middleware, so
|
|
251
|
+
# fallback models actually take effect here
|
|
252
|
+
raw_result = execute_transcription(audio_input, context.model || resolved_model)
|
|
313
253
|
|
|
314
254
|
execution_completed_at = Time.current
|
|
315
255
|
duration_ms = ((execution_completed_at - execution_started_at) * 1000).to_i
|
|
@@ -455,37 +395,6 @@ module RubyLLM
|
|
|
455
395
|
end
|
|
456
396
|
end
|
|
457
397
|
|
|
458
|
-
# Executes transcription with reliability features
|
|
459
|
-
#
|
|
460
|
-
# @param audio_input [Hash] Normalized audio input
|
|
461
|
-
# @return [Hash] Raw transcription result
|
|
462
|
-
def execute_with_reliability(audio_input)
|
|
463
|
-
models_to_try = [resolved_model] + self.class.fallback_models
|
|
464
|
-
last_error = nil
|
|
465
|
-
|
|
466
|
-
models_to_try.each do |model|
|
|
467
|
-
retries = 0
|
|
468
|
-
max_retries = reliability_max_retries
|
|
469
|
-
|
|
470
|
-
begin
|
|
471
|
-
return execute_transcription(audio_input, model)
|
|
472
|
-
rescue => e
|
|
473
|
-
last_error = e
|
|
474
|
-
retries += 1
|
|
475
|
-
|
|
476
|
-
if retryable_error?(e) && retries < max_retries
|
|
477
|
-
sleep(calculate_backoff(retries))
|
|
478
|
-
retry
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
# Try next model
|
|
482
|
-
next
|
|
483
|
-
end
|
|
484
|
-
end
|
|
485
|
-
|
|
486
|
-
raise last_error || StandardError.new("All transcription models exhausted")
|
|
487
|
-
end
|
|
488
|
-
|
|
489
398
|
# Executes the actual transcription API call
|
|
490
399
|
#
|
|
491
400
|
# @param audio_input [Hash] Normalized audio input
|
|
@@ -663,29 +572,6 @@ module RubyLLM
|
|
|
663
572
|
def resolved_language
|
|
664
573
|
@runtime_language || self.class.language
|
|
665
574
|
end
|
|
666
|
-
|
|
667
|
-
# Returns max retries from reliability config
|
|
668
|
-
def reliability_max_retries
|
|
669
|
-
config = self.class.reliability_config
|
|
670
|
-
config&.max_retries || 3
|
|
671
|
-
end
|
|
672
|
-
|
|
673
|
-
# Checks if error is retryable
|
|
674
|
-
def retryable_error?(error)
|
|
675
|
-
message = error.message.to_s.downcase
|
|
676
|
-
retryable_patterns = ["rate limit", "timeout", "503", "502", "429", "overloaded"]
|
|
677
|
-
retryable_patterns.any? { |pattern| message.include?(pattern) }
|
|
678
|
-
end
|
|
679
|
-
|
|
680
|
-
# Calculates exponential backoff delay
|
|
681
|
-
def calculate_backoff(attempt)
|
|
682
|
-
config = self.class.reliability_config
|
|
683
|
-
base = (config&.backoff == :constant) ? 1.0 : 0.4
|
|
684
|
-
max_delay = 10.0
|
|
685
|
-
|
|
686
|
-
delay = base * (2**(attempt - 1))
|
|
687
|
-
[delay, max_delay].min
|
|
688
|
-
end
|
|
689
575
|
end
|
|
690
576
|
end
|
|
691
577
|
end
|