💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Fix translation chunk concatenation when showmodels is enabled (#1052)
JiangNan79908eee5a4c
diff --git a/src/python/txtai/pipeline/text/translation.py b/src/python/txtai/pipeline/text/translation.pyindex 17dd1b51..cf00d7f3 100644--- a/src/python/txtai/pipeline/text/translation.py+++ b/src/python/txtai/pipeline/text/translation.py@@ -202,11 +202,15 @@ class Translation(HFModel):# Combine translations - handle splits on large text from tokenizerresults, last = [], -1for x, i in enumerate(indices):- v = (path, translated[x]) if showmodels else translated[x]if i == last:- results[-1] += v+ if showmodels:+ # Concatenate text portion of (path, text) tuple+ prev = results[-1]+ results[-1] = (prev[0], prev[1] + translated[x])+ else:+ results[-1] += translated[x]else:- results.append(v)+ results.append((path, translated[x]) if showmodels else translated[x])last = idiff --git a/test/python/testpipeline/testtext/testtranslation.py b/test/python/testpipeline/testtext/testtranslation.pyindex a383d968..e42b69f4 100644--- a/test/python/testpipeline/testtext/testtranslation.py+++ b/test/python/testpipeline/testtext/testtranslation.py@@ -122,6 +122,31 @@ class TestTranslation(unittest.TestCase):# Validate no translationself.assertEqual(text, translation)+ def testShowmodelsChunked(self):+ """+ Test a long translation with showmodels flag. When text is chunked+ by the tokenizer, results should still be properly concatenated as+ a 3-tuple (translation, language, model) rather than a malformed tuple.+ """++ text = "This is a test translation to Spanish. " * 100+ result = self.translate(text, "es", showmodels=True)++ # Result should be a tuple of exactly 3 elements+ self.assertIsInstance(result, tuple)+ self.assertEqual(len(result), 3)++ translation, language, modelpath = result++ # Translation should be a single string, not a nested tuple+ self.assertIsInstance(translation, str)+ self.assertIsNotNone(translation)+ self.assertGreater(len(translation), 0)++ # Language and model should be valid strings+ self.assertEqual(language, "en")+ self.assertIsInstance(modelpath, str)+def testTranslationWithShowmodels(self):"""Test a translation using Marian models and showmodels flag to return