Skip to content

Commit

Permalink
Fix retries
Browse files Browse the repository at this point in the history
  • Loading branch information
markedmondson committed Dec 14, 2024
1 parent 1c24501 commit debc937
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/i18n/tasks/translators/openai_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def translate_batch(batch, from, to, retry_count = 0)

if result.size != batch.size
if retry_count < RETRIES
translate_batch(batch, from, to, retry_count)
result = translate_batch(batch, from, to, retry_count + 1)
elsif retry_count == RETRIES
# Try each string individually
batch.each do |string|
translate_batch([string], from, to, RETRIES + 1)
end
# Try each string individually once
result = batch.each_with_object([]) do |string, array|
array << translate_batch([string], from, to, RETRIES + 1)
end.flatten
else
error = I18n.t('i18n_tasks.openai_translate.errors.invalid_size', expected: batch.size, actual: result.size)
fail ::I18n::Tasks::CommandError, error
Expand All @@ -113,7 +113,7 @@ def translate_batch(batch, from, to, retry_count = 0)
result
rescue JSON::ParserError
if retry_count < RETRIES
translate_batch([string], from, to, retry_count + 1)
translate_batch(batch, from, to, retry_count + 1)
else
raise ::I18n::Tasks::CommandError, I18n.t('i18n_tasks.openai_translate.errors.invalid_json')
end
Expand Down

0 comments on commit debc937

Please sign in to comment.