mixle.task.llm module¶
A tiny provider-agnostic LLM surface – so a regular program can reach a small LM, and an LM can be a teacher.
mixle has no LLM client of its own; this is the minimal adapter. An LLM is anything with complete(prompt)
-> str. CallableLLM wraps a local function (a llama.cpp/transformers call, or a test double);
OpenAICompatLLM posts to any OpenAI-compatible /v1/chat/completions endpoint (Ollama, vLLM, TGI,
llama.cpp server, a hosted API) using only the standard library – no openai/requests dependency.
The point of having it here: llm_labeler() turns an LLM into the teacher the rest of mixle.task
distills from. teacher = llm_labeler(OpenAICompatLLM(...), ["spam", "ham"]) plugs a frontier model straight
into mixle.task.distill.distill() / mixle.task.active.active_distill() – the expensive LM labels a
little, the tiny local student serves the rest. The same adapter lets an LLM design a model (mixle.task.design).
- class LLM(*args, **kwargs)[source]
Bases:
ProtocolAnything that can turn a prompt into text. The whole contract the rest of the package depends on.
- class CallableLLM(fn)[source]
Bases:
objectWrap a plain
fn(prompt) -> str(orfn(prompt, system)) as anLLM– local models and tests.- Parameters:
fn (Callable[..., str])
- class OpenAICompatLLM(base_url, model, *, api_key=None, temperature=0.0, max_tokens=512, timeout=60.0)[source]
Bases:
objectAn
LLMbacked by any OpenAI-compatible/v1/chat/completionsendpoint (stdlib HTTP only).- Parameters:
- pick_label(text, labels)[source]
Map a free-text LLM reply to one of
labels(exact, then substring, else the first label).
- llm_labeler(llm, labels, *, instruction=None, system=None)[source]
Turn an LLM into a label-constrained teacher
texts -> [label]for distillation / active labeling.Each item is classified into
labelsby a constrained prompt; the reply is mapped back withpick_label(). The returned callable has the batched-teacher shape the rest ofmixle.taskexpects.
- llm_extractor(llm, fields, *, instruction=None, system=None)[source]
Turn an LLM into a field-extraction teacher
texts -> [{field: value}]formixle.task.extract.distill_extractor().Each text is extracted into a JSON object over
fields(values must be verbatim substrings so they align to token spans during distillation). The returned callable has the batched-teacher shape the extractor expects.