Backends¶
OpenAI-compatible HTTP API backend plugin.
- class nlp_shap.backends.api.ApiBackend(config: BackendConfig, *, transport: Any | None = None)[source]¶
Bases:
objectGenerate text through an OpenAI-compatible
/chat/completionsendpoint.- async generate(snapshot: ConversationSnapshot, max_new_tokens: int, temperature: float, top_k: int) GenerationRecord[source]¶
Generate assistant text for
snapshotvia the HTTP API.
Chat-completions request and response helpers.
- nlp_shap.backends.api.payload.build_chat_payload(model_id: str, messages: list[dict[str, str]], max_new_tokens: int, temperature: float, top_k: int) dict[str, Any][source]¶
Build an OpenAI-style chat-completions JSON body.
- nlp_shap.backends.api.payload.payload_cache_key(payload: dict[str, Any]) str[source]¶
Return a stable SHA256 key for deterministic request deduplication.
- nlp_shap.backends.api.payload.extract_message_content(data: dict[str, Any]) str[source]¶
Parse assistant text from a chat-completions JSON response.
LM Studio backend plugin.
- class nlp_shap.backends.lmstudio.LmStudioBackend(config: BackendConfig)[source]¶
Bases:
objectGenerate text through a local LM Studio API server.
- async generate(snapshot: ConversationSnapshot, max_new_tokens: int, temperature: float, top_k: int) GenerationRecord[source]¶
Generate assistant text for
snapshotvia LM Studio.
Mock backend exports.
- class nlp_shap.backends.mock.MockBackend(config: BackendConfig | None = None, *, model_id: str = 'mock')[source]¶
Bases:
objectHash-based generative backend with no external model dependencies.
- async generate(snapshot: ConversationSnapshot, max_new_tokens: int, temperature: float, top_k: int) GenerationRecord[source]¶
Return deterministic generation output for
snapshot.
Hugging Face causal language model backend (text-only).
- class nlp_shap.backends.transformers.text.TransformersTextBackend(config: BackendConfig)[source]¶
Bases:
objectGenerate text with a local Hugging Face causal language model.
- set_kv_cache_enabled(enabled: bool) None[source]¶
Enable or disable prefix-cache reuse for coalition generation.
- async generate(snapshot: ConversationSnapshot, max_new_tokens: int, temperature: float, top_k: int) GenerationRecord[source]¶
Generate assistant text for
snapshotwith optional prefix caching.