LlmBackend
Abstract interface for an LLM CLI backend.
Usage
LlmBackend()Concrete backends map abstract model sizes to provider-specific model names and encapsulate how to invoke the provider’s CLI and parse the raw response.
Attributes
models: dict[TModel, str]- Mapping from abstract model size to the provider’s model name.
Methods
| Name | Description |
|---|---|
| build_command() | Build the CLI argv for a single invocation (prompt delivered via stdin). |
| env() | Return extra environment variables for the CLI invocation, merged over the inherited environment. |
| parse_response() | Parse raw CLI stdout into text or a validated model. |
build_command()
Build the CLI argv for a single invocation (prompt delivered via stdin).
Usage
build_command(model, schema_path, agent)Parameters
model: str-
Provider-specific model name.
schema_path: str | None-
Schema argument for structured output, or
None. agent: bool- Whether the invocation may use tools / agent capabilities.
Returns
list[str]- The argv list to execute.
env()
Return extra environment variables for the CLI invocation, merged over the inherited environment.
Usage
env()parse_response()
Parse raw CLI stdout into text or a validated model.
Usage
parse_response(raw, response_model)Parameters
raw: str-
Raw stdout from the backend CLI.
response_model: type[BaseModel] | None-
Model to validate against, or
Nonefor raw text.
Returns
str | BaseModel-
rawwhenresponse_modelisNone, else a validated instance.