lang_tools.llm
¶
LLM service layer built on llm-core's StructuredLLMChain.
Each module exposes a typed input model, a typed output model, and a
build_*_chain(chat_config, base_prompt_fol=...) factory that loads the
versioned Jinja prompt and wires everything into a StructuredLLMChain.
Public API
TranslationInput, TranslationOutput, build_translation_chain ConversationInput, ConversationOutput, ConversationTurn, build_conversation_chain TutorInput, TutorOutput, CorrectionBlock, ConversationBlock, ErrorDetail, build_tutor_chain TopicSuggestionInput, TopicSuggestionOutput, build_topic_suggestion_chain SplitterInput, SplitterOutput, build_paragraph_splitter_chain GreetingInput, GreetingOutput, build_greeting_chain WordGeneratorInput, WordGeneratorOutput, GeneratedWord, build_word_generator_chain
Modules:
-
conversation–ConversationGeneratorChain: generate a multi-turn bilingual dialogue.
-
greeting–GreetingGeneratorChain: open a conversational tutor session.
-
splitter–ParagraphSplitterChain: split text into reconstruction-friendly portions.
-
topics–TopicSuggestionChain: generate practice topics for a language.
-
translation–TranslationChain: translate text between any two supported languages.
-
tutor–TutorResponseChain: produce a correction + conversation continuation.
-
word_generator–WordGeneratorChain: generate themed vocabulary on demand.
Classes:
-
ConversationBlock–Tutor's conversation continuation.
-
ConversationInput–Inputs to
ConversationGeneratorChain. -
ConversationOutput–Outputs from
ConversationGeneratorChain. -
ConversationTurn–One turn in a generated conversation.
-
CorrectionBlock–Tutor's correction block.
-
ErrorDetail–Structured grammar / vocabulary error.
-
GeneratedWord–One LLM-generated vocabulary item.
-
GreetingInput–Inputs to
GreetingGeneratorChain. -
GreetingOutput–Outputs from
GreetingGeneratorChain. -
SplitterInput–Inputs to
ParagraphSplitterChain. -
SplitterOutput–Outputs from
ParagraphSplitterChain. -
TopicSuggestionInput–Inputs to
TopicSuggestionChain. -
TopicSuggestionOutput–Outputs from
TopicSuggestionChain. -
TranslationInput–Inputs to
TranslationChain. -
TranslationOutput–Outputs from
TranslationChain. -
TutorInput–Inputs to
TutorResponseChain. -
TutorOutput–Outputs from
TutorResponseChain. -
WordGeneratorInput–Inputs to
WordGeneratorChain. -
WordGeneratorOutput–Outputs from
WordGeneratorChain.
Functions:
-
build_conversation_chain–Build a conversation generator chain wired to
chat_config. -
build_greeting_chain–Build a greeting generator chain wired to
chat_config. -
build_paragraph_splitter_chain–Build a paragraph splitter chain wired to
chat_config. -
build_topic_suggestion_chain–Build a topic suggestion chain wired to
chat_config. -
build_translation_chain–Build a translation chain wired to
chat_config. -
build_tutor_chain–Build a tutor response chain wired to
chat_config. -
build_word_generator_chain–Build a word generator chain wired to
chat_config.
ConversationBlock
¶
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:
-
turns(list[ConversationTurn]) –Generated dialogue turns.
ConversationTurn
¶
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
¶
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.
GreetingInput
¶
GreetingOutput
¶
SplitterInput
¶
SplitterOutput
¶
TopicSuggestionInput
¶
TopicSuggestionOutput
¶
TranslationInput
¶
TranslationOutput
¶
Bases: BaseModel
Outputs from TranslationChain.
Attributes:
-
translated_text(str) –The translated string.
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:
-
correction(CorrectionBlock) –Correction block (may be empty when no errors).
-
conversation(ConversationBlock) –Conversation continuation block.
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:
-
words(list[GeneratedWord]) –Generated vocabulary list.
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
build_greeting_chain
¶
build_greeting_chain(
chat_config: ChatConfig,
*,
base_prompt_fol: Path | None = None,
version: str = "auto",
) -> StructuredLLMChain[GreetingInput, GreetingOutput]
Build a greeting generator chain wired to chat_config.
Source code in src/lang_tools/llm/greeting.py
build_paragraph_splitter_chain
¶
build_paragraph_splitter_chain(
chat_config: ChatConfig,
*,
base_prompt_fol: Path | None = None,
version: str = "auto",
) -> StructuredLLMChain[SplitterInput, SplitterOutput]
Build a paragraph splitter chain wired to chat_config.
Source code in src/lang_tools/llm/splitter.py
build_topic_suggestion_chain
¶
build_topic_suggestion_chain(
chat_config: ChatConfig,
*,
base_prompt_fol: Path | None = None,
version: str = "auto",
) -> StructuredLLMChain[
TopicSuggestionInput, TopicSuggestionOutput
]
Build a topic suggestion chain wired to chat_config.
Source code in src/lang_tools/llm/topics.py
build_translation_chain
¶
build_translation_chain(
chat_config: ChatConfig,
*,
base_prompt_fol: Path | None = None,
version: str = "auto",
) -> StructuredLLMChain[
TranslationInput, TranslationOutput
]
Build a translation chain wired to chat_config.
Parameters:
-
chat_config(ChatConfig) –llm-coreChatConfig(e.g.ChatOpenAIConfig). -
base_prompt_fol(Path | None, default:None) –Override prompts root; defaults to in-package folder.
-
version(str, default:'auto') –Prompt version (
"1"or"auto").
Returns:
-
StructuredLLMChain[TranslationInput, TranslationOutput]–StructuredLLMChainready toinvoke/ainvoke.
Source code in src/lang_tools/llm/translation.py
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
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.