"""Unified async entry points for section generation LLM calls. Callers in async handlers should use these helpers instead of branching on ``enable_async_pipeline`` at every call site. """ from __future__ import annotations from typing import TYPE_CHECKING from app.async_executor import run_sync_in_executor from app.config import settings from app.generator.adapter import get_llm_adapter from app.llm.async_llm_adapter import get_async_llm_adapter if TYPE_CHECKING: from app.models.schemas import WritingStyleProfile async def generate_section( *, skeleton: str, bullets: list[str], snippets: list[str], style_profile: "WritingStyleProfile | None" = None, temperature: float = 0.2, creativity_hint: str = "", document_context: list[str] | None = None, style_anchor: str | None = None, hierarchy_section_snippets: list[str] | None = None, paragraph_snippets: list[str] | None = None, identity_facts: str | None = None, survey_level: int | None = None, reference_only_context: bool = False, ai_percent: int | None = None, interference_level: str | None = None, tenant_id: str | None = None, ) -> str: if settings.enable_async_pipeline: return await get_async_llm_adapter().generate_section( skeleton=skeleton, bullets=bullets, snippets=snippets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, document_context=document_context, style_anchor=style_anchor, hierarchy_section_snippets=hierarchy_section_snippets, paragraph_snippets=paragraph_snippets, identity_facts=identity_facts, survey_level=survey_level, reference_only_context=reference_only_context, ai_percent=ai_percent, interference_level=interference_level, tenant_id=tenant_id, ) return await run_sync_in_executor( get_llm_adapter().generate_section, skeleton=skeleton, bullets=bullets, snippets=snippets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, document_context=document_context, style_anchor=style_anchor, hierarchy_section_snippets=hierarchy_section_snippets, paragraph_snippets=paragraph_snippets, identity_facts=identity_facts, survey_level=survey_level, reference_only_context=reference_only_context, ai_percent=ai_percent, interference_level=interference_level, tenant_id=tenant_id, ) async def proofread( *, text: str, bullets: list[str], style_profile: "WritingStyleProfile | None" = None, temperature: float = 0.15, creativity_hint: str = "", ) -> str: if settings.enable_async_pipeline: return await get_async_llm_adapter().proofread( text=text, bullets=bullets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, ) return await run_sync_in_executor( get_llm_adapter().proofread, text=text, bullets=bullets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, ) async def enhance( *, text: str, bullets: list[str], snippets: list[str], style_profile: "WritingStyleProfile | None" = None, temperature: float = 0.2, creativity_hint: str = "", ) -> str: if settings.enable_async_pipeline: return await get_async_llm_adapter().enhance( text=text, bullets=bullets, snippets=snippets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, ) return await run_sync_in_executor( get_llm_adapter().enhance, text=text, bullets=bullets, snippets=snippets, style_profile=style_profile, temperature=temperature, creativity_hint=creativity_hint, ) async def validate_section_compliance( *, survey_level: int | None, section_code: str, bullets: list[str], evidence_snippets: list[str], text: str, ) -> str: if settings.enable_async_pipeline: return await get_async_llm_adapter().validate_section_compliance( survey_level=survey_level, section_code=section_code, bullets=bullets, evidence_snippets=evidence_snippets, text=text, ) return await run_sync_in_executor( get_llm_adapter().validate_section_compliance, survey_level=survey_level, section_code=section_code, bullets=bullets, evidence_snippets=evidence_snippets, text=text, ) async def constrained_weave( *, section_code: str, section_title: str | None, bullets: list[str], standard_passages: list[str], survey_level: int | None = None, tenant_id: str | None = None, ) -> str: if settings.enable_async_pipeline: return await get_async_llm_adapter().constrained_weave( section_code=section_code, section_title=section_title, bullets=bullets, standard_passages=standard_passages, survey_level=survey_level, tenant_id=tenant_id, ) return await run_sync_in_executor( get_llm_adapter().constrained_weave, section_code=section_code, section_title=section_title, bullets=bullets, standard_passages=standard_passages, survey_level=survey_level, tenant_id=tenant_id, )