Backends¶
OpenAI¶
OpenAI backend.
- class LLMOpenAI.LLMOpenAI.LLMOpenAI(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
BaseLLMOpenAI chat-completions backend.
Configuration keys:
LLM_VERSION: Model name. API_KEY_NAME: Environment variable holding the API key. BASE_URL: Optional custom base URL (also accepts ``BASE_URL_ENV``). ORGANIZATION / PROJECT: Optional OpenAI account scoping. IMAGE_DETAIL: Detail level sent with images ("auto", "low", "high"). LLM_CONFIG: Request parameters, forwarded as-is. Use the names the model expects, e.g. ``max_completion_tokens`` for the gpt-5 family and ``max_tokens`` before it.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
Azure OpenAI¶
Azure OpenAI backend.
- class LLMAzureOpenAI.LLMAzureOpenAI.LLMAzureOpenAI(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
BaseLLMAzure OpenAI chat-completions backend.
Configuration keys:
LLM_VERSION: Model name. DEPLOYMENT: Azure deployment name. Defaults to ``LLM_VERSION``. API_KEY_NAME: Environment variable holding the API key. ENDPOINT / ENDPOINT_ENV: Endpoint URL, or the environment variable holding it. API_VERSION: Azure API version. IMAGE_DETAIL: Detail level sent with images ("auto", "low", "high"). LLM_CONFIG: Request parameters, forwarded as-is. Use the names the deployment expects, e.g. ``max_completion_tokens`` for the gpt-5 family and ``max_tokens`` before it.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
- LLMAzureOpenAI.LLMAzureOpenAI.LLM¶
alias of
LLMAzureOpenAI
Azure OpenAI (Responses API)¶
Azure OpenAI backend speaking the Responses API.
- class LLMAzureOpenAIResponses.LLMAzureOpenAIResponses.LLMAzureOpenAIResponses(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
LLMAzureOpenAIAzure OpenAI backend for deployments served through the Responses API.
The reasoning-heavy deployments (the
-protier, and theo*-promodels before it) do not expose/chat/completionsat all: every request to it comes back as400 The requested operation is unsupported. They are only reachable through/responses, which differs from chat completions in more than the URL:max_completion_tokensis namedmax_output_tokens, andseeddoes not exist.Content parts are
input_text/input_image, andinput_imagecarries the URL directly rather than nesting it under animage_urlobject.The answer is one flat
output_text, and usage is reported asinput_tokens/output_tokens.
Connection settings are read by
LLMAzureOpenAIand are unchanged, except thatAPI_VERSIONmust be one that serves the Responses API (2025-04-01-previewor later).LLM_CONFIGis still forwarded as-is, so it has to use the Responses names.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
- build_content(message, images=None)[source]¶
Build the content of a single message, using Responses content parts.
- Parameters:
message (str) – The text of the message.
images (Optional[Sequence[ImageInput]], optional) – Images to attach.
- Returns:
The plain string without images, and a list of
input_text/input_imageparts with them. The base class builds atextpart instead, which the Responses API rejects.- Return type:
Any
- image_part(image)[source]¶
Encode an image as a Responses
input_imagecontent part.- Parameters:
image (ImageInput) – A
PIL.Image.Image, or the path of an image file.- Returns:
An
input_imagepart holding adata:URL and the configured detail level. Unlike the chat-completions part, the URL is a plain string field.- Return type:
Dict[str, Any]
- LLMAzureOpenAIResponses.LLMAzureOpenAIResponses.LLM¶
alias of
LLMAzureOpenAIResponses
Anthropic¶
Anthropic backend.
- class LLMAnthropic.LLMAnthropic.LLMAnthropic(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
BaseLLMAnthropic Messages API backend.
Configuration keys:
LLM_VERSION: Model name. API_KEY_NAME: Environment variable holding the API key. BASE_URL: Optional base URL. When set, the Foundry client is used. LLM_CONFIG: Request parameters, forwarded as-is. ``max_tokens`` is required by the API, so it is always sent.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
- LLMAnthropic.LLMAnthropic.LLM¶
alias of
LLMAnthropic
Google Gemini¶
Google Gemini backend.
- class LLMGemini.LLMGemini.LLMGemini(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
BaseLLMGemini backend built on the google-genai SDK.
Configuration keys:
LLM_VERSION: Model name. API_KEY_NAME: Environment variable holding the API key. BASE_URL: Optional custom endpoint. LLM_CONFIG: Request parameters, forwarded to ``GenerateContentConfig``. Generic names are translated, so ``max_tokens`` reaches the API as ``max_output_tokens``.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
- build_content(message, images=None)[source]¶
Build message content as Gemini parts.
- Parameters:
message (str) – The text of the message.
images (Optional[Sequence[ImageInput]], optional) – Images to attach.
- Returns:
The text part followed by one inline data part per image.
- Return type:
List[types.Part]
GLM¶
GLM backend (OpenAI-compatible API).
- class LLMGLM.LLMGLM.LLMGLM(model, params=None, config=None, config_file=None, examples=None)[source]¶
Bases:
BaseLLMGLM chat-completions backend, served through the OpenAI-compatible API.
Configuration keys:
LLM_VERSION: Model name. API_KEY_NAME: Environment variable holding the API key. ``ZHIPUAI_API_KEY`` is used as a fallback when the named variable is unset. BASE_URL: API base URL. Defaults to the BigModel endpoint. LLM_CONFIG: Request parameters, forwarded as-is.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
Hugging Face¶
Hugging Face LLM wrapper with optional quantization and config loading.
- class LLMHuggingFace.LLMHuggingFace.LLMHuggingFace(model, params=None, config=None, config_file=None, examples=None, device=None, quantize=None, cache_dir=None, device_map=None)[source]¶
Bases:
BaseLLMText-only Hugging Face backend, running the model in-process.
The weights are loaded on the first
query()(throughconnect()), so building the instance from a configuration file stays cheap.Configuration keys:
MODEL_NAME: Hugging Face model identifier. DEVICE: Device to run on. Defaults to CUDA when available. QUANTIZE: 8, 4, or 0 (no quantization). Defaults to 8. DEVICE_MAP / MULTI_GPU: Model sharding across GPUs. CACHE_DIR: Where weights are downloaded. DISABLE_SYSTEM: Rewrite system messages for templates without a system role. ENABLE_THINKING: Passed to chat templates that support it (Qwen3 family). LLM_CONFIG: Generation parameters (``max_tokens``, ``temperature``, ``top_p``, ``stop``, ``use_cache``), consumed locally rather than sent to a server.- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
device (str | None)
quantize (int | None)
cache_dir (str | None)
device_map (Any | None)
- format_prompt(examples, query)[source]¶
Format a simple Q/A few-shot prompt.
- Parameters:
examples (List[Dict[str, str]]) – Few-shot examples with “question”/”answer”.
query (str) – User question to append.
- Returns:
Rendered prompt string.
- Return type:
str
- generate_response(examples, query, max_length=512)[source]¶
Generate a response from Q/A few-shot examples.
- Parameters:
examples (List[Dict[str, str]]) – Few-shot examples with “question”/”answer”.
query (str) – User question to answer.
max_length (int) – Maximum number of generated tokens.
- Returns:
Assistant response.
- Return type:
str
- image_part(image)[source]¶
Wrap an image as the content part the chat templates expect.
Where the remote backends encode the image into the request, here the image travels as an object: the processor reads it when it renders the template, so it is kept as a
PILimage rather than base64.- Parameters:
image (Any) – A
PIL.Image.Image, or the path of an image file.- Returns:
An
imagecontent part holding the opened image.- Return type:
Dict[str, Any]
- Raises:
NotImplementedError – If this model does not take images.
- LLMHuggingFace.LLMHuggingFace.LLM¶
alias of
LLMHuggingFace
vLLM¶
vLLM offline backend with process-local shared engine reuse.
- class LLMVLLM.LLMVLLM.LLMVLLM(model, params=None, config=None, config_file=None, examples=None, **overrides)[source]¶
Bases:
BaseLLMOffline vLLM backend.
Model weights and KV runtime are kept in a process-level cache, so creating multiple instances with the same engine config does not reload the model.
Configuration keys:
MODEL_NAME: Model identifier or local path. DTYPE, TENSOR_PARALLEL_SIZE, MAX_MODEL_LEN, MAX_NUM_SEQS, MAX_NUM_BATCHED_TOKENS, GPU_MEMORY_UTILIZATION, SWAP_SPACE, TRUST_REMOTE_CODE, ENABLE_PREFIX_CACHING, DISABLE_LOG_STATS, ENFORCE_EAGER: vLLM engine settings. DOWNLOAD_DIR / DOWNLOAD_WORKERS: Where and how weights are fetched. DISABLE_SYSTEM: Rewrite system messages for templates without a system role. LLM_CONFIG: Sampling parameters, consumed locally rather than sent to a server.
- Parameters:
model (str)
params (Dict[str, Any] | None)
config (Dict[str, Any] | None)
config_file (str | Path | None)
examples (str | Path | None)
overrides (Any)