Truncate text to fit within token limit.
(self, text: str, max_tokens: int = LLM_CONTEXT_LIMIT)
| 304 | return prompt | self.llm.with_structured_output(AnswerCheck) |
| 305 | |
| 306 | def _truncate_context(self, text: str, max_tokens: int = LLM_CONTEXT_LIMIT) -> str: |
| 307 | """Truncate text to fit within token limit.""" |
| 308 | tokens = self._tokenizer.encode(text) |
| 309 | if len(tokens) > max_tokens: |
| 310 | logger.warning(f"[GraphRAG] Context too long ({len(tokens)} tokens), truncating to {max_tokens}") |
| 311 | return self._tokenizer.decode(tokens[:max_tokens]) |
| 312 | return text |
| 313 | |
| 314 | def query(self, query: str) -> Tuple[str, str, List[int], Dict[int, str]]: |
| 315 | """Process a query and return answer with context.""" |
no test coverage detected