Skip to content

Refactor TranslationConfig to embed ModelConfig per chatbot role #141

Description

@MaleicAcid

Refactor TranslationConfig to embed ModelConfig per chatbot role

Motivation

LeanTranslator (PRs #132#139) introduced three independent chatbot roles: primary translator, retry fallback, and Context Review. Each may need a different endpoint, proxy, and extra_body (e.g. disabling Qwen3.6 thinking mode). The current flat design shares base_url_config, proxy across all roles and has no way to pass extra_body from config files at all.

Proposal

Make ModelConfig serialization-friendly, then embed it directly in TranslationConfig.

Convert ModelProvider from Enum to StrEnum so ModelConfig becomes JSON/YAML-native. For Python 3.10 compatibility, use str, Enum multiple inheritance with a __str__ override (verified on 3.10–3.13):

import sys
if sys.version_info >= (3, 11):
    from enum import StrEnum as _StrEnum
else:
    from enum import Enum
    class _StrEnum(str, Enum):
        def __str__(self) -> str:
            return self.value

class ModelProvider(_StrEnum):
    OPENAI = "openai"
    ANTHROPIC = "anthropic"
    GEMINI = "gemini"

ModelConfig.provider typed as ModelProvider | str to allow custom providers (e.g. "litellm") without modifying the enum.

Refactored TranslationConfig:

@dataclass
class TranslationConfig:
    chatbot: ModelConfig | None = None
    retry_chatbot: ModelConfig | None = None
    cr_chatbot: ModelConfig | None = None
    translate_mode: str = "standard"
    enable_cr: bool = True
    chunked_guideline: bool = False
    fee_limit: float = 0.8
    consumer_thread: int = 4
    glossary: str | None = None
    is_force_glossary_used: bool = False

Removed fields: chatbot_model, base_url_config, proxy, retry_model, cr_model — all replaced by per-role ModelConfig with base_url, proxy, extra_body.

Side benefit: provider2chatbot dict becomes dict[str, type[ChatBot]], enabling custom provider registration (provider2chatbot["litellm"] = LiteLLMBot).

Backward compatibility

This is a breaking change. The LeanTranslator fields (translate_mode, cr_model, enable_cr, chunked_guideline) have not been in any PyPI release. The older fields (chatbot_model, base_url_config, retry_model) require mechanical migration. Carrying deprecated fields alongside new ones adds significant __post_init__ complexity for marginal benefit.

Propose releasing as 1.7.0 with a migration guide in the changelog.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions