Skip to content

lang_tools.llm.tutor

TutorResponseChain: produce a correction + conversation continuation.

Classes:

Functions:

ConversationBlock

Bases: BaseModel

Tutor's conversation continuation.

Attributes:

  • content (str) –

    Continuation text in the target language.

  • translation (str) –

    Translation of the continuation.

CorrectionBlock

Bases: BaseModel

Tutor's correction block.

Attributes:

  • content (str) –

    Correction text in the target language.

  • translation (str) –

    Translation of the correction text.

  • errors (list[ErrorDetail]) –

    Structured list of individual errors.

ErrorDetail

Bases: BaseModel

Structured grammar / vocabulary error.

Attributes:

  • original (str) –

    The user's wording.

  • corrected (str) –

    The corrected wording.

  • explanation (str) –

    Brief grammar / vocab note.

TutorInput

Bases: BaseModelKwargs

Inputs to TutorResponseChain.

Attributes:

  • topic (str) –

    Conversation topic.

  • language (str) –

    ISO 639-1 target language code.

  • user_message (str) –

    Latest user message.

  • history (list[TutorMessage]) –

    Prior TutorMessages.

  • difficulty_level (str) –

    "beginner" / "intermediate" / "advanced".

TutorOutput

Bases: BaseModel

Outputs from TutorResponseChain.

Attributes:

build_tutor_chain

build_tutor_chain(
    chat_config: ChatConfig,
    *,
    base_prompt_fol: Path | None = None,
    version: str = "auto",
) -> StructuredLLMChain[TutorInput, TutorOutput]

Build a tutor response chain wired to chat_config.

Source code in src/lang_tools/llm/tutor.py
def build_tutor_chain(
    chat_config: ChatConfig,
    *,
    base_prompt_fol: Path | None = None,
    version: str = "auto",
) -> StructuredLLMChain[TutorInput, TutorOutput]:
    """Build a tutor response chain wired to `chat_config`."""
    return StructuredLLMChain(
        chat_config=chat_config,
        prompt_str=load_prompt(
            "tutor_response",
            base_prompt_fol=base_prompt_fol,
            version=version,
        ),
        input_model=TutorInput,
        output_model=TutorOutput,
    )