From 9568d12f681bb7e2081c244e7f0b97b93ddc34ec Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 29 Apr 2026 11:04:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20improve=20legacy?= =?UTF-8?q?=20AI=20translate=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The return of the legacy AI translate prompt is sometimes surrounded with a html code block. We improve the prompt to not return this surrounding code block. --- src/backend/core/services/ai_services/legacy.py | 3 ++- .../documents/test_api_documents_ai_translate.py | 12 +++++++++--- .../external_api/test_external_api_documents_ai.py | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/backend/core/services/ai_services/legacy.py b/src/backend/core/services/ai_services/legacy.py index 9855ee73a..c6c4dd912 100644 --- a/src/backend/core/services/ai_services/legacy.py +++ b/src/backend/core/services/ai_services/legacy.py @@ -61,7 +61,8 @@ AI_TRANSLATE = ( "Keep the same html structure and formatting. " "Translate the content in the html to the specified language {language:s}. " "Check the translation for accuracy and make any necessary corrections. " - "Do not provide any other information." + "Do not provide any other information. " + "Return the content directly without wrapping it in code blocks or markdown delimiters." ) diff --git a/src/backend/core/tests/documents/test_api_documents_ai_translate.py b/src/backend/core/tests/documents/test_api_documents_ai_translate.py index 1954cbc47..290f87825 100644 --- a/src/backend/core/tests/documents/test_api_documents_ai_translate.py +++ b/src/backend/core/tests/documents/test_api_documents_ai_translate.py @@ -117,7 +117,9 @@ def test_api_documents_ai_translate_anonymous_success(mock_create, settings): "Keep the same html structure and formatting. " "Translate the content in the html to the specified language Spanish. " "Check the translation for accuracy and make any necessary corrections. " - "Do not provide any other information." + "Do not provide any other information. " + "Return the content directly without wrapping it in code blocks or markdown " + "delimiters." ), }, {"role": "user", "content": "Hello"}, @@ -219,7 +221,9 @@ def test_api_documents_ai_translate_authenticated_success(mock_create, reach, ro "Translate the content in the html to the " "specified language Colombian Spanish. " "Check the translation for accuracy and make any necessary corrections. " - "Do not provide any other information." + "Do not provide any other information. " + "Return the content directly without wrapping it in code blocks or markdown " + "delimiters." ), }, {"role": "user", "content": "Hello"}, @@ -296,7 +300,9 @@ def test_api_documents_ai_translate_success(mock_create, via, role, mock_user_te "Translate the content in the html to the " "specified language Colombian Spanish. " "Check the translation for accuracy and make any necessary corrections. " - "Do not provide any other information." + "Do not provide any other information. " + "Return the content directly without wrapping it in code blocks or markdown " + "delimiters." ), }, {"role": "user", "content": "Hello"}, diff --git a/src/backend/core/tests/external_api/test_external_api_documents_ai.py b/src/backend/core/tests/external_api/test_external_api_documents_ai.py index ee695958b..e645c4007 100644 --- a/src/backend/core/tests/external_api/test_external_api_documents_ai.py +++ b/src/backend/core/tests/external_api/test_external_api_documents_ai.py @@ -226,7 +226,9 @@ def test_external_api_documents_ai_translate_can_be_allowed( "Translate the content in the html to the " "specified language Colombian Spanish. " "Check the translation for accuracy and make any necessary corrections. " - "Do not provide any other information." + "Do not provide any other information. " + "Return the content directly without wrapping it in code blocks or markdown " + "delimiters." ), }, {"role": "user", "content": "Hello"},