Skip to content

lang_tools.llm.conversation

ConversationGeneratorChain: generate a multi-turn bilingual dialogue.

Classes:

Functions:

ConversationInput

Bases: BaseModelKwargs

Inputs to ConversationGeneratorChain.

Attributes:

  • topic (str) –

    Topic prompt for the dialogue.

  • language (str) –

    ISO 639-1 code of the target language.

  • difficulty_level (str) –

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

  • num_turns (int) –

    How many turns the dialogue should contain.

  • max_sentences_per_turn (int) –

    Per-turn sentence cap.

  • sample_conversation (str | None) –

    Optional few-shot example to calibrate level.

ConversationOutput

Bases: BaseModel

Outputs from ConversationGeneratorChain.

Attributes:

ConversationTurn

Bases: BaseModel

One turn in a generated conversation.

Attributes:

  • role (Literal['user', 'system']) –

    "user" or "system".

  • content (str) –

    Target-language text.

  • translation (str) –

    User-language translation.

build_conversation_chain

build_conversation_chain(
    chat_config: ChatConfig,
    *,
    base_prompt_fol: Path | None = None,
    version: str = "auto",
) -> StructuredLLMChain[
    ConversationInput, ConversationOutput
]

Build a conversation generator chain wired to chat_config.

Source code in src/lang_tools/llm/conversation.py
def build_conversation_chain(
    chat_config: ChatConfig,
    *,
    base_prompt_fol: Path | None = None,
    version: str = "auto",
) -> StructuredLLMChain[ConversationInput, ConversationOutput]:
    """Build a conversation generator chain wired to `chat_config`."""
    return StructuredLLMChain(
        chat_config=chat_config,
        prompt_str=load_prompt(
            "conversation_generator",
            base_prompt_fol=base_prompt_fol,
            version=version,
        ),
        input_model=ConversationInput,
        output_model=ConversationOutput,
    )