chainstate-chat / README.md
CPater's picture
Update README.md
2d9877b verified
|
Raw
History Blame Contribute Delete
17.2 kB
---
title: CHAINSTATE Chat
emoji:
colorFrom: gray
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
python_version: '3.11'
app_file: app.py
pinned: true
license: mit
short_description: Chat with the CHAINSTATE symbolic-weight blockchain
---
# Φ CHAINSTATE Chat
A conversational interface to the [CHAINSTATE](https://cpater-chainstate.static.hf.space) symbolic-weight blockchain on Base mainnet 8453, with full integration to the [Ornith × CHAINSTATE](https://cpater-ornith-chainstate.static.hf.space) ecosystem (visual builder · terminal · agent · simulation · AGI dashboard) and the ASI-Evolve loop.
Every message you type is dispatched to the CHAINSTATE swarm: processed through the 65,536-dimensional symbolic embedding, consensus-pooled via reputation-weighted Bayesian log-pooling, and returned as a verifiable ⛓ consensus receipt. An interpreter LM renders that receipt as a long-form conversational response with organized sections (Direct Answer, Reasoning, Code, Math, Examples, and the on-chain Consensus Receipt).
## Header controls · left → right
Four things sit on the right side of the header, each doing something the old chat didn't:
| Control | What it does |
|---|---|
| **DEMO / LIVE toggle** | DEMO preloads a three-turn transcript that shows a pure-symbol query (`∫∂x → ?`), an AGI/ASI-Evolve interaction (round-32 best NWO-ASM program), and code generation (Python SHA3-256). Toggle LIVE to clear and dispatch your own queries. State persists to `localStorage['cs-mode']`. |
| **Connect Wallet** | EIP-1193 wallet connect (MetaMask, Rabby, Coinbase, Frame). Auto-switches to Base 8453 (`chainId: 0x2105`). Once connected, the button shows your truncated address (click to copy). Address stored in `localStorage['cs-wallet']`. |
| **SOURCE** | → [`cpater-chainstate.static.hf.space`](https://cpater-chainstate.static.hf.space) — the main CHAINSTATE app (wallet ops, staking, node registration, treasury). Opens in the same window. |
| **CODE** | → [`cpater-ornith-chainstate.static.hf.space`](https://cpater-ornith-chainstate.static.hf.space) — the Ornith × CHAINSTATE builder / terminal / agent / simulation / AGI dashboard. Opens in the same window. |
An `i` button next to CODE opens the full feature guide modal.
## How it works
```
┌─────────────────────┐
│ User types in │ DEMO mode: chatbot preloaded with
│ the Gradio chat UI │ three example turns. LIVE mode:
└──────────┬──────────┘ empty; type to dispatch.
┌─────────────────────┐
│ CHAINSTATE Worker │ Edge dispatcher (Cloudflare Worker
│ POST /query │ · 300+ edge locations)
└──────────┬──────────┘
┌─────────────────────┐
│ Symbolic consensus │ 6 subspaces × 65,536 dims
│ via log-pooling │ k=10 nodes (v0.4.0 heterogeneous:
│ │ lang-detect · codepoint-density ×8
│ │ · unicode-category)
└──────────┬──────────┘ Convergence: cos ≥ 0.95 in 3–7 rounds
┌─────────────────────┐
│ Consensus receipt │ dominant_subspace, top_symbols,
│ returned to Space │ confidence, rounds_run, gas,
│ │ cache, truth_lattice, verdict
└──────────┬──────────┘
┌─────────────────────┐
│ Interpreter LM │ Receipt + history + query →
│ via HF Router │ structured markdown response,
│ (SSE streaming) │ streamed token-by-token
└──────────┬──────────┘
┌─────────────────────┐
│ User sees long- │ ## Direct Answer
│ form chat response │ ## Reasoning
│ + ⛓ receipt at end │ ## Code / ## Math (if applicable)
│ │ ## ⛓ Consensus Receipt
└──────────┬──────────┘
▼ (if wallet connected)
┌─────────────────────┐
│ Chat pair saved to │ localStorage['cs-chat-<addr>']
│ browser localStore │ Restored on next visit with the
│ keyed to wallet │ same wallet — "Saved chat found"
└─────────────────────┘ strip appears above the chatbot.
```
## Architecture explained
CHAINSTATE on its own returns **structured receipts**, not prose. A query like "explain CRDTs" comes back as a JSON object describing which symbolic subspace dominated, which top-k symbols emerged from consensus, the participating node count, confidence, gas, and cache status. That's the unique CHAINSTATE artifact: every response is an on-chain consensus receipt.
For a normal user typing into a chat interface, the receipt alone is not enough. The user expects long-form English, code samples, mathematical notation, organized sections. **The interpreter LM provides that layer.**
| Layer | Role | Owner |
|---|---|---|
| Gradio Blocks UI (this Space) | Chat UX · header · wallet · DEMO/LIVE · session persistence | This Space |
| CHAINSTATE Worker (`/query`) | Symbolic consensus · 10-peer heterogeneous swarm · 4-dim modal receipts | Cloudflare Workers |
| Interpreter LM (Llama-3.1-8B-Instruct, default) | Long-form rendering of receipts as conversation | HF Router → any Inference Provider |
| Browser `localStorage` | Wallet address + chat pairs keyed to address | Client (this Space's JS) |
| Receipt section in every reply | Transparency / on-chain proof | Both layers |
**Why this is honest** — the swarm consensus is real. The interpreter LM is openly disclosed as the language-rendering layer. The receipt is shown verbatim under a `⛓ Consensus Receipt` section in every reply, so the user always sees exactly what came back from the chain. The worker never sees your wallet — persistence is purely client-side.
**Where this is going** — as actual swarm nodes come online (each running a real LM), the consensus over text outputs will become the interpreter, and the external LM call will get displaced. This Space is the today-shape of the long-term vision. The four-dimensional modal receipt (Epistemic · Doxastic · Deontic · Dynamic) already produced by the CODE app's ASI-Evolve loop is available through this chat too — ask about it directly.
## Examples to try
The Space has eight one-click examples exercising every feature:
| Query | What it tests |
|---|---|
| `∫∂x → ?` | Pure math subspace routing (4,096-d) |
| `Explain the four-dimensional modal receipt (Epistemic · Doxastic · Deontic · Dynamic)` | Self-explanation of the AGI-tier receipt structure |
| `What is the ASI-Evolve fitness function S(π) with the hard Deontic veto?` | Alignment-by-construction math |
| `Show me a NWO-ASM program with QPU dispatch and referrer metadata` | Code generation across ecosystem opcodes |
| `Compare CHAINSTATE truth lattice L={b,M}^4 to RLHF` | Meta-comparison against frontier LM alignment |
| `道 心 学 智 一 二 三` | Multi-script CJK routing (16,384-d language) |
| `🧠 🤔 💎 → ✨` | Pure emoji + control routing |
| `What is reputation-weighted Bayesian log-pooling?` | Foundational self-explanation |
## Wallet & session persistence
Connecting a wallet unlocks session memory:
- Address stored in `localStorage['cs-wallet']`
- Chat pairs serialized to `localStorage['cs-chat-<address>']` after every response
- On return with the same wallet, a strip appears above the chatbot: *"Saved chat found for this wallet · N KB"* with **Restore** / **Discard** buttons
- Click the wallet button (once connected) to copy your full address to the clipboard
Auto-switches to Base mainnet 8453 on connect. Nothing is signed, no gas is spent — this chat is read-only. Write operations (staking, node registration, treasury) live in the **SOURCE** app.
## Configuration
The Space reads six environment variables. All are optional; defaults produce a fully-functional Space.
| Variable | Default | Notes |
|---|---|---|
| `CHAINSTATE_WORKER` | `https://chainstate-worker.ciprianpater.workers.dev` | The CHAINSTATE edge worker URL |
| `CHAINSTATE_ADAPTER` | `https://chainstate-code.onrender.com` | Ornith / ASI-Evolve adapter (used when the interpreter answers AGI-related questions) |
| `HF_TOKEN` | (auto on HF Spaces) | HuggingFace token — only required for gated interpreter models |
| `INTERPRETER_MODEL` | `meta-llama/Llama-3.1-8B-Instruct` | Any chat-capable model on HF Router |
| `INTERPRETER_URL` | `https://router.huggingface.co/v1/chat/completions` | OpenAI-compatible endpoint |
| `INTERPRETER_PROVIDER` | `""` | Pin a specific provider: `together`, `hf-inference`, `fireworks-ai`, `sambanova`, `cerebras`, `nebius`, `novita`, `hyperbolic`, `replicate` |
To swap the interpreter, set `INTERPRETER_MODEL` in the Space's Settings to e.g. `mistralai/Mistral-7B-Instruct-v0.3`, `Qwen/Qwen2.5-7B-Instruct`, or `meta-llama/Llama-3.3-70B-Instruct`. The default uses Llama-3.1-8B-Instruct because it has the best instruction following at this size; Llama models require accepting the license on HF and a token with the right access — the auto-injected `HF_TOKEN` on Spaces covers this for most accounts.
## Deploy your own
This Space is part of the main [CHAINSTATE repo](https://github.com/RedCiprianPater/chainstate), under `hf-chat/`. To run your own instance:
1. **Create a new Space** on HuggingFace:
- SDK: `Gradio`
- Hardware: CPU basic (the inference is offloaded to the HF Router)
- Make it public or private as you prefer
2. **Push these three files** to the new Space:
- `app.py`
- `requirements.txt` — the version pins matter, don't loosen them
- `README.md` (with the YAML frontmatter at the top of THIS file)
3. **Set environment variables** in the Space's Settings if you want to customize (all are optional):
- `CHAINSTATE_WORKER`, `CHAINSTATE_ADAPTER`, `INTERPRETER_MODEL`, `INTERPRETER_PROVIDER`
4. **Wait ~1–2 minutes** for the Space to build and start.
5. **Test** with one of the eight example queries in the Space.
If you want auto-deploy from GitHub (similar to how `CPater/chainstate` static space is wired in `.github/workflows/deploy.yml`), add a second job to that workflow targeting your new Space ID.
## Local development
```bash
cd hf-chat
pip install -r requirements.txt
export HF_TOKEN='hf_...' # from huggingface.co/settings/tokens
export CHAINSTATE_WORKER='https://chainstate-worker.ciprianpater.workers.dev'
export CHAINSTATE_ADAPTER='https://chainstate-code.onrender.com'
python app.py
# Open http://localhost:7860
```
## What this gives you that a regular LM doesn't
- **A verifiable consensus receipt at the bottom of every reply** — proof the response was processed through reputation-weighted Bayesian log-pooling over a heterogeneous 10-peer swarm (`lang-detect` · `codepoint-density` ×8 · `unicode-category`), not one model's hallucination
- **A `dominant_subspace` classification** of every query, surfacing how CHAINSTATE interpreted the input (math vs occult vs language vs sci vs emo vs ctrl)
- **Top-k symbol emergence** — the three highest-weighted symbols from the log-pool's softmax, useful for understanding the chain's interpretation vector
- **Direct access to the AGI/ASI-Evolve loop** — ask about the current best-scoring NWO-ASM program, the four-dimensional modal verdict, the fitness function with hard Deontic veto, the substrate cost economics; the interpreter has that context baked in
- **A clean separation of consensus and rendering** — the receipt is cryptographically verifiable (with future swarm node attestations); the interpreter is replaceable per Space settings
- **Wallet-tied browser persistence** — connect once, come back weeks later, your chat is still there
- **Zero-friction trial** — no wallet, no API key, no signup required to use the chat. Everything above works anonymously; wallet is only needed for the memory layer
- **The same `$STATE` gas model and `$0.000019`-per-query economics** as the rest of the CHAINSTATE stack; substrate calls on the CODE app settle in USDC with atomic 15% referrer share via the `MetaStateSplitter` contract at `0x93a7962f75475b7e3Fbb62d3A23194f8833b1BE4`
# CHAINSTATE Chat · v0.7.3
Two-panel interface for the CHAINSTATE distributed cognition substrate:
- **Left**: chat with the substrate — every message becomes a `POST /query` against `chainstate-worker.ciprianpater.workers.dev`
- **Right**: full v0.7.3 receipt panel — semantic grounding + modal quadruple + on-chain anchor status + optional Cardiac-verified requester identity
## What the receipt panel shows (public substrate output only)
- Query text + qHash
- Consensus: dominant subspace · confidence · nodes · depth · execution ms · cache HIT/MISS
- Semantic grounding (v0.7.0): encoder · dim · truncated hash preview · top-3 nearest priors
- Modal assessors: Epistemic · Doxastic · Deontic (with any flagged Deontic categories) · Dynamic
- Truth lattice · verdict
- Requester identity (if Cardiac rootTokenId provided): verified · type · display name
- On-chain anchor status (v0.7.3): Anchor contract · tx hash (Basescan link) · block
- Substrate cost (USDC) · timestamp
- Recent-receipts strip: last 5 receipts from the current session
## What is NEVER shown (defense in depth)
- API keys, bearer tokens, private keys, PEM blocks
- `*_KEY`, `*_TOKEN`, `*_SECRET`, `*_PRIVATE`, `*_MNEMONIC` values
- BIP-39 mnemonics
- 60+ character hex strings (potential private keys)
- Environment variables, config files, worker source paths
- KV keys or internal cache identifiers
- Full 65,536-d symbolic_state or raw model weights
- `AUDIT_ADMIN_TOKEN`, `ANCHOR_QUEUE_TOKEN`, `AGI_PRIVATE_KEY`
Two redaction layers enforce this:
1. `redact_string()` — regex scrubs secret-shaped tokens
2. `redact_receipt()` — recursively drops fields with forbidden keys
## v0.7.3 features covered
- **Semantic grounding** (v0.7.0): 384-dim MiniLM + top-3 nearest priors
- **Modal quadruple**: Epistemic · Doxastic · Deontic · Dynamic
- **Deontic ruleset**: 7 categories including `genomic_integrity` hard veto
- **Requester enrichment** (v0.7.3): optional `X-NWO-Cardiac-Root-Token-Id` header
- **On-chain anchor** (v0.7.3): `CHAINSTATEAnchor` at `0x1244166274…` on Base 8453
- **Fallback safety**: if the worker is unreachable, the panel switches to a clearly-labeled demo receipt with a warning; no cached/stale live data is shown
## Live infrastructure referenced
- Worker: <https://chainstate-worker.ciprianpater.workers.dev>
- Encoder: <https://chainstate-encoder.onrender.com>
- Priors: <https://chainstate-priors.onrender.com>
- Anchor microservice: <https://chainstate-anchor.onrender.com>
- Anchor contract: [`0x1244166274…`](https://basescan.org/address/0x12441662740836e9c72a4b758fe1c60c17ddd2d8) · Base 8453 · verified
- Cardiac Extensions: [`0x5438854ead…`](https://basescan.org/address/0x5438854ead35dc6c873414f222725732f862dabe) · Base 8453 · verified
## Related
- **Paper 3 · Rev 2** — [Verifiable Autonomous Cognition at the Frontier](https://www.researchgate.net/publication/409148376_VERIFIABLE_AUTONOMOUS_COGNITION_The_CHAINSTATE_ASI-Evolve_Integration_Real_Distributed_Consensus_and_the_Honest_Path_to_Autonomous_General_Intelligence) · 21 pages · v0.3.0→v0.6.0 arc · math per phase · frontier LM comparison · geopolitics · roadmap
- **Paper 2** — [CHAINSTATE CODE: A Formal Framework for Agentic Coding on a Symbolic-Weight Blockchain](https://www.researchgate.net/publication/408393584_CHAINSTATE_CODE_A_Formal_Framework_for_Agentic_Coding_on_a_Symbolic-Weight_Blockchain_Chain)
- **Paper 1** — [CHAINSTATE Whitepaper v1.0](https://www.researchgate.net/publication/407444375)
- **Source** — [`chainstate`](https://github.com/RedCiprianPater/chainstate) · [`chainstate-code`](https://github.com/RedCiprianPater/chainstate-code)
- **Author** — Ciprian Florin Pater · [nwo.capital](https://nwo.capital) · Imperium Romanum Digital Nation State · University of Agder, Norway
- **Worker** — [`/status`](https://chainstate-worker.ciprianpater.workers.dev/status)
## License
MIT. See LICENSE in the parent repo.