Skip to content

lang_tools.llm.word_generator

WordGeneratorChain: generate themed vocabulary on demand.

Classes:

Functions:

GeneratedWord

Bases: BaseModel

One LLM-generated vocabulary item.

Attributes:

  • text (str) –

    The word in the target language.

  • translation (str) –

    English translation.

  • part_of_speech (str) –

    Word class label.

  • example_sentence (str) –

    Example sentence in the target language.

  • example_translation (str) –

    English translation of the example sentence.

WordGeneratorInput

Bases: BaseModelKwargs

Inputs to WordGeneratorChain.

Attributes:

  • language (str) –

    ISO 639-1 target language code.

  • topic (str) –

    Theme to draw vocabulary from.

  • num_words (int) –

    How many words to produce.

  • difficulty (str) –

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

  • require_accents (bool) –

    If True, only return words containing accented chars.

WordGeneratorOutput

Bases: BaseModel

Outputs from WordGeneratorChain.

Attributes:

build_word_generator_chain

build_word_generator_chain(
    chat_config: ChatConfig,
    *,
    base_prompt_fol: Path | None = None,
    version: str = "auto",
) -> StructuredLLMChain[
    WordGeneratorInput, WordGeneratorOutput
]

Build a word generator chain wired to chat_config.

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