WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.35k stars 970 forks source link

OpenAI MachineTranslationError: Could not parse assistant reply #11806

Open erikhugintech opened 4 weeks ago

erikhugintech commented 4 weeks ago

Describe the issue

When attempting to OpenAI translate an entire component, I get "MachineTranslationError: Could not parse assistant reply".

A sample log:

celery-translate stderr | [2024-06-07 10:19:28,345: ERROR/ForkPoolWorker-31] stasism-applications/dodge-dare/pt_PT: failed automatic translation: Could not parse assistant reply
celery-translate stderr | [2024-06-07 10:19:28,345: ERROR/11392] stasism-applications/dodge-dare/pt_PT: failed automatic translation: Could not parse assistant reply
celery-translate stderr | [2024-06-07 10:19:28,344: ERROR/ForkPoolWorker-31] Could not fetch translations from OpenAI
celery-translate stderr | [2024-06-07 10:19:28,344: ERROR/11392] Could not fetch translations from OpenAI
celery-translate stderr | [2024-06-07 10:19:28,343: WARNING/ForkPoolWorker-31] Machinery error: MachineTranslationError: Could not parse assistant reply
celery-translate stderr | [2024-06-07 10:19:28,343: WARNING/11392] Machinery error: MachineTranslationError: Could not parse assistant reply
celery-translate stderr | Sair
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | Bem Jogado!
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | Quantos golpes precisas levar antes de perder
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | [2024-06-07 10:19:28,343: WARNING/ForkPoolWorker-31] Failed to parse assistant reply: Vidas Iniciais
celery-translate stderr | Sair
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | Bem Jogado!
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | Quantos golpes precisas levar antes de perder
celery-translate stderr | ==WEBLATE_PART==
celery-translate stderr | [2024-06-07 10:19:28,343: WARNING/11392] Failed to parse assistant reply: Vidas Iniciais

I already tried

Steps to reproduce the behavior

  1. Go to Product/Component/Portuguese (Brazil)
  2. Select Tools/Automatic Translation
  3. Mode: Add as translation
  4. Search filter: Untranslated Strings
  5. Source: Machine Translation
  6. OpenAI (preconfigured and working fine for most languages/components)
  7. Click Apply

Expected behavior

Screenshots

No response

Exception traceback

No response

How do you run Weblate?

Docker container

Weblate versions

Weblate deploy checks

SystemCheckError: System check identified some issues:

CRITICALS:
?: (weblate.E003) Cannot send e-mail (timed out), please check EMAIL_* settings.
        HINT: https://docs.weblate.org/en/weblate-5.5.5/admin/install.html#out-mail

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-5.5.5/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
        HINT: https://docs.weblate.org/en/weblate-5.5.5/admin/backup.html

Additional context

The translated parts in the log seem to correspond to the final strings in the JSON file used as a source:

    "DODGEDARE_SCENARIOSCOMPLETEDTEXT": "You completed:",
    "DODGEDARE_STARTINGLIVES_TEXT": "Starting Lives",
    "DODGEDARE_STARTINGLIVES_TEXTTOOLTIP": "How many times you need to be hit before you lose",
    "DODGEDARE_WELLDONETEXT": "Well Done!",
    "HT_EXIT": "Exit"
}
nijel commented 3 weeks ago

Weblate does this to translate more strings at once. It appears that OpenAI omitted some strings from the response.

erikhugintech commented 3 weeks ago

@nijel Is it possible to discard the problematic translations, but keep the rest? Currently, one such error in my 600 string initial automated translation prevents the remaining correctly translated strings from being saved.

nijel commented 3 weeks ago

Yes, b4d31853d2748dcb58813037163fb56219a57e64 will do that.

nijel commented 2 weeks ago

In the long term, it might be better to use JSON mode instead of this simple joining of strings. Example can be found at https://medium.com/@sean37gl/how-to-leverage-chatgpts-new-json-mode-to-build-better-user-experiences-db8f6963f608