33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
# SPDX-FileCopyrightText: 2026 Art Sea LLC
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Protocol, runtime_checkable
|
|
|
|
from band_aider.ai_client.llm_context_batch import LLMContextBatch
|
|
from band_aider.ai_client.llm_context_reduction import LLMContextReduction
|
|
from band_aider.ai_client.token_budget_estimator import TokenBudgetEstimator
|
|
|
|
|
|
@runtime_checkable
|
|
class LLMContextReducer(Protocol):
|
|
"""LLMContextReducer splits oversized prompts and builds recurrent batch prompts."""
|
|
|
|
def can_reduce(self, prompt: str) -> bool:
|
|
"""Return whether this reducer can safely split the prompt."""
|
|
|
|
def split(self, prompt: str, token_budget: int, estimator: TokenBudgetEstimator) -> list[LLMContextBatch]:
|
|
"""Split an oversized prompt into bounded batches."""
|
|
|
|
def prompt_for_batch(
|
|
self,
|
|
original_prompt: str,
|
|
batch: LLMContextBatch,
|
|
previous_result: str,
|
|
) -> str:
|
|
"""Return the prompt to send for one recurrent batch."""
|
|
|
|
def final_result(self, reductions: list[LLMContextReduction]) -> str:
|
|
"""Return the final result string from completed reductions."""
|