Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions conserver/links/hugging_llm_link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ The link can be configured through environment variables or the link configurati
HUGGINGFACE_API_KEY=your-api-key # Required for API-based inference
```

> **Local inference is opt-in.** The default path (`use_local_model: false`) calls the
> HuggingFace HTTP API and pulls in no ML dependencies. Setting `use_local_model: true`
> runs the model on-device via `transformers`, which is **not** part of the base
> `conserver` install. Install it with `uv sync --group conserver --group conserver-local`
> and add a model backend (e.g. `torch`) yourself. Without it, the local path raises a
> clear `ImportError` at runtime.

Additional configuration options:
- `model`: HuggingFace model ID (default: "meta-llama/Llama-2-70b-chat-hf")
- `use_local_model`: Toggle local model inference (default: false)
Expand Down
19 changes: 18 additions & 1 deletion conserver/links/hugging_llm_link/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
RetryError,
before_sleep_log,
)
import transformers
import anyio

# Local imports
Expand Down Expand Up @@ -154,6 +153,24 @@ class LocalHuggingFaceLLM(BaseLLM):

def __init__(self, config: LLMConfig):
super().__init__(config)
# transformers (and a backend such as torch) is an optional dependency.
# The default, API-based path (use_local_model=false) does not need it, so
# the import is deferred to here rather than loaded at module import time.
try:
import transformers
except ModuleNotFoundError as e:
# Only translate the "transformers itself is missing" case. If transformers
# is present but raises while importing a transitive dep/backend, re-raise the
# original error so the real cause isn't masked by the guidance below.
if e.name != "transformers":
raise
raise ImportError(
"Local HuggingFace inference requires the optional 'conserver-local' "
"dependency group plus a model backend (e.g. torch). "
"Install it with: uv sync --group conserver --group conserver-local. "
"The default path (use_local_model=false) calls the HuggingFace API "
"and needs none of this."
) from e
Comment thread
howethomas marked this conversation as resolved.
Comment thread
howethomas marked this conversation as resolved.
Comment thread
pavanputhra marked this conversation as resolved.
logger.info(f"Initializing local model: {self.config.model}")
device = "cpu" # Always use CPU for local models
logger.info(f"Using device: {device}")
Expand Down
13 changes: 11 additions & 2 deletions conserver/links/hugging_llm_link/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Dict, Any, Optional
from transformers import pipeline
from typing import Any, Dict

AUDIT_META = {
"third_party_service": "Hugging Face",
Expand All @@ -21,6 +20,16 @@ def __init__(self, model_name: str = "facebook/bart-large-mnli", **kwargs):
model_name: The HuggingFace model to use
**kwargs: Additional arguments passed to the model pipeline
"""
# transformers is an optional dependency (group: conserver-local); import lazily.
try:
from transformers import pipeline
except ModuleNotFoundError as e:
if e.name != "transformers":
raise
raise ImportError(
"HuggingLLMLink requires the optional 'conserver-local' dependency group. "
"Install it with: uv sync --group conserver --group conserver-local."
) from e
Comment thread
howethomas marked this conversation as resolved.
self.classifier = pipeline(
"zero-shot-classification", model=model_name, **kwargs
)
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ api = [
conserver = [
{include-group = "storage"},
# Processing links
"transformers>=4.48.0",
"openai>=1.60.0",
"groq>=0.4.0",
"deepgram-sdk>=3.1.5,<4.0.0",
Expand All @@ -68,6 +67,16 @@ conserver = [
"watchdog",
]

# Optional: on-device HuggingFace inference for hugging_llm_link's local-model path.
# transformers is ~48MB (plus tokenizers/huggingface_hub, ~67MB total) and additionally
# needs a model backend such as torch installed separately. The default hugging_llm_link
# path (use_local_model=false) calls the HuggingFace HTTP API and needs none of this, so
# transformers is kept out of the base conserver install.
# Install with: uv sync --group conserver --group conserver-local
conserver-local = [
"transformers>=4.48.0",
]

# Development / test dependencies.
dev = [
"black>=24.2.0",
Expand Down
6 changes: 4 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.