helpers
helpers
¶
LLM helper utilities — sanitization, truncation, and factory.
truncate_legislative_text(text, verbatim_chars=LLM_VERBATIM_CHARS, max_chars=LLM_MAX_TEXT_CHARS)
¶
Truncate Czech legislative text via structural extraction for LLM processing.
When TISK_SHORTENER is disabled (0), returns the full text unmodified.
Strategy (when enabled and text exceeds max_chars):
1. First verbatim_chars kept verbatim (covers explanatory report + most content)
2. From remainder: extract section headings + first 500 chars of each section
3. Hard cap at max_chars total
Source code in pspcz_analyzer/services/llm/helpers.py
create_llm_client()
¶
Factory: return the configured LLM backend client.
Reads LLM_PROVIDER from config: - "ollama" (default) -> LLMClient(provider="ollama", ...) - "openai" -> LLMClient(provider="openai", ...) (fails fast if OPENAI_API_KEY is empty)
Raises ValueError for unknown provider.