Metadata-Version: 2.4
Name: proprioceptive-lens
Version: 0.1.0
Summary: See inside your local model: live confidence, hesitations, long-term memory and internal-state behaviour for local LLMs.
License-Expression: MIT
Keywords: llm,ollama,interpretability,local-ai,memory,hidden-states
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: deep
Requires-Dist: torch>=2.1; extra == "deep"
Requires-Dist: transformers>=4.43; extra == "deep"
Dynamic: license-file

# Proprioceptive Lens

**See inside your local model.** A free app for anyone running local AI with [Ollama](https://ollama.com) or Hugging Face models.

![Lens showing a confidently wrong answer: every word at near-100% certainty](docs/demo-confidence.gif)

*qwen3:4b says the 17th US president was Garfield, with 100% certainty. (It was Andrew Johnson.) Token confidence shows the surface; Lens also lets you look underneath.*

- **Confidence you can see.** Every word is tinted by how sure the model was. Hover any word to see what it almost said.
- **Where it hesitated.** A live certainty trace, plus the exact words where the model weighed alternatives.
- **It remembers you.** Private memory of your conversations, on your computer, for any model.
- **Inside the model** (deep mode). A live layer-by-layer activity map of the network while it writes.
- **Behaviour** (optional). Internal-state probes score what the model is doing: writing code or prose, formal or casual
  register, following your instructions, creative or literal, assertive or hedged, repeating itself, asking or stating.
  These probes were validated on the original model, then transferred to each supported model. There they were
  re-tested against length and random-direction controls, and with a live test on the model's own answers.
- **Terminal mode and an API** for wiring Lens into your own stack.
- **Private.** Everything runs locally. Behaviour is opt-in and sends only 16 scrambled numbers per word, never your text.

![Deep mode: layer activity map and live Behaviour scores](docs/demo-deep-behaviour.gif)

## Install and run

```bash
pip install proprioceptive-lens      # no dependencies; Python 3.9+
ollama pull qwen3:4b                 # any chat model works
lens                                 # opens the app in your browser
```

Options: `lens --port 7777 --ollama http://127.0.0.1:11434 --hindsight http://localhost:8888`.

## Deep mode and Behaviour

```bash
pip install "proprioceptive-lens[deep]"
lens --deep Qwen/Qwen2.5-3B-Instruct
```

Deep mode runs a Hugging Face model locally and reads its hidden states. It works with Llama, Qwen, Mistral, Gemma,
Phi, Falcon, Granite, OLMo, SmolLM, DeepSeek and other families. Lens tells Ollama users which command matches the
model they already run. Switch on **Behaviour** in the app to see internal-state probe scores. The app lists which
models have a Behaviour pack; so does [docs/MODELS.md](docs/MODELS.md).

## Proprioceptive Terminal Mode

```bash
lens term                                   # interactive: confidence-coloured output, /why, /memory, /behaviour
lens term -m qwen3:4b "your question"       # one-shot
echo "your question" | lens term --json     # JSON-lines events for scripts and pipelines
```

Events: `memory`, `token` (`text`, `p`, `alternatives`, plus `layers` in deep mode), `behaviour` (score per probe),
`done`. Any OpenAI-compatible client pointed at `http://127.0.0.1:7777/v1` also gets Lens memory.

## Share a prompt

`http://127.0.0.1:7777/?ask=Why%20is%20the%20sky%20blue` opens Lens with the prompt ready to send.

## Privacy

Lens listens only on `127.0.0.1` and rejects requests from other websites. Memories live in
`~/.proprioceptive-lens/memory.sqlite3`. You can view or forget them in the app, or delete the file. Behaviour is off
until you turn it on.

## License

MIT for this client. The Behaviour probes and the scoring service are proprietary to Proprioceptive AI, are not part
of this package, and no licence to them (or to any Proprioceptive AI patent) is granted by this licence.
