Skip to content

Commit

Permalink
Fix retries
Browse files Browse the repository at this point in the history
  • Loading branch information
markedmondson committed Nov 7, 2024
1 parent ea8a72f commit 0fdd55f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/i18n/tasks/translators/openai_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,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)
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)
# Try each string individually once
result = []
batch.map do |string|
result << translate_batch([string], from, to, RETRIES + 1)
end
else
error = I18n.t('i18n_tasks.openai_translate.errors.invalid_size', expected: batch.size, actual: result.size)
Expand Down

0 comments on commit 0fdd55f

Please sign in to comment.