From aa83cfacbdba1fe15f484c09b2cb9e2b8df3e2fd Mon Sep 17 00:00:00 2001 From: ChemaVX Date: Wed, 6 May 2026 06:51:36 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20truncar=20contextos=20en=20/compare=20a?= =?UTF-8?q?=203000=20palabras=20para=20evitar=20l=C3=ADmite=20de=20tokens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/generator/generator.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/generator/generator.py b/src/generator/generator.py index d759b0a..5c3236a 100644 --- a/src/generator/generator.py +++ b/src/generator/generator.py @@ -670,6 +670,15 @@ async def generate_comparison( if not settings.anthropic_api_key: raise ValueError("Claude API key required for comparison") + def _truncate(text: str, max_words: int = 3000) -> str: + words = text.split() + if len(words) > max_words: + return " ".join(words[:max_words]) + "\n\n[... contenido adicional truncado ...]" + return text + + context_a = _truncate(context_a) + context_b = _truncate(context_b) + prompt = ( f'Eres un analista experto. Compara en profundidad estos dos temas:\n' f'TEMA A: "{topic_a}"\n'