Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Mar 11, 2025

Requires: #248

We are seeing a lot of

Failed to machine-translate Post#1708161 to it: <html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>

Timeouts may happen when we send large chunks over to our LLM for translation. Timeouts may also happen in two ways:

  1. Site user presses 🌐 to translate a post manually (controller API); or
  2. We send old posts for backfilling (job).

This PR solves (2). (1) will be handled in a different PR. We will loosely split content up into chunks. Example post raw is meta's /t/354449.

@nattsw nattsw force-pushed the split-raw-before-translate branch from 7580b96 to 32fae6d Compare March 11, 2025 08:14
text = text_for_translation(translatable)
chunks = DiscourseTranslator::ContentSplitter.split(text)
chunks
.map { |chunk| ::DiscourseAi::Translator.new(chunk, target_locale_sym).translate }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you considered it but I'm wondering if we should translate chunks in parallel.

Copy link
Contributor Author

@nattsw nattsw Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did ... 🤔 but we may hit rate limits

@nattsw
Copy link
Contributor Author

nattsw commented Mar 11, 2025

I'll add some limits to the splitter.

@xfalcox xfalcox force-pushed the split-raw-before-translate branch from bb3d1f3 to d9a0322 Compare March 25, 2025 14:06
@xfalcox xfalcox merged commit 23b83fb into main Mar 25, 2025
6 checks passed
@xfalcox xfalcox deleted the split-raw-before-translate branch March 25, 2025 18:21
nattsw added a commit to discourse/discourse-ai that referenced this pull request Jun 23, 2025
In discourse/discourse-translator#249 we introduced splitting content (post.raw) prior to sending to translation as we were using a sync api.

Now that we're streaming thanks to #1424, we'll chunk based on the LlmModel.max_output_tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants