Skip to content

llm_calls

llm_calls

Functions:

Name Description
estimate_llm_calls_by_stage

Estimate nominal model calls for one record, split by workflow stage.

estimate_llm_calls_by_stage(*, mode, strategy, has_grouped_entities, validation_chunk_count, repair_iterations=0, replace_map_generation_uses_llm=True)

Estimate nominal model calls for one record, split by workflow stage.

Source code in src/anonymizer/measurement/metrics/llm_calls.py
def estimate_llm_calls_by_stage(
    *,
    mode: str,
    strategy: str,
    has_grouped_entities: bool,
    validation_chunk_count: int | None,
    repair_iterations: int = 0,
    replace_map_generation_uses_llm: bool = True,
) -> dict[str, int | None]:
    """Estimate nominal model calls for one record, split by workflow stage."""
    detection_calls = None if validation_chunk_count is None else 2 + validation_chunk_count
    replace_map_generation = 0
    if replace_map_generation_uses_llm and has_grouped_entities and (mode == "rewrite" or strategy == "Substitute"):
        replace_map_generation = 1

    if mode != "rewrite":
        return {
            "entity_detection": detection_calls,
            "replace_map_generation": replace_map_generation,
        }

    rewrite_body_calls = has_grouped_entities
    return {
        "entity_detection": detection_calls,
        "latent_entity_detection": 1 if rewrite_body_calls else 0,
        "replace_map_generation": replace_map_generation,
        "rewrite_pipeline": 5 if rewrite_body_calls else 0,
        "rewrite_evaluate": 3 * (1 + repair_iterations) if rewrite_body_calls else 0,
        "rewrite_repair": repair_iterations if rewrite_body_calls else 0,
        "rewrite_final_judge": 0,
    }