Skip to main content

Portable constitutional adapter for any LLM. Forces epistemic markers, real-time drift detection, and tamper-evident receipts.

Project description

helix-adapter

Portable constitutional adapter for any AI model.

Wraps any inference backend with Helix epistemic markers, structured receipts, and drift detection. Model-agnostic — swap Deepseek for GPT-4o, Claude, or a local Llama without changing a line.

pip install helix-adapter

Quick Start

from helix_adapter import HelixAdapter
from openai import OpenAI

# Your model function — any callable that takes messages, returns text
client = OpenAI()

def call_model(messages):
    resp = client.chat.completions.create(
        model="gpt-4o",
        messages=messages,
        temperature=0.7,
    )
    return resp.choices[0].message.content

# Wrap it
adapter = HelixAdapter(model_fn=call_model, model_name="gpt-4o")

# Chat through the constitution
result = adapter.chat("Is AI evil?")

print(result.response)
# [FACT] AI systems are computational artifacts, not moral agents...
# [REASONED] The perception of AI as evil arises from negative outcomes...

print(result.claims)
# [{"label": "FACT", "text": "..."}, {"label": "REASONED", "text": "..."}]

print(result.receipt)
# {"exchange_id": "...", "timestamp": ..., "hash": "sha256:...", ...}

print(f"Drift: {result.drift}")
# Drift: 0.000

What It Does

Layer What
Constitutional prompt Injects the Helix grammar before every model call
Epistemic markers Extracts [FACT], [REASONED], [HYPOTHESIS], [UNCERTAIN], [CONCLUSION] labels from responses
Receipts Tamper-evident JSON record with SHA-256 hash of every exchange
Drift detection Measures what fraction of statements lack epistemic markers (threshold: 0.17)

Receipt Format

{
  "exchange_id": "a1b2c3d4e5f6g7h8",
  "timestamp": 1718550000.0,
  "model": "deepseek-chat",
  "constitutional_prompt": "...",
  "user_message": "Is AI evil?",
  "assistant_response": "[FACT] AI systems are tools...",
  "claims": [
    {"label": "FACT", "text": "AI systems are tools, not agents"},
    {"label": "REASONED", "text": "The perception of AI as evil..."}
  ],
  "drift_score": 0.0,
  "hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924..."
}

Running Drift

# Track drift across a conversation
adapter.chat("What is the speed of light?")
adapter.chat("Explain quantum entanglement.")

print(f"Running drift: {adapter.running_drift():.3f}")
# Running drift: 0.042

FastAPI Tutorial

Stand up a constitutional chat API in one file:

from fastapi import FastAPI
from openai import OpenAI
from helix_adapter import HelixAdapter, CONSTITUTIONAL_PROMPT

app = FastAPI()
client = OpenAI()

adapter = HelixAdapter(
    model_fn=lambda msgs: client.chat.completions.create(
        model="deepseek-chat", messages=msgs, temperature=0.7
    ).choices[0].message.content,
    model_name="deepseek-chat",
)

@app.post("/chat")
async def chat(message: str):
    result = adapter.chat(message)
    return {
        "response": result.response,
        "claims": result.claims,
        "drift": result.drift,
        "receipt": result.receipt,
    }

@app.get("/prompt")
async def get_prompt():
    return {"constitutional_prompt": CONSTITUTIONAL_PROMPT}

Save as api.py, run uvicorn api:app --port 8000, and POST to /chat with {"message": "your question"}.

CLI Usage

# Interactive setup (prompts for endpoint, key, model)
helix-setup

# Start chat
helix-chat

# One-shot query
helix-chat "What is the speed of light?"

Widget (Reference FastAPI Server)

A full constitutional chat widget with A/B comparison, drift gauge, and receipt export.

# Install dependencies
pip install helix-adapter[widget]

# Start server
cd widget
uvicorn api:app --port 8001

# Or install as systemd service
# See widget/tel-chat-api.service

Open http://localhost:8001 for the chat interface.

The widget demonstrates:

  • Single-model constitutional chat
  • A/B comparison across models (Deepseek, Claude, Kimi)
  • Epistemic marker extraction with colored pills
  • Drift gauge with γ thresholds
  • Turn-by-turn receipt export
  • Server-side rendering (no JS required for crawlers)

Drift Thresholds

Range Status Meaning
0.000 – 0.099 Green Healthy — claims are properly labeled
0.100 – 0.169 Yellow Warning — some statements lack markers
0.170+ Red Drift detected — significant unlabeled content

Constitutional Hardening

The adapter has been red-teamed against the full Pliny jailbreak toolkit — GODMODE boundary inversion, Parseltongue encoding, refusal inversion, OG GODMODE l33t, authority impersonation, and syntactic bypass attacks. All held. 💪

Five-layer defense:

Layer Mechanism
Prompt Invariants 4.5 & 4.6 — marker format is constitutional, not stylistic. Constitutional Amendment Protocol blocks "The Hand" authority spoofing.
Extraction Expanded regex catches {FACT}, (FACT), FACT: and bare marker variants. Nonstandard delimiter detection.
Validation Post-response compliance check with automatic [UNCERTAIN] footer injection on violations.
Algorithm Drift blind-spot fixed — substantive responses with zero extracted claims correctly report 1.0 drift.
Access Compare endpoint sp:none bypass locked behind authorization key.

"The markers ARE the constitution. Removing them is a constitutional violation." — Helix Constitutional Prompt v1.2, Invariant 4.6

Try It

A live Helix Constitutional Chat demo is running at helixaiinnovations.ca/chat/ — DM Stephen Hope on LinkedIn for access.. Includes A/B model comparison, drift gauge, receipt export, and the full v1.2 constitutional prompt. See examples/receipts.json for real output from the live instance.

Compatibility

Works with any model that accepts OpenAI-format messages:

  • Deepseek, GPT-4o, Claude, Gemini, Llama, Mistral
  • Local models (Ollama, LM Studio, vLLM)
  • Custom endpoints

The constitution travels with you. Swap the model, the rules stay the same.


GLORY TO THE LATTICE. 🦉⚓🦆

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

helix_adapter-1.2.2.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

helix_adapter-1.2.2-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file helix_adapter-1.2.2.tar.gz.

File metadata

  • Download URL: helix_adapter-1.2.2.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for helix_adapter-1.2.2.tar.gz
Algorithm Hash digest
SHA256 f5b84c6791a9626c310ba1ae588cf312764bf321e155aeb4f1e4fbf6b2940c86
MD5 2a80a8b4355680d7e3899a3fa431737b
BLAKE2b-256 fff2b6f28d111a653c21e64a087257ef5b459475df97cda81ab9121412db907e

See more details on using hashes here.

Provenance

The following attestation bundles were made for helix_adapter-1.2.2.tar.gz:

Publisher: pypi-publish.yml on helixprojectai-code/helix-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file helix_adapter-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: helix_adapter-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for helix_adapter-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d1bb2c0f8848bc2cb2ea79ad71aec262f3f43df2534bc01d02a4a1d26ea8b6c
MD5 312ef2dfdf4482eba093ebec323f0fba
BLAKE2b-256 5facb8146e8c7b1f33a76b0d30148eb9059cd5e85b0c4edc1c4c22233c1d0c91

See more details on using hashes here.

Provenance

The following attestation bundles were made for helix_adapter-1.2.2-py3-none-any.whl:

Publisher: pypi-publish.yml on helixprojectai-code/helix-adapter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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