Skip to main content

Zu HuggingFace adapter: task models as typed tools/detectors/validators, behind the supply-chain guards

Project description

zu-huggingface

HuggingFace models behind Zu's typed ports. HuggingFace is not a model — it is the largest hub of open models across every modality — so "supporting it" means three different things, and this package draws the line cleanly (Engineering Design §8.3–8.5).

Chat / vision-language models as the policy — no code here

A chat or vision-language model that is the brain speaks the OpenAI chat API on all three HuggingFace serving surfaces (the router's /v1, a dedicated Endpoint's /v1, or a local vLLM server). So a HuggingFace model as the policy is the existing openai-compatible provider pointed at a HuggingFace base URL — the OpenRouter story exactly, no new adapter:

# agent.yaml — a HuggingFace multimodal model as the policy
model:    meta-llama/Llama-Vision-...        # any chat / VLM id on the Hub
provider: openai-compatible
options:
  base_url: https://router.huggingface.co/v1  # or an Endpoint, or local vLLM
  api_key_env: HF_TOKEN

Task models as tools, detectors, validators — this package

Most HuggingFace models are not chat models (OCR, ASR, detection, embeddings, classification, …), so they enter through the non-policy ports by their role (the port is the role, assigned per agent — §4.5):

Role Class Task
Tool Transcribe (hf_transcribe) speech → text (ASR)
Tool ImageToText (hf_image_to_text) image → text (OCR / caption)
Tool DetectObjects (hf_detect) image → labelled boxes
Tool Embed (hf_embed) text → vector (retrieval / grounding)
Tool Classify (hf_classify) text → labels
Tool ZeroShotClassify (hf_zero_shot) text + labels → scores
Tool Summarize (hf_summarize) text → text
Tool Translate (hf_translate) text → text
Detector HfClassifierDetector classify an observation → ESCALATE/stop
Validator HfClassifierValidator classify the result → fail/RETRY

Each is parameterised by a model id (and the role wrappers by the labels that matter), so they are wired by reference in config per agent rather than as zero-config entry points:

tools:
  - ref: zu_huggingface.tools:Transcribe
    args: { model: openai/whisper-large-v3 }
  - ref: zu_huggingface.tools:Embed
    args: { model: BAAI/bge-large-en-v1.5 }
detectors:
  - ref: zu_huggingface.roles:HfClassifierDetector
    args: { model: facebook/bart-large-mnli, candidate_labels: ["safe","unsafe"], escalate_on: ["unsafe"] }

The typed multimodal Content (Text/Image/Audio) from zu_core.content is the currency in and out — which is what lets a non-chat model slot into the loop as cleanly as a chat one.

Hosted vs local — one seam

Every tool depends only on the HfClient seam, so the same tool works:

  • HostedInferenceClientBackend wraps huggingface_hub.InferenceClient (the serverless router or a dedicated Endpoint). Egresses to router.huggingface.co; HF_TOKEN is read from the environment inside the backend. pip install 'zu-huggingface[hosted]'.
  • LocalPipelineBackend wraps transformers.pipeline for the air-gapped / on-prem case. Reaches no network. Every pipeline is built through the supply-chain guards. pip install 'zu-huggingface[local]' (plus a backend such as torch).

The supply chain — safe by default (§8.3)

Pulling a model from the Hub is a supply-chain surface. supply_chain.py enforces, by default:

  • Pin + hash. A ModelPin should carry a full commit-sha revision; verify_file_hash checks a downloaded file's sha256.
  • safetensors, not pickle. verify_model_source rejects .bin/.pt/.ckpt checkpoints (which execute on deserialisation) unless explicitly allowed.
  • No remote code. safe_pipeline_kwargs forces trust_remote_code=False; assert_no_remote_code raises if it is relaxed.

The safe configuration is the default — there is nothing to turn on to be safe, only flags a reviewed case may relax.

Tests

Offline, no network, no model download: the tools and role wrappers are exercised against a fake HfClient, and the supply-chain guards are pure. uv run pytest packages/zu-huggingface.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zu_huggingface-0.2.3.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zu_huggingface-0.2.3-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file zu_huggingface-0.2.3.tar.gz.

File metadata

  • Download URL: zu_huggingface-0.2.3.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zu_huggingface-0.2.3.tar.gz
Algorithm Hash digest
SHA256 dceaf3db5ab6fef86231e62c0abf20cad7ea8178a85f7a804fba08415cd53cf3
MD5 fda11ebca9eaf434a396757b98b52fb3
BLAKE2b-256 5a65b113593bb26d859ceb20a0ecd3b6b72acad833ca25014659c9531ca7c06a

See more details on using hashes here.

File details

Details for the file zu_huggingface-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: zu_huggingface-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for zu_huggingface-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 739d1ee2df9655012c064ffa2bd9c0d4e497f7f8a6edf2b905b6b93e1d49b3ae
MD5 a6377d2b5cec1fa381be1a909b2edc86
BLAKE2b-256 b6f5c14b46c8f9cfee80994a799bc3247b81a072782f2a624f9361e0c0460869

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page