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: Protocol

Anything that can turn a prompt into text. The whole contract the rest of the package depends on.

complete(prompt, *, system=None, **kwargs)[source]
Parameters:
  • prompt (str)

  • system (str | None)

  • kwargs (Any)

Return type:

str

class CallableLLM(fn)[source]

Bases: object

Wrap a plain fn(prompt) -> str (or fn(prompt, system)) as an LLM – local models and tests.

Parameters:

fn (Callable[..., str])

complete(prompt, *, system=None, **kwargs)[source]
Parameters:
  • prompt (str)

  • system (str | None)

  • kwargs (Any)

Return type:

str

class OpenAICompatLLM(base_url, model, *, api_key=None, temperature=0.0, max_tokens=512, timeout=60.0)[source]

Bases: object

An LLM backed by any OpenAI-compatible /v1/chat/completions endpoint (stdlib HTTP only).

Parameters:
complete(prompt, *, system=None, **kwargs)[source]
Parameters:
  • prompt (str)

  • system (str | None)

  • kwargs (Any)

Return type:

str

pick_label(text, labels)[source]

Map a free-text LLM reply to one of labels (exact, then substring, else the first label).

Parameters:
Return type:

str

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 labels by a constrained prompt; the reply is mapped back with pick_label(). The returned callable has the batched-teacher shape the rest of mixle.task expects.

Parameters:
Return type:

Callable[[list[str]], list[str]]

llm_extractor(llm, fields, *, instruction=None, system=None)[source]

Turn an LLM into a field-extraction teacher texts -> [{field: value}] for mixle.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.

Parameters:
Return type:

Callable[[list[str]], list[dict[str, str]]]