cloxy 5.1__tar.gz → 5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cloxy-5.1 → cloxy-5.3}/PKG-INFO +74 -8
- {cloxy-5.1 → cloxy-5.3}/README.md +73 -7
- {cloxy-5.1 → cloxy-5.3}/cloxy/__init__.py +1 -1
- cloxy-5.3/cloxy/backends/__init__.py +11 -0
- cloxy-5.3/cloxy/backends/openai_backend.py +133 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/cli.py +173 -1
- cloxy-5.3/cloxy/cluster.py +131 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/config.py +46 -2
- {cloxy-5.1 → cloxy-5.3}/cloxy/convos.py +98 -17
- cloxy-5.3/cloxy/push.py +220 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/server.py +245 -38
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/PKG-INFO +74 -8
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/SOURCES.txt +6 -1
- {cloxy-5.1 → cloxy-5.3}/tests/test_cli.py +13 -0
- cloxy-5.3/tests/test_cluster.py +177 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_convos.py +80 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_endpoints.py +77 -0
- cloxy-5.3/tests/test_push.py +126 -0
- cloxy-5.1/cloxy/backends/__init__.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/LICENSE +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/__main__.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/backends/mlx_backend.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/catalog.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/hardware.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/mcp_server.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/memory.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy/proxy.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/dependency_links.txt +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/entry_points.txt +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/requires.txt +0 -0
- {cloxy-5.1 → cloxy-5.3}/cloxy.egg-info/top_level.txt +0 -0
- {cloxy-5.1 → cloxy-5.3}/pyproject.toml +0 -0
- {cloxy-5.1 → cloxy-5.3}/setup.cfg +0 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_config.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_mcp.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_memory.py +0 -0
- {cloxy-5.1 → cloxy-5.3}/tests/test_proxy.py +0 -0
{cloxy-5.1 → cloxy-5.3}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloxy
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.3
|
|
4
4
|
Summary: Give your local AI eyes and memory — web proxy, self-maintaining conversation memory, MCP server, and an Apple Silicon LLM in one process.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/roygurner-gif/cloxy
|
|
@@ -43,7 +43,7 @@ Dynamic: license-file
|
|
|
43
43
|
|
|
44
44
|
Cloxy is one process that gives any AI tool three things it doesn't have on its own:
|
|
45
45
|
|
|
46
|
-
- **Memory that keeps itself.** Cloxy watches your Claude Code sessions and ingests them as they happen. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
46
|
+
- **Memory that keeps itself.** Cloxy watches your Claude Code and Codex sessions and ingests them as they happen — one memory shared by every agent you run, on every machine you run them on. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
47
47
|
- **Eyes.** A web proxy that turns any URL into clean text, markdown, or a CSS-selected extract, and a `/verify` endpoint that ranks a page's passages against a claim.
|
|
48
48
|
- **A local LLM** (optional, Apple Silicon). `cloxy init` picks an MLX model that fits your unified memory; `/v1/chat/completions` serves it OpenAI-style — with your memory injected if you want.
|
|
49
49
|
|
|
@@ -67,7 +67,7 @@ pipx install "git+https://github.com/roygurner-gif/cloxy"
|
|
|
67
67
|
## Quick start
|
|
68
68
|
|
|
69
69
|
```bash
|
|
70
|
-
cloxy start # server on http://127.0.0.1:9055 — the watcher
|
|
70
|
+
cloxy start # server on http://127.0.0.1:9055 — the watcher ingests ~/.claude/projects + ~/.codex/sessions
|
|
71
71
|
cloxy status # memories, watcher, index sizes
|
|
72
72
|
cloxy recall "what port does the staging cluster use"
|
|
73
73
|
```
|
|
@@ -99,12 +99,21 @@ CLOXY_URL=http://192.168.1.20:9055
|
|
|
99
99
|
CLOXY_API_KEY=…
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
To feed that server this machine's
|
|
102
|
+
To feed that server this machine's agent sessions too, run `cloxy push` on the client:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
cloxy push # every 10s: send new session lines to CLOXY_URL
|
|
106
|
+
cloxy push --once # one pass (cron / a timer)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
It sends only complete lines that are new since the last pass, tagged with the byte offset they start at, to `POST /push`. The server appends them to a mirror under `~/.cloxy/inbox/<host>/<agent>/` — refusing any slice that doesn't line up, and telling the client where to resume — and its watcher ingests the mirror like local sessions. Same API key as everything else; no ssh, no rsync. `--host` sets the name this machine appears under (default: its hostname).
|
|
103
110
|
|
|
104
111
|
## How memory works
|
|
105
112
|
|
|
106
113
|
```
|
|
107
|
-
~/.claude/projects/**/*.jsonl
|
|
114
|
+
~/.claude/projects/**/*.jsonl ─┐
|
|
115
|
+
~/.codex/sessions/**/*.jsonl ─┼─watcher (5s)──▶ parse new lines from last byte offset
|
|
116
|
+
~/.cloxy/inbox/ (cloxy push) ─┘
|
|
108
117
|
│
|
|
109
118
|
pack whole messages into ~1500-char chunks
|
|
110
119
|
header: [2026-09-12 14:40 · rmbr · Board colors]
|
|
@@ -117,6 +126,7 @@ To feed that server this machine's Claude Code sessions, mirror them into one of
|
|
|
117
126
|
```
|
|
118
127
|
|
|
119
128
|
- **Incremental.** Each session file is tracked by byte offset. Only new lines are read. The last, still-growing chunk is stored so it's searchable immediately and replaced on the next pass.
|
|
129
|
+
- **Every agent.** Claude Code and Codex CLI sessions are recognised per file (by name, else by the first line); harness plumbing — system reminders, Codex's environment/AGENTS.md preamble, tool calls, reasoning — is dropped, and each memory records which `agent` wrote it.
|
|
120
130
|
- **Dated and scoped.** Every memory carries the session's working directory (project), timestamps, git branch, and title. Filter with `project`, `since`, `until`.
|
|
121
131
|
- **Hybrid.** Dense vectors catch meaning; FTS5 catches the exact port number, hostname, or flag that embeddings blur. Results are fused and gently tilted toward recent memories (30-day half-life; `recency_weight` 0–1). The `score` on each hit is the fused rank value (typically 0.01–0.04), so compare hits within one query by order, not by magnitude — it is not a cosine similarity like `/verify` reports.
|
|
122
132
|
- **Asymmetric embeddings.** A short question is embedded differently from the long text it searches. Models trained that way (the E5 family) get their `query: ` / `passage: ` prefixes automatically; fastembed does not add them, and without them E5 recall drops sharply. Override with `CLOXY_EMBED_QUERY_PREFIX` / `CLOXY_EMBED_PASSAGE_PREFIX`.
|
|
@@ -133,6 +143,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
133
143
|
| `POST` | `/ingest_text` | Store any text. `{text, source, project?, metadata?}` |
|
|
134
144
|
| `POST` | `/ingest_convos` | Run an ingest pass now. `{convo_dir?, force?}` |
|
|
135
145
|
| `GET` | `/projects` | Projects present in memory with counts and date ranges |
|
|
146
|
+
| `POST` | `/push` | Receive session lines from `cloxy push`. `{host, agent, path, offset, data (base64, whole lines), replace?}` → `{size}`; 409 + `{size}` if the offset doesn't match |
|
|
136
147
|
| `GET` | `/ingest_status` | Watcher state |
|
|
137
148
|
| `GET` | `/memory_stats` | Counts, sources, index sizes |
|
|
138
149
|
| `DELETE` | `/memory/{id}` | Delete one memory |
|
|
@@ -141,7 +152,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
141
152
|
| `POST` | `/fetch` | Fetch a URL. `{url, mode: clean\|raw\|markdown\|extract, selector?, headers?}` |
|
|
142
153
|
| `POST` | `/search` | Fetch a URL, return lines containing a pattern |
|
|
143
154
|
| `POST` | `/verify` | Fetch a URL, rank passages by semantic match to a claim |
|
|
144
|
-
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat (streaming or not). Extra: `memory`, `memory_top_k`, `memory_project` |
|
|
155
|
+
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat (streaming or not). Extra: `memory`, `memory_top_k`, `memory_project`, `citations` |
|
|
145
156
|
| `GET` | `/v1/models` | The currently loaded model |
|
|
146
157
|
| `GET` | `/health` | Health + watcher summary |
|
|
147
158
|
|
|
@@ -188,12 +199,51 @@ resp = client.chat.completions.create(
|
|
|
188
199
|
print(resp.choices[0].message.content)
|
|
189
200
|
```
|
|
190
201
|
|
|
202
|
+
#### Citations
|
|
203
|
+
|
|
204
|
+
Ask for `"citations": true` (it implies `memory`) and the model is told to cite the injected memories inline as `[1]`, `[2]`. The response gains a `cloxy_citations` object (on the final chunk when streaming):
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"sources": [{"n": 1, "id": 412, "source": "fleischner-2017", "date": "2026-11-01",
|
|
209
|
+
"snippet": "Solid nodule <6 mm, low-risk: no routine follow-up…", "cited": true}],
|
|
210
|
+
"unknown": [],
|
|
211
|
+
"checks": [{"claim": "A 4 mm solid nodule needs no routine follow-up.", "cited": [1],
|
|
212
|
+
"support": {"1": 0.86}, "best_match": 1, "verdict": "ok"}],
|
|
213
|
+
"flagged": 0
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`checks` embeds each cited sentence against every injected source and flags it as `better_match_elsewhere` when a different source fits it better, or `unknown_source` when it cites a number that wasn't given. It catches mis-attributed citations; it does not prove a claim is true — a sentence that misstates its own source can still pass. Load reference material with `POST /ingest_text` (with a descriptive `source`) to make it citable.
|
|
218
|
+
|
|
191
219
|
Continue.dev / Cursor: add an OpenAI-compatible model with base URL `http://localhost:9055/v1` and any API key (or your `CLOXY_API_KEY`).
|
|
192
220
|
|
|
193
221
|
> Claude Code speaks the Anthropic Messages API, not the OpenAI one, so it can't use Cloxy as its *model* — but it uses Cloxy's memory and eyes through MCP (above).
|
|
194
222
|
|
|
195
223
|
Why MLX: it's Apple's framework for the unified-memory architecture, it runs in-process (no daemon, no HTTP hop between proxy and model), and it's fast on M-series parts. Cross-platform inference via `llama-cpp-python` is planned as a separate extra.
|
|
196
224
|
|
|
225
|
+
### A model bigger than one Mac (MLX distributed / JACCL)
|
|
226
|
+
|
|
227
|
+
Shard one model across several Macs with MLX's own distributed stack. Cloxy drives Apple's tools (`mlx.distributed_config`, `mlx.launch`, `mlx_lm server`); it does not shard anything itself:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# every Mac: same python path with cloxy[mlx] installed, passwordless ssh from this one
|
|
231
|
+
cloxy cluster setup --hosts m4-a.local,m4-b.local,m4-c.local --backend jaccl-ring --auto-setup
|
|
232
|
+
cloxy cluster serve --model mlx-community/Qwen3-235B-A22B-4bit # rank 0 = first host, port 9056
|
|
233
|
+
CLOXY_LLM_URL=http://m4-a.local:9056 cloxy start # memory + chat, cluster as the brain
|
|
234
|
+
cloxy cluster status
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
| Backend | Link | When |
|
|
238
|
+
|---|---|---|
|
|
239
|
+
| `jaccl` | RDMA over Thunderbolt 5, every pair of Macs cabled | lowest latency; macOS 26.2+ with RDMA enabled |
|
|
240
|
+
| `jaccl-ring` | RDMA over Thunderbolt 5, each Mac cabled to two neighbours | more Macs than TB ports |
|
|
241
|
+
| `ring` | TCP over any network | always works, slowest |
|
|
242
|
+
|
|
243
|
+
`setup` writes `~/.cloxy/hostfile.json` (RDMA devices per pair); `--auto-setup` lets mlx configure the Thunderbolt interfaces and needs sudo on each Mac. `serve` picks pipeline parallel (layers split, ~1 sync per token) on `ring` and tensor parallel on `jaccl` — tensor syncs every layer of every token, which only pays on RDMA (two M4 minis over Wi-Fi: tensor 0.85 tok/s, pipeline 27–36 tok/s). Override with `--pipeline` / `--tensor`; flags after `--` go to `mlx_lm server` (e.g. `-- --max-tokens 4096`). With `CLOXY_LLM_URL` set, `/v1/chat/completions` injects memory here and forwards to the cluster — no model loads in the cloxy process. The same variable works for any OpenAI-compatible server (Ollama, LM Studio, vLLM).
|
|
244
|
+
|
|
245
|
+
> `mlx_lm server` has no auth; rank 0 binds `0.0.0.0`. Keep the cluster on a private network and expose only cloxy (with `CLOXY_API_KEY`).
|
|
246
|
+
|
|
197
247
|
## CLI
|
|
198
248
|
|
|
199
249
|
```
|
|
@@ -201,10 +251,14 @@ cloxy start [--host H] [--port P] run the server
|
|
|
201
251
|
cloxy mcp MCP stdio server (for editors)
|
|
202
252
|
cloxy recall QUERY [-k N] [--project P] [--since D] [--until D] [--mode M] [--full] [--json]
|
|
203
253
|
cloxy ingest [DIR] [--force] run an ingest pass now
|
|
254
|
+
cloxy push [--once] [--interval S] [--host NAME] mirror this machine's sessions to CLOXY_URL
|
|
204
255
|
cloxy status health, memory, watcher
|
|
205
256
|
cloxy reembed re-embed every memory (after changing model/prefix; server stopped)
|
|
206
257
|
cloxy install-service | uninstall-service launchd (macOS)
|
|
207
258
|
cloxy init | show | list local LLM setup
|
|
259
|
+
cloxy cluster setup --hosts A,B,... [--over thunderbolt|ethernet] [--backend jaccl|jaccl-ring|ring] [--auto-setup]
|
|
260
|
+
cloxy cluster serve [--model ID] [--port P] [--pipeline] [-- MLX_LM_SERVER_FLAGS]
|
|
261
|
+
cloxy cluster status hostfile + whether CLOXY_LLM_URL answers
|
|
208
262
|
```
|
|
209
263
|
|
|
210
264
|
## Configuration
|
|
@@ -220,8 +274,10 @@ Everything is an environment variable.
|
|
|
220
274
|
| `CLOXY_DATA_DIR` | `~/.cloxy` | Database, LLM config, logs, downloaded embedding models (`models/`) |
|
|
221
275
|
| `FASTEMBED_CACHE_PATH` | `$CLOXY_DATA_DIR/models` | Where embedding/reranker models are cached (set explicitly to share an existing cache) |
|
|
222
276
|
| `CLOXY_WATCH` | `1` | Run the conversation watcher |
|
|
223
|
-
| `CLOXY_WATCH_DIRS` | `~/.claude/projects` | Directories to watch (`:`-separated) |
|
|
277
|
+
| `CLOXY_WATCH_DIRS` | `~/.claude/projects:~/.codex/sessions` | Directories to watch (`:`-separated). `~/.cloxy/inbox` is always watched too |
|
|
224
278
|
| `CLOXY_WATCH_INTERVAL` | `5` | Seconds between scans |
|
|
279
|
+
| `CLOXY_PUSH_SOURCES` | `claude=~/.claude/projects,codex=~/.codex/sessions` | What `cloxy push` mirrors, as `agent=dir` pairs |
|
|
280
|
+
| `CLOXY_PUSH_INTERVAL` | `10` | Seconds between `cloxy push` passes |
|
|
225
281
|
| `CLOXY_EMBED_MODEL` | `BAAI/bge-small-en-v1.5` | Embedding model (recorded in the DB; change it, then `cloxy reembed`) |
|
|
226
282
|
| `CLOXY_EMBED_DIM` | `384` | Must match the model |
|
|
227
283
|
| `CLOXY_EMBED_QUERY_PREFIX` | by model | Prepended to every query before embedding (`query: ` for E5, empty otherwise) |
|
|
@@ -230,18 +286,28 @@ Everything is an environment variable.
|
|
|
230
286
|
| `CLOXY_RERANK_MODEL` | `Xenova/ms-marco-MiniLM-L-6-v2` | Reranker |
|
|
231
287
|
| `CLOXY_CHAT_MEMORY` | *(unset)* | `1` to inject memory into every chat completion by default |
|
|
232
288
|
| `CLOXY_CHAT_MEMORY_TOP_K` | `5` | How many memories to inject |
|
|
289
|
+
| `CLOXY_CHAT_CITATIONS` | *(unset)* | `1` to ask for inline `[n]` citations + `cloxy_citations` by default |
|
|
290
|
+
| `CLOXY_CITE_MARGIN` | `0.02` | How much better another source must match before a citation is flagged |
|
|
291
|
+
| `CLOXY_CITE_WINDOW` | `300` | Source window size (chars) for the citation check |
|
|
233
292
|
| `CLOXY_ALLOW_PRIVATE_URLS` | *(unset)* | `1` lets the proxy fetch private/loopback addresses (SSRF risk) |
|
|
234
293
|
| `CLOXY_USER_AGENT` | Chrome UA | User agent for web requests |
|
|
235
294
|
| `CLOXY_FETCH_TIMEOUT` | `30` | Web fetch timeout, seconds |
|
|
236
295
|
| `CLOXY_CONFIG` | `~/.cloxy/config.json` | LLM config written by `cloxy init` |
|
|
237
296
|
| `CLOXY_EAGER_LLM` | *(unset)* | `1` loads the LLM at startup |
|
|
297
|
+
| `CLOXY_LLM_URL` | *(unset)* | Forward chat to this OpenAI-compatible server (e.g. a `cloxy cluster serve` rank 0) instead of in-process MLX |
|
|
298
|
+
| `CLOXY_LLM_API_KEY` | *(unset)* | Sent upstream as `Authorization: Bearer` |
|
|
299
|
+
| `CLOXY_LLM_TIMEOUT` | `600` | Upstream request timeout, seconds |
|
|
300
|
+
| `CLOXY_HOSTFILE` | `~/.cloxy/hostfile.json` | MLX distributed hostfile for `cloxy cluster` |
|
|
301
|
+
| `CLOXY_CLUSTER_BACKEND` | `jaccl` | Backend when neither `--backend` nor the hostfile names one |
|
|
302
|
+
| `CLOXY_CLUSTER_PORT` | `9056` | Port `cloxy cluster serve` gives `mlx_lm server` |
|
|
238
303
|
|
|
239
304
|
## Security
|
|
240
305
|
|
|
241
306
|
- **Loopback by default.** Nothing is reachable off your machine unless you set `CLOXY_HOST=0.0.0.0`.
|
|
242
307
|
- **If you expose it, set an API key.** Otherwise anyone on the network can read and write your memory. The key is compared in constant time.
|
|
243
308
|
- **SSRF guard.** `/fetch`, `/search`, `/verify` resolve the target and refuse private, loopback, link-local, and cloud-metadata addresses — and re-check every redirect hop (max 5). Bodies are streamed and cut at 500 KB; binary content types are refused.
|
|
244
|
-
- **Your transcripts stay local.** The watcher reads
|
|
309
|
+
- **Your transcripts stay local.** The watcher reads the session directories on this machine and writes to `~/.cloxy/memory.db`. They leave it only if you run `cloxy push`, and then only to the `CLOXY_URL` you set. No telemetry.
|
|
310
|
+
- **`/push` writes only inside the inbox.** Host, agent, and every path component are validated; anything that resolves outside `~/.cloxy/inbox` is refused. The only outbound traffic is `/fetch` requests you make and one-time model downloads.
|
|
245
311
|
|
|
246
312
|
## Docker (proxy + memory + MCP; no LLM, no watcher)
|
|
247
313
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Cloxy is one process that gives any AI tool three things it doesn't have on its own:
|
|
6
6
|
|
|
7
|
-
- **Memory that keeps itself.** Cloxy watches your Claude Code sessions and ingests them as they happen. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
7
|
+
- **Memory that keeps itself.** Cloxy watches your Claude Code and Codex sessions and ingests them as they happen — one memory shared by every agent you run, on every machine you run them on. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
8
8
|
- **Eyes.** A web proxy that turns any URL into clean text, markdown, or a CSS-selected extract, and a `/verify` endpoint that ranks a page's passages against a claim.
|
|
9
9
|
- **A local LLM** (optional, Apple Silicon). `cloxy init` picks an MLX model that fits your unified memory; `/v1/chat/completions` serves it OpenAI-style — with your memory injected if you want.
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ pipx install "git+https://github.com/roygurner-gif/cloxy"
|
|
|
28
28
|
## Quick start
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
cloxy start # server on http://127.0.0.1:9055 — the watcher
|
|
31
|
+
cloxy start # server on http://127.0.0.1:9055 — the watcher ingests ~/.claude/projects + ~/.codex/sessions
|
|
32
32
|
cloxy status # memories, watcher, index sizes
|
|
33
33
|
cloxy recall "what port does the staging cluster use"
|
|
34
34
|
```
|
|
@@ -60,12 +60,21 @@ CLOXY_URL=http://192.168.1.20:9055
|
|
|
60
60
|
CLOXY_API_KEY=…
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
To feed that server this machine's
|
|
63
|
+
To feed that server this machine's agent sessions too, run `cloxy push` on the client:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cloxy push # every 10s: send new session lines to CLOXY_URL
|
|
67
|
+
cloxy push --once # one pass (cron / a timer)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
It sends only complete lines that are new since the last pass, tagged with the byte offset they start at, to `POST /push`. The server appends them to a mirror under `~/.cloxy/inbox/<host>/<agent>/` — refusing any slice that doesn't line up, and telling the client where to resume — and its watcher ingests the mirror like local sessions. Same API key as everything else; no ssh, no rsync. `--host` sets the name this machine appears under (default: its hostname).
|
|
64
71
|
|
|
65
72
|
## How memory works
|
|
66
73
|
|
|
67
74
|
```
|
|
68
|
-
~/.claude/projects/**/*.jsonl
|
|
75
|
+
~/.claude/projects/**/*.jsonl ─┐
|
|
76
|
+
~/.codex/sessions/**/*.jsonl ─┼─watcher (5s)──▶ parse new lines from last byte offset
|
|
77
|
+
~/.cloxy/inbox/ (cloxy push) ─┘
|
|
69
78
|
│
|
|
70
79
|
pack whole messages into ~1500-char chunks
|
|
71
80
|
header: [2026-09-12 14:40 · rmbr · Board colors]
|
|
@@ -78,6 +87,7 @@ To feed that server this machine's Claude Code sessions, mirror them into one of
|
|
|
78
87
|
```
|
|
79
88
|
|
|
80
89
|
- **Incremental.** Each session file is tracked by byte offset. Only new lines are read. The last, still-growing chunk is stored so it's searchable immediately and replaced on the next pass.
|
|
90
|
+
- **Every agent.** Claude Code and Codex CLI sessions are recognised per file (by name, else by the first line); harness plumbing — system reminders, Codex's environment/AGENTS.md preamble, tool calls, reasoning — is dropped, and each memory records which `agent` wrote it.
|
|
81
91
|
- **Dated and scoped.** Every memory carries the session's working directory (project), timestamps, git branch, and title. Filter with `project`, `since`, `until`.
|
|
82
92
|
- **Hybrid.** Dense vectors catch meaning; FTS5 catches the exact port number, hostname, or flag that embeddings blur. Results are fused and gently tilted toward recent memories (30-day half-life; `recency_weight` 0–1). The `score` on each hit is the fused rank value (typically 0.01–0.04), so compare hits within one query by order, not by magnitude — it is not a cosine similarity like `/verify` reports.
|
|
83
93
|
- **Asymmetric embeddings.** A short question is embedded differently from the long text it searches. Models trained that way (the E5 family) get their `query: ` / `passage: ` prefixes automatically; fastembed does not add them, and without them E5 recall drops sharply. Override with `CLOXY_EMBED_QUERY_PREFIX` / `CLOXY_EMBED_PASSAGE_PREFIX`.
|
|
@@ -94,6 +104,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
94
104
|
| `POST` | `/ingest_text` | Store any text. `{text, source, project?, metadata?}` |
|
|
95
105
|
| `POST` | `/ingest_convos` | Run an ingest pass now. `{convo_dir?, force?}` |
|
|
96
106
|
| `GET` | `/projects` | Projects present in memory with counts and date ranges |
|
|
107
|
+
| `POST` | `/push` | Receive session lines from `cloxy push`. `{host, agent, path, offset, data (base64, whole lines), replace?}` → `{size}`; 409 + `{size}` if the offset doesn't match |
|
|
97
108
|
| `GET` | `/ingest_status` | Watcher state |
|
|
98
109
|
| `GET` | `/memory_stats` | Counts, sources, index sizes |
|
|
99
110
|
| `DELETE` | `/memory/{id}` | Delete one memory |
|
|
@@ -102,7 +113,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
102
113
|
| `POST` | `/fetch` | Fetch a URL. `{url, mode: clean\|raw\|markdown\|extract, selector?, headers?}` |
|
|
103
114
|
| `POST` | `/search` | Fetch a URL, return lines containing a pattern |
|
|
104
115
|
| `POST` | `/verify` | Fetch a URL, rank passages by semantic match to a claim |
|
|
105
|
-
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat (streaming or not). Extra: `memory`, `memory_top_k`, `memory_project` |
|
|
116
|
+
| `POST` | `/v1/chat/completions` | OpenAI-compatible chat (streaming or not). Extra: `memory`, `memory_top_k`, `memory_project`, `citations` |
|
|
106
117
|
| `GET` | `/v1/models` | The currently loaded model |
|
|
107
118
|
| `GET` | `/health` | Health + watcher summary |
|
|
108
119
|
|
|
@@ -149,12 +160,51 @@ resp = client.chat.completions.create(
|
|
|
149
160
|
print(resp.choices[0].message.content)
|
|
150
161
|
```
|
|
151
162
|
|
|
163
|
+
#### Citations
|
|
164
|
+
|
|
165
|
+
Ask for `"citations": true` (it implies `memory`) and the model is told to cite the injected memories inline as `[1]`, `[2]`. The response gains a `cloxy_citations` object (on the final chunk when streaming):
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"sources": [{"n": 1, "id": 412, "source": "fleischner-2017", "date": "2026-11-01",
|
|
170
|
+
"snippet": "Solid nodule <6 mm, low-risk: no routine follow-up…", "cited": true}],
|
|
171
|
+
"unknown": [],
|
|
172
|
+
"checks": [{"claim": "A 4 mm solid nodule needs no routine follow-up.", "cited": [1],
|
|
173
|
+
"support": {"1": 0.86}, "best_match": 1, "verdict": "ok"}],
|
|
174
|
+
"flagged": 0
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`checks` embeds each cited sentence against every injected source and flags it as `better_match_elsewhere` when a different source fits it better, or `unknown_source` when it cites a number that wasn't given. It catches mis-attributed citations; it does not prove a claim is true — a sentence that misstates its own source can still pass. Load reference material with `POST /ingest_text` (with a descriptive `source`) to make it citable.
|
|
179
|
+
|
|
152
180
|
Continue.dev / Cursor: add an OpenAI-compatible model with base URL `http://localhost:9055/v1` and any API key (or your `CLOXY_API_KEY`).
|
|
153
181
|
|
|
154
182
|
> Claude Code speaks the Anthropic Messages API, not the OpenAI one, so it can't use Cloxy as its *model* — but it uses Cloxy's memory and eyes through MCP (above).
|
|
155
183
|
|
|
156
184
|
Why MLX: it's Apple's framework for the unified-memory architecture, it runs in-process (no daemon, no HTTP hop between proxy and model), and it's fast on M-series parts. Cross-platform inference via `llama-cpp-python` is planned as a separate extra.
|
|
157
185
|
|
|
186
|
+
### A model bigger than one Mac (MLX distributed / JACCL)
|
|
187
|
+
|
|
188
|
+
Shard one model across several Macs with MLX's own distributed stack. Cloxy drives Apple's tools (`mlx.distributed_config`, `mlx.launch`, `mlx_lm server`); it does not shard anything itself:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# every Mac: same python path with cloxy[mlx] installed, passwordless ssh from this one
|
|
192
|
+
cloxy cluster setup --hosts m4-a.local,m4-b.local,m4-c.local --backend jaccl-ring --auto-setup
|
|
193
|
+
cloxy cluster serve --model mlx-community/Qwen3-235B-A22B-4bit # rank 0 = first host, port 9056
|
|
194
|
+
CLOXY_LLM_URL=http://m4-a.local:9056 cloxy start # memory + chat, cluster as the brain
|
|
195
|
+
cloxy cluster status
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
| Backend | Link | When |
|
|
199
|
+
|---|---|---|
|
|
200
|
+
| `jaccl` | RDMA over Thunderbolt 5, every pair of Macs cabled | lowest latency; macOS 26.2+ with RDMA enabled |
|
|
201
|
+
| `jaccl-ring` | RDMA over Thunderbolt 5, each Mac cabled to two neighbours | more Macs than TB ports |
|
|
202
|
+
| `ring` | TCP over any network | always works, slowest |
|
|
203
|
+
|
|
204
|
+
`setup` writes `~/.cloxy/hostfile.json` (RDMA devices per pair); `--auto-setup` lets mlx configure the Thunderbolt interfaces and needs sudo on each Mac. `serve` picks pipeline parallel (layers split, ~1 sync per token) on `ring` and tensor parallel on `jaccl` — tensor syncs every layer of every token, which only pays on RDMA (two M4 minis over Wi-Fi: tensor 0.85 tok/s, pipeline 27–36 tok/s). Override with `--pipeline` / `--tensor`; flags after `--` go to `mlx_lm server` (e.g. `-- --max-tokens 4096`). With `CLOXY_LLM_URL` set, `/v1/chat/completions` injects memory here and forwards to the cluster — no model loads in the cloxy process. The same variable works for any OpenAI-compatible server (Ollama, LM Studio, vLLM).
|
|
205
|
+
|
|
206
|
+
> `mlx_lm server` has no auth; rank 0 binds `0.0.0.0`. Keep the cluster on a private network and expose only cloxy (with `CLOXY_API_KEY`).
|
|
207
|
+
|
|
158
208
|
## CLI
|
|
159
209
|
|
|
160
210
|
```
|
|
@@ -162,10 +212,14 @@ cloxy start [--host H] [--port P] run the server
|
|
|
162
212
|
cloxy mcp MCP stdio server (for editors)
|
|
163
213
|
cloxy recall QUERY [-k N] [--project P] [--since D] [--until D] [--mode M] [--full] [--json]
|
|
164
214
|
cloxy ingest [DIR] [--force] run an ingest pass now
|
|
215
|
+
cloxy push [--once] [--interval S] [--host NAME] mirror this machine's sessions to CLOXY_URL
|
|
165
216
|
cloxy status health, memory, watcher
|
|
166
217
|
cloxy reembed re-embed every memory (after changing model/prefix; server stopped)
|
|
167
218
|
cloxy install-service | uninstall-service launchd (macOS)
|
|
168
219
|
cloxy init | show | list local LLM setup
|
|
220
|
+
cloxy cluster setup --hosts A,B,... [--over thunderbolt|ethernet] [--backend jaccl|jaccl-ring|ring] [--auto-setup]
|
|
221
|
+
cloxy cluster serve [--model ID] [--port P] [--pipeline] [-- MLX_LM_SERVER_FLAGS]
|
|
222
|
+
cloxy cluster status hostfile + whether CLOXY_LLM_URL answers
|
|
169
223
|
```
|
|
170
224
|
|
|
171
225
|
## Configuration
|
|
@@ -181,8 +235,10 @@ Everything is an environment variable.
|
|
|
181
235
|
| `CLOXY_DATA_DIR` | `~/.cloxy` | Database, LLM config, logs, downloaded embedding models (`models/`) |
|
|
182
236
|
| `FASTEMBED_CACHE_PATH` | `$CLOXY_DATA_DIR/models` | Where embedding/reranker models are cached (set explicitly to share an existing cache) |
|
|
183
237
|
| `CLOXY_WATCH` | `1` | Run the conversation watcher |
|
|
184
|
-
| `CLOXY_WATCH_DIRS` | `~/.claude/projects` | Directories to watch (`:`-separated) |
|
|
238
|
+
| `CLOXY_WATCH_DIRS` | `~/.claude/projects:~/.codex/sessions` | Directories to watch (`:`-separated). `~/.cloxy/inbox` is always watched too |
|
|
185
239
|
| `CLOXY_WATCH_INTERVAL` | `5` | Seconds between scans |
|
|
240
|
+
| `CLOXY_PUSH_SOURCES` | `claude=~/.claude/projects,codex=~/.codex/sessions` | What `cloxy push` mirrors, as `agent=dir` pairs |
|
|
241
|
+
| `CLOXY_PUSH_INTERVAL` | `10` | Seconds between `cloxy push` passes |
|
|
186
242
|
| `CLOXY_EMBED_MODEL` | `BAAI/bge-small-en-v1.5` | Embedding model (recorded in the DB; change it, then `cloxy reembed`) |
|
|
187
243
|
| `CLOXY_EMBED_DIM` | `384` | Must match the model |
|
|
188
244
|
| `CLOXY_EMBED_QUERY_PREFIX` | by model | Prepended to every query before embedding (`query: ` for E5, empty otherwise) |
|
|
@@ -191,18 +247,28 @@ Everything is an environment variable.
|
|
|
191
247
|
| `CLOXY_RERANK_MODEL` | `Xenova/ms-marco-MiniLM-L-6-v2` | Reranker |
|
|
192
248
|
| `CLOXY_CHAT_MEMORY` | *(unset)* | `1` to inject memory into every chat completion by default |
|
|
193
249
|
| `CLOXY_CHAT_MEMORY_TOP_K` | `5` | How many memories to inject |
|
|
250
|
+
| `CLOXY_CHAT_CITATIONS` | *(unset)* | `1` to ask for inline `[n]` citations + `cloxy_citations` by default |
|
|
251
|
+
| `CLOXY_CITE_MARGIN` | `0.02` | How much better another source must match before a citation is flagged |
|
|
252
|
+
| `CLOXY_CITE_WINDOW` | `300` | Source window size (chars) for the citation check |
|
|
194
253
|
| `CLOXY_ALLOW_PRIVATE_URLS` | *(unset)* | `1` lets the proxy fetch private/loopback addresses (SSRF risk) |
|
|
195
254
|
| `CLOXY_USER_AGENT` | Chrome UA | User agent for web requests |
|
|
196
255
|
| `CLOXY_FETCH_TIMEOUT` | `30` | Web fetch timeout, seconds |
|
|
197
256
|
| `CLOXY_CONFIG` | `~/.cloxy/config.json` | LLM config written by `cloxy init` |
|
|
198
257
|
| `CLOXY_EAGER_LLM` | *(unset)* | `1` loads the LLM at startup |
|
|
258
|
+
| `CLOXY_LLM_URL` | *(unset)* | Forward chat to this OpenAI-compatible server (e.g. a `cloxy cluster serve` rank 0) instead of in-process MLX |
|
|
259
|
+
| `CLOXY_LLM_API_KEY` | *(unset)* | Sent upstream as `Authorization: Bearer` |
|
|
260
|
+
| `CLOXY_LLM_TIMEOUT` | `600` | Upstream request timeout, seconds |
|
|
261
|
+
| `CLOXY_HOSTFILE` | `~/.cloxy/hostfile.json` | MLX distributed hostfile for `cloxy cluster` |
|
|
262
|
+
| `CLOXY_CLUSTER_BACKEND` | `jaccl` | Backend when neither `--backend` nor the hostfile names one |
|
|
263
|
+
| `CLOXY_CLUSTER_PORT` | `9056` | Port `cloxy cluster serve` gives `mlx_lm server` |
|
|
199
264
|
|
|
200
265
|
## Security
|
|
201
266
|
|
|
202
267
|
- **Loopback by default.** Nothing is reachable off your machine unless you set `CLOXY_HOST=0.0.0.0`.
|
|
203
268
|
- **If you expose it, set an API key.** Otherwise anyone on the network can read and write your memory. The key is compared in constant time.
|
|
204
269
|
- **SSRF guard.** `/fetch`, `/search`, `/verify` resolve the target and refuse private, loopback, link-local, and cloud-metadata addresses — and re-check every redirect hop (max 5). Bodies are streamed and cut at 500 KB; binary content types are refused.
|
|
205
|
-
- **Your transcripts stay local.** The watcher reads
|
|
270
|
+
- **Your transcripts stay local.** The watcher reads the session directories on this machine and writes to `~/.cloxy/memory.db`. They leave it only if you run `cloxy push`, and then only to the `CLOXY_URL` you set. No telemetry.
|
|
271
|
+
- **`/push` writes only inside the inbox.** Host, agent, and every path component are validated; anything that resolves outside `~/.cloxy/inbox` is refused. The only outbound traffic is `/fetch` requests you make and one-time model downloads.
|
|
206
272
|
|
|
207
273
|
## Docker (proxy + memory + MCP; no LLM, no watcher)
|
|
208
274
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""LLM backends: in-process MLX, or an upstream OpenAI-compatible server."""
|
|
2
|
+
from .. import config
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get():
|
|
6
|
+
"""The active backend module. CLOXY_LLM_URL set = upstream (e.g. an MLX cluster)."""
|
|
7
|
+
if config.LLM_URL:
|
|
8
|
+
from . import openai_backend
|
|
9
|
+
return openai_backend
|
|
10
|
+
from . import mlx_backend
|
|
11
|
+
return mlx_backend
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Upstream backend: forward chat to an OpenAI-compatible server (CLOXY_LLM_URL).
|
|
3
|
+
|
|
4
|
+
The main use is an MLX distributed cluster — `cloxy cluster serve` runs
|
|
5
|
+
mlx_lm.server under mlx.launch, so the model is sharded across several Macs
|
|
6
|
+
(JACCL over Thunderbolt 5, or ring over TCP) and rank 0 answers HTTP. Anything
|
|
7
|
+
else that speaks /v1/chat/completions works too (Ollama, LM Studio, vLLM).
|
|
8
|
+
|
|
9
|
+
Same interface as mlx_backend: load_model / is_loaded / current_model /
|
|
10
|
+
generate_chat / stream_chat (yields StreamPiece).
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import time
|
|
16
|
+
from typing import AsyncGenerator, List, Optional
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
from .. import config
|
|
21
|
+
from .mlx_backend import StreamPiece
|
|
22
|
+
|
|
23
|
+
# Tests swap this for an httpx.MockTransport.
|
|
24
|
+
_transport: Optional[httpx.AsyncBaseTransport] = None
|
|
25
|
+
_model_id: Optional[str] = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class UpstreamError(RuntimeError):
|
|
29
|
+
def __init__(self, status: int, detail: str):
|
|
30
|
+
super().__init__(detail)
|
|
31
|
+
self.status = status
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _client() -> httpx.AsyncClient:
|
|
35
|
+
headers = {"Authorization": f"Bearer {config.LLM_API_KEY}"} if config.LLM_API_KEY else {}
|
|
36
|
+
return httpx.AsyncClient(base_url=config.LLM_URL, headers=headers,
|
|
37
|
+
timeout=httpx.Timeout(config.LLM_TIMEOUT, connect=10),
|
|
38
|
+
transport=_transport)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def is_loaded() -> bool:
|
|
42
|
+
return _model_id is not None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def current_model() -> Optional[str]:
|
|
46
|
+
return _model_id
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def load_model(hf_id: Optional[str] = None) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Nothing to load locally: check the upstream answers and remember which model
|
|
52
|
+
to name. The configured id wins; otherwise ask /v1/models. mlx_lm.server
|
|
53
|
+
lists every cached model there, so the configured id is the reliable one.
|
|
54
|
+
"""
|
|
55
|
+
global _model_id
|
|
56
|
+
try:
|
|
57
|
+
async with _client() as c:
|
|
58
|
+
r = await c.get("/v1/models")
|
|
59
|
+
except httpx.HTTPError as e:
|
|
60
|
+
raise UpstreamError(503, f"LLM upstream {config.LLM_URL} unreachable: {e}") from e
|
|
61
|
+
if r.status_code != 200:
|
|
62
|
+
raise UpstreamError(503, f"LLM upstream {config.LLM_URL} returned HTTP {r.status_code}")
|
|
63
|
+
if hf_id:
|
|
64
|
+
_model_id = hf_id
|
|
65
|
+
return
|
|
66
|
+
data = (r.json() or {}).get("data") or []
|
|
67
|
+
_model_id = data[0]["id"] if data else "upstream"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _body(messages, max_tokens, temperature, top_p, stream: bool) -> dict:
|
|
71
|
+
# No "model" field: mlx_lm.server would try to load whatever we name, which
|
|
72
|
+
# a sharded cluster can't do mid-flight. Omitted = the model it was started with.
|
|
73
|
+
body = {"messages": messages, "max_tokens": max_tokens,
|
|
74
|
+
"temperature": temperature, "top_p": top_p, "stream": stream}
|
|
75
|
+
if stream:
|
|
76
|
+
body["stream_options"] = {"include_usage": True}
|
|
77
|
+
return body
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def generate_chat(messages: List[dict], max_tokens: int = 512,
|
|
81
|
+
temperature: float = 0.7, top_p: float = 0.95) -> dict:
|
|
82
|
+
started = time.perf_counter()
|
|
83
|
+
try:
|
|
84
|
+
async with _client() as c:
|
|
85
|
+
r = await c.post("/v1/chat/completions",
|
|
86
|
+
json=_body(messages, max_tokens, temperature, top_p, False))
|
|
87
|
+
except httpx.HTTPError as e:
|
|
88
|
+
raise UpstreamError(502, f"LLM upstream error: {e}") from e
|
|
89
|
+
if r.status_code != 200:
|
|
90
|
+
raise UpstreamError(502, f"LLM upstream returned HTTP {r.status_code}: {r.text[:300]}")
|
|
91
|
+
out = r.json()
|
|
92
|
+
elapsed = time.perf_counter() - started
|
|
93
|
+
out["model"] = _model_id or out.get("model")
|
|
94
|
+
toks = (out.get("usage") or {}).get("completion_tokens")
|
|
95
|
+
out["cloxy_meta"] = {
|
|
96
|
+
"elapsed_seconds": round(elapsed, 3),
|
|
97
|
+
"tokens_per_second": round(toks / elapsed, 2) if toks and elapsed > 0 else None,
|
|
98
|
+
"upstream": config.LLM_URL,
|
|
99
|
+
}
|
|
100
|
+
return out
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async def stream_chat(messages: List[dict], max_tokens: int = 512,
|
|
104
|
+
temperature: float = 0.7, top_p: float = 0.95,
|
|
105
|
+
) -> AsyncGenerator[StreamPiece, None]:
|
|
106
|
+
"""Relay the upstream SSE stream as StreamPiece fragments."""
|
|
107
|
+
finish, usage = None, None
|
|
108
|
+
try:
|
|
109
|
+
async with _client() as c:
|
|
110
|
+
async with c.stream("POST", "/v1/chat/completions",
|
|
111
|
+
json=_body(messages, max_tokens, temperature, top_p, True)) as r:
|
|
112
|
+
if r.status_code != 200:
|
|
113
|
+
detail = (await r.aread()).decode(errors="replace")[:300]
|
|
114
|
+
raise UpstreamError(502, f"LLM upstream returned HTTP {r.status_code}: {detail}")
|
|
115
|
+
async for line in r.aiter_lines():
|
|
116
|
+
if not line.startswith("data:"):
|
|
117
|
+
continue
|
|
118
|
+
payload = line[5:].strip()
|
|
119
|
+
if payload == "[DONE]":
|
|
120
|
+
break
|
|
121
|
+
try:
|
|
122
|
+
chunk = json.loads(payload)
|
|
123
|
+
except json.JSONDecodeError:
|
|
124
|
+
continue
|
|
125
|
+
usage = chunk.get("usage") or usage
|
|
126
|
+
for choice in chunk.get("choices") or []:
|
|
127
|
+
text = (choice.get("delta") or {}).get("content")
|
|
128
|
+
if text:
|
|
129
|
+
yield StreamPiece(text=text)
|
|
130
|
+
finish = choice.get("finish_reason") or finish
|
|
131
|
+
except httpx.HTTPError as e:
|
|
132
|
+
raise UpstreamError(502, f"LLM upstream error: {e}") from e
|
|
133
|
+
yield StreamPiece(text="", finish_reason=finish or "stop", usage=usage)
|