neohorse-kit 0.1.0__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.
- neohorse_kit-0.1.0/.agents/skills/neohorse-kit/SKILL.md +86 -0
- neohorse_kit-0.1.0/.github/workflows/ci.yml +34 -0
- neohorse_kit-0.1.0/.github/workflows/release.yml +30 -0
- neohorse_kit-0.1.0/.gitignore +9 -0
- neohorse_kit-0.1.0/LICENSE +21 -0
- neohorse_kit-0.1.0/PKG-INFO +372 -0
- neohorse_kit-0.1.0/README.md +358 -0
- neohorse_kit-0.1.0/docs/readme/README.zh-CN.md +350 -0
- neohorse_kit-0.1.0/pyproject.toml +33 -0
- neohorse_kit-0.1.0/src/neohorse_kit/__init__.py +55 -0
- neohorse_kit-0.1.0/src/neohorse_kit/cli.py +143 -0
- neohorse_kit-0.1.0/src/neohorse_kit/client.py +629 -0
- neohorse_kit-0.1.0/src/neohorse_kit/mcp_server.py +107 -0
- neohorse_kit-0.1.0/src/neohorse_kit/presets.py +94 -0
- neohorse_kit-0.1.0/src/neohorse_kit/skills/neohorse-kit/SKILL.md +86 -0
- neohorse_kit-0.1.0/src/neohorse_kit/types.py +220 -0
- neohorse_kit-0.1.0/tests/test_cli.py +33 -0
- neohorse_kit-0.1.0/tests/test_client.py +558 -0
- neohorse_kit-0.1.0/tests/test_types.py +117 -0
- neohorse_kit-0.1.0/uv.lock +893 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: neohorse-kit
|
|
3
|
+
description: Judge text or JSON with the NeoHorse JEV decision API (Token
|
|
4
|
+
Rhythm) — probability-based yes/no scores (noul), label routing (choice), ordered
|
|
5
|
+
ratings (score), and single-question PNG image judging; presets for
|
|
6
|
+
urgency/sentiment/severity/priority. Use when scoring, routing, triaging,
|
|
7
|
+
grading or deciding on text, JSON records, or one image.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# neohorse-kit — NeoHorse JEV decisions for agents
|
|
11
|
+
|
|
12
|
+
Prefer the MCP tools (`decide`, `ask`, `list_models`) when they are available
|
|
13
|
+
in this session. Otherwise use the CLI or Python below.
|
|
14
|
+
|
|
15
|
+
## Setup (once)
|
|
16
|
+
|
|
17
|
+
- Needs `NEOHORSE_API_KEYS` (comma-separated key pool) or `NEOHORSE_API_KEY`
|
|
18
|
+
in the environment. Keys look like `sk_...`; get one from the Token Rhythm
|
|
19
|
+
console (https://tokenrhythm.studio). The JEV model is grayscale-gated: a
|
|
20
|
+
key without access answers 403.
|
|
21
|
+
- No install needed: `uvx neohorse-kit ...`. Persistent: `pip install neohorse-kit`.
|
|
22
|
+
|
|
23
|
+
## Judging via CLI
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
uvx neohorse-kit "路口信号灯为红色,前方有行人。" # urgency preset (noul 0..1)
|
|
27
|
+
uvx neohorse-kit "TEXT" --ask "现在是否应停车?" --kind noul
|
|
28
|
+
uvx neohorse-kit "TEXT" --ask "危险程度?" --kind score --levels 低 中 高
|
|
29
|
+
uvx neohorse-kit "TEXT" --ask "应该走哪条路线?" --kind choice --options left:"左转" straight:"直行"
|
|
30
|
+
uvx neohorse-kit photo.png --image --ask "这张图片里有猫吗?" # one PNG, one question
|
|
31
|
+
uvx neohorse-kit --models # key health check
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Output JSON: `answers.<name>.noul` / `.choice` / `.score`, with
|
|
35
|
+
`probabilities` and (except noul) `confidence`.
|
|
36
|
+
|
|
37
|
+
## Choosing the question type
|
|
38
|
+
|
|
39
|
+
- Yes/no decision → `noul`. Ask one concrete question — "现在是否应停车?",
|
|
40
|
+
never "分析这段文本".
|
|
41
|
+
- Routing among labels → `choice` (1..255 options); `criteria` maps each label
|
|
42
|
+
to a short description.
|
|
43
|
+
- Ordered intensity → `score` (2..10 levels); `criteria` lists levels from low
|
|
44
|
+
to high.
|
|
45
|
+
|
|
46
|
+
## Limits (the API answers 422 when exceeded)
|
|
47
|
+
|
|
48
|
+
- 1..16 questions per text call; image calls take exactly 1 question.
|
|
49
|
+
- `image` is a top-level PNG base64 data URL; body ≤ 1 MiB (≤ 8 MiB with an
|
|
50
|
+
image). Pass a path or bytes and neohorse-kit converts it.
|
|
51
|
+
- JEV is a decision model: never call it through `/v1/chat/completions`.
|
|
52
|
+
|
|
53
|
+
## Batching (Python — one upstream call for many questions)
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from neohorse_kit import NeoHorseClient, presets
|
|
57
|
+
|
|
58
|
+
client = NeoHorseClient()
|
|
59
|
+
r = client.decide(state, [presets.urgency(), presets.priority()])
|
|
60
|
+
r.answers["priority"].choice # typed answers, IDE-completable
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Custom questions:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from neohorse_kit.types import Choice, Score
|
|
67
|
+
Choice(instructions="Which lane?", criteria={"left": "turn", "straight": None})
|
|
68
|
+
Score(instructions="Risk?", criteria=["low", "medium", "high"])
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`state` may be any JSON object, not just text — pass structured records
|
|
72
|
+
directly. `client.decide(state, q, endpoint="systemone")` switches to the
|
|
73
|
+
System One compatible response shape.
|
|
74
|
+
|
|
75
|
+
## Reading results
|
|
76
|
+
|
|
77
|
+
Probabilities are not verdicts, and the platform docs say explicitly they are
|
|
78
|
+
not calibrated correctness rates: pick a threshold that suits the task (e.g.
|
|
79
|
+
`noul > 0.8` means act) instead of trusting a single answer blindly.
|
|
80
|
+
`/v1/decision` reports packed `input_tokens`; `/v1/systemone` reports
|
|
81
|
+
`usage.input_tokens` / `usage.output_tokens`.
|
|
82
|
+
|
|
83
|
+
## Cost care
|
|
84
|
+
|
|
85
|
+
Identical requests are served from an LRU cache. Pass `--no-cache` (CLI) or
|
|
86
|
+
`cache_size=0` (Python) when you need a genuinely fresh call.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
14
|
+
python: ["3.11", "3.12", "3.13"]
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: astral-sh/setup-uv@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python }}
|
|
21
|
+
enable-cache: true
|
|
22
|
+
- run: uv sync
|
|
23
|
+
- run: uv run pytest -q
|
|
24
|
+
|
|
25
|
+
build:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
- uses: astral-sh/setup-uv@v5
|
|
30
|
+
- run: uv build
|
|
31
|
+
- uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Push a tag (v0.1.0) to run tests, publish to PyPI and create a GitHub Release.
|
|
4
|
+
# PyPI auth uses Trusted Publishing: configure the "pending publisher" once at
|
|
5
|
+
# https://pypi.org/manage/account/publishing/ (owner: lincong1987, repository:
|
|
6
|
+
# neohorse-kit, workflow: release.yml, environment: empty) — no API token needed.
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags: ["v*"]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
release:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
id-token: write # PyPI Trusted Publishing
|
|
17
|
+
contents: write # GitHub Release
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: astral-sh/setup-uv@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
- run: uv sync
|
|
24
|
+
- run: uv run pytest -q
|
|
25
|
+
- run: uv build
|
|
26
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
27
|
+
- uses: softprops/action-gh-release@v2
|
|
28
|
+
with:
|
|
29
|
+
files: dist/*
|
|
30
|
+
generate_release_notes: true
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 neohorse-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: neohorse-kit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Community toolkit for the NeoHorse JEV decision API (Token Rhythm): multi-key client with caching and metering, typed questions/answers, presets, CLI and MCP server
|
|
5
|
+
Project-URL: Repository, https://github.com/lincong1987/neohorse-kit
|
|
6
|
+
Project-URL: Issues, https://github.com/lincong1987/neohorse-kit/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/lincong1987/neohorse-kit/releases
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: httpx>=0.27
|
|
12
|
+
Requires-Dist: mcp>=1.2
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
|
|
17
|
+
**English** · [简体中文](docs/readme/README.zh-CN.md)
|
|
18
|
+
|
|
19
|
+
# neohorse-kit: Production-Grade NeoHorse JEV Decision Toolkit
|
|
20
|
+
|
|
21
|
+
### Multi-Key Failover · Deterministic LRU Cache · Typed Questions · CLI & Native MCP Server
|
|
22
|
+
|
|
23
|
+
**Turn NeoHorse JEV into a production decision layer — explicit probability scores with a ~50 ms decision time, zero 401/403/429 downtime, zero redundant bills.**
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/neohorse-kit/)
|
|
26
|
+
[](https://pypi.org/project/neohorse-kit/)
|
|
27
|
+
[](https://modelcontextprotocol.io/)
|
|
28
|
+
[](https://agentskills.io)
|
|
29
|
+
[](https://github.com/lincong1987/neohorse-kit/actions)
|
|
30
|
+
[](LICENSE)
|
|
31
|
+
|
|
32
|
+
<br />
|
|
33
|
+
|
|
34
|
+
<code>pip install neohorse-kit</code> · <code>uvx neohorse-kit-mcp</code>
|
|
35
|
+
|
|
36
|
+
<br /><br />
|
|
37
|
+
|
|
38
|
+
[Quick Start](#quick-start) · [Architecture & How It Works](#architecture--how-it-works) · [Three Question Types](#three-question-types) · [Image Questions](#image-questions) · [Two Endpoints](#two-endpoints) · [Agent Setup (MCP & Skill)](#agent-setup-mcp--skill) · [FAQ](#faq)
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
> [!IMPORTANT]
|
|
43
|
+
> **Community Project**: This repository is an independent open-source production-readiness suite and is not affiliated with or endorsed by 基元律动 (Token Rhythm). The NeoHorse JEV decision API is a product of [基元律动 Token Rhythm](https://tokenrhythm.studio) — thanks to the team for providing the free grayscale test model. Install only from official releases on PyPI ([`neohorse-kit`](https://pypi.org/project/neohorse-kit/)) and GitHub ([`lincong1987/neohorse-kit`](https://github.com/lincong1987/neohorse-kit)). API docs: <https://tokenrhythm.studio/docs/api-integration>.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Understand neohorse-kit in 3 Seconds
|
|
48
|
+
|
|
49
|
+
When agents route tickets, moderate content, triage reports, or take branch actions, chat LLMs are **slow, token-hungry, and their confidence scores are not real probabilities**. A decision model exists precisely for this: [基元律动 Token Rhythm](https://tokenrhythm.studio)'s **NeoHorse JEV 4B** answers structured questions with an **explicit probability distribution** (top-level `decision_seconds` ≈ 50 ms on `/v1/decision`).
|
|
50
|
+
|
|
51
|
+
**However, running JEV in production or agent loops introduces real operational friction:**
|
|
52
|
+
|
|
53
|
+
* 🛑 **401 / 403 / 429 crashes**: a key without grayscale access (403), an expired key (401), or a capacity-limited key (429) abruptly halts your agent loop;
|
|
54
|
+
* 💸 **Redundant billing & latency**: re-running duplicate tickets or regression suites burns upstream credits and adds hundreds of milliseconds;
|
|
55
|
+
* 🧩 **Friction for AI Agents**: hand-writing raw JSON payloads is tedious, and there is no standard MCP/Skill integration;
|
|
56
|
+
* 📐 **Silent protocol traps**: 16-question caps, image-implies-one-question, body-size limits — a bare upstream `422 JEV_INVALID_REQUEST` tells you nothing.
|
|
57
|
+
|
|
58
|
+
**`neohorse-kit` is the production operations layer for JEV:**
|
|
59
|
+
|
|
60
|
+
* 🔑 **Multi-key pool & zero-downtime failover**: 401/403 (dead key or missing grayscale) and 429 (capacity) hot-swap to the next key mid-request.
|
|
61
|
+
* ⚡ **Deterministic LRU cache**: identical requests (same `model` + `state` + `questions` + `image`) are served from memory in ~0.1 ms at $0 upstream cost.
|
|
62
|
+
* 📦 **1..16 questions in ONE round trip**: batch urgency, severity, routing and risk into a single HTTP payload.
|
|
63
|
+
* 🖼️ **Image questions**: attach one PNG per call — pass bytes or a path, the kit builds the data URL and enforces the one-question rule.
|
|
64
|
+
* 📐 **Protocol guards**: documented limits are checked client-side with actionable errors before a request is spent.
|
|
65
|
+
* 📊 **Per-key metering**: calls / input / output tokens per key, split by each endpoint's own token convention.
|
|
66
|
+
* 🤖 **Turnkey MCP server & Agent Skill**: `uvx neohorse-kit-mcp` and `neohorse-kit --install-skill` work out of the box.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
### 1. Installation & Environment
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install neohorse-kit # or: uv add neohorse-kit
|
|
76
|
+
|
|
77
|
+
# Configure a pool of keys (comma-separated; automatically fails over on 401 / 403 / 429)
|
|
78
|
+
export NEOHORSE_API_KEYS="sk_tr_prod_1...,sk_tr_prod_2..."
|
|
79
|
+
# Or a single key: export NEOHORSE_API_KEY="sk_tr_..."
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> Get keys from the [Token Rhythm console](https://tokenrhythm.studio). JEV is currently **grayscale-gated**: a key without access gets `403` — keep such a key in the pool anyway, the kit rotates off it instantly.
|
|
83
|
+
|
|
84
|
+
### 2. Python Usage
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from neohorse_kit import NeoHorseClient, presets
|
|
88
|
+
|
|
89
|
+
# Defaults to NeoHorse-Jev-4B on /v1/decision, loads the NEOHORSE_API_KEYS pool
|
|
90
|
+
client = NeoHorseClient()
|
|
91
|
+
|
|
92
|
+
# ① Binary question -> probability of YES (0..1)
|
|
93
|
+
res = client.decide("路口信号灯为红色,前方有行人。", presets.urgency())
|
|
94
|
+
print(f"Urgency probability: {res.answers['is_urgent'].noul:.4f}")
|
|
95
|
+
# e.g. 0.9896
|
|
96
|
+
|
|
97
|
+
# ② Batch questions on arbitrary JSON state (ONE HTTP roundtrip)
|
|
98
|
+
ticket = {
|
|
99
|
+
"ticket_id": "#4096",
|
|
100
|
+
"customer_tier": "Enterprise",
|
|
101
|
+
"title": "Database connection pool exhausted during peak sales",
|
|
102
|
+
}
|
|
103
|
+
batch = client.decide(ticket, [
|
|
104
|
+
presets.urgency(), # noul 0..1
|
|
105
|
+
presets.severity(), # score 0..3 (expected level)
|
|
106
|
+
presets.priority(), # choice low/medium/high/urgent
|
|
107
|
+
])
|
|
108
|
+
print("Severity:", batch.answers["severity"].score) # e.g. 2.78
|
|
109
|
+
print("Priority:", batch.answers["priority"].choice) # e.g. "urgent"
|
|
110
|
+
print("Per-key usage:", client.usage)
|
|
111
|
+
# {'sk_tr_prod_1…': {'calls': 2, 'input_tokens': 168, 'output_tokens': 0}, ...}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
> **Async native**: `from neohorse_kit import AsyncNeoHorseClient` — 100% feature parity in async event loops.
|
|
115
|
+
|
|
116
|
+
### 3. Command Line Interface
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Default urgency check (clean JSON output)
|
|
120
|
+
neohorse-kit "Payment checkout API returning 500 error"
|
|
121
|
+
|
|
122
|
+
# Noul decision
|
|
123
|
+
neohorse-kit "路口信号灯为红色,前方有行人。" --ask "现在是否应停车?" --kind noul
|
|
124
|
+
|
|
125
|
+
# Choice routing with a full probability distribution
|
|
126
|
+
neohorse-kit "I want an immediate refund, you billed me twice!" \
|
|
127
|
+
--ask "What department should handle this?" \
|
|
128
|
+
--kind choice \
|
|
129
|
+
--options billing:"payment, refund, billing issues" technical:"bugs and downtime"
|
|
130
|
+
|
|
131
|
+
# Score rating
|
|
132
|
+
neohorse-kit "I have been waiting for two weeks with no reply. Unacceptable!" \
|
|
133
|
+
--ask "How angry is the customer?" --kind score --levels calm annoyed angry furious
|
|
134
|
+
|
|
135
|
+
# Image question (one PNG, one question)
|
|
136
|
+
neohorse-kit photo.png --image --ask "这张图片里有猫吗?"
|
|
137
|
+
|
|
138
|
+
# System One compatible response shape
|
|
139
|
+
neohorse-kit "TEXT" --endpoint systemone
|
|
140
|
+
|
|
141
|
+
# Key health check (model catalog)
|
|
142
|
+
neohorse-kit --models
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Architecture & How It Works
|
|
148
|
+
|
|
149
|
+
`neohorse-kit` sits between your application/agents and the JEV endpoints
|
|
150
|
+
(`POST /v1/decision`, `POST /v1/systemone`):
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
Your code ──► neohorse-kit ──► key pool rotation + retry/backoff ──► https://tokenrhythm.studio/v1
|
|
154
|
+
│
|
|
155
|
+
├─ LRU cache (sha256 of the full payload) ── hit? return in ~0.1 ms, $0
|
|
156
|
+
├─ protocol guards (1..16 questions, image rules, body caps)
|
|
157
|
+
└─ per-key usage metering
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Failover & Resilience Matrix
|
|
161
|
+
|
|
162
|
+
| Error Type | Trigger | neohorse-kit Behavior |
|
|
163
|
+
|---|---|---|
|
|
164
|
+
| **401** | Invalid or expired platform key | **Instant rotation** to the next key |
|
|
165
|
+
| **403** | Key lacks JEV grayscale access | **Instant rotation** to the next key |
|
|
166
|
+
| **429** | Capacity rate limit (multi-key pool) | **Instant rotation**, no downtime |
|
|
167
|
+
| **429** | Capacity rate limit (single key) | Respects `Retry-After` with exponential backoff & jitter |
|
|
168
|
+
| **408 / 5xx / network timeout** | Upstream blip | Exponential backoff + jitter within a 30 s budget, then rotates |
|
|
169
|
+
| **413 / 422 / other 4xx** | Body over limit or bad payload | Raises `NeoHorseBadRequest` immediately (no wasteful retries); the platform `traceId` is attached |
|
|
170
|
+
|
|
171
|
+
Errors carry the platform's `code` / `message` / `traceId` — keep the traceId when filing an issue with Token Rhythm.
|
|
172
|
+
|
|
173
|
+
### Deterministic Cache
|
|
174
|
+
|
|
175
|
+
JEV answers are deterministic for identical input, so the kit caches by a
|
|
176
|
+
sha256 of the canonical request payload (image data URL included):
|
|
177
|
+
|
|
178
|
+
```text
|
|
179
|
+
First call: ~300-400 ms (network round trip + ~50 ms decision; billed once)
|
|
180
|
+
Second call: ~0.1 ms (memory hit, $0 cost)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
> Pass `cache_size=0` (Python) or `--no-cache` (CLI) to force fresh calls.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Three Question Types
|
|
188
|
+
|
|
189
|
+
JEV answers with explicit probability distributions across three question models:
|
|
190
|
+
|
|
191
|
+
```mermaid
|
|
192
|
+
flowchart LR
|
|
193
|
+
Input["state (text or JSON)"] --> Engine["NeoHorse JEV 4B"]
|
|
194
|
+
Engine --> Q1["noul: binary probability 0..1"]
|
|
195
|
+
Engine --> Q2["choice: label + distribution + confidence"]
|
|
196
|
+
Engine --> Q3["score: expected level + distribution + confidence"]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 1. `noul` — Binary Probability
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from neohorse_kit import presets
|
|
203
|
+
|
|
204
|
+
q = presets.noul("用户是否要求退款?", true="explicit refund request or payment dispute")
|
|
205
|
+
res = client.decide("Your tool is completely broken, refund my card right now!", q)
|
|
206
|
+
print(res.answers["answer"].noul) # 0.9821
|
|
207
|
+
print(res.answers["answer"].probabilities) # {"false": 0.018, "true": 0.982} on /v1/decision
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 2. `choice` — Categorical Classification (1..255 options)
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
q = presets.choice("What domain does this ticket belong to?", {
|
|
214
|
+
"billing": "Invoices, double charges, payment methods, refunds",
|
|
215
|
+
"technical": "Server 500, bugs, network downtime, crashes",
|
|
216
|
+
"account": "Password reset, email changes, profile settings",
|
|
217
|
+
})
|
|
218
|
+
res = client.decide("I forgot my password and my registered email is deactivated.", q)
|
|
219
|
+
ans = res.answers["answer"]
|
|
220
|
+
print(ans.choice) # "account"
|
|
221
|
+
print(ans.confidence) # 0.9412
|
|
222
|
+
print(ans.probabilities) # {'account': 0.96, 'billing': 0.02, 'technical': 0.02}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 3. `score` — Ordered Level Rating (2..10 levels)
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
q = presets.score("How angry is the customer?", ["calm", "annoyed", "angry", "furious"])
|
|
229
|
+
res = client.decide("This is the third time I am reporting this. Why has nobody fixed it?!", q)
|
|
230
|
+
ans = res.answers["answer"]
|
|
231
|
+
print(ans.score) # 1.68 (expected level: between annoyed(1) and angry(2))
|
|
232
|
+
print(ans.levels) # ['calm', 'annoyed', 'angry', 'furious'] (works for list or dict legend)
|
|
233
|
+
print(ans.probabilities) # {'0': 0.05, '1': 0.27, '2': 0.55, '3': 0.13}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
> [!TIP]
|
|
237
|
+
> **Probabilities are not verdicts — and not correctness rates**: the platform docs say explicitly that the scores and `confidence` are *not* calibrated correctness rates. Pick your own thresholds to match your SLA — `noul > 0.85` auto-escalate, `0.50..0.85` human review, `< 0.50` automated handling.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Image Questions
|
|
242
|
+
|
|
243
|
+
Attach one PNG per call via the top-level `image` field. Pass bytes, a path,
|
|
244
|
+
or a ready data URL — the kit converts and validates:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from pathlib import Path
|
|
248
|
+
from neohorse_kit import presets
|
|
249
|
+
|
|
250
|
+
res = client.decide("上传的图片", presets.noul("这张图片里有猫吗?"), image=Path("cat.png"))
|
|
251
|
+
print(res.answers["answer"].noul) # 0.9992
|
|
252
|
+
print(res.input_details["image_tokens"]) # 64
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Rules (enforced client-side before spending a request):
|
|
256
|
+
|
|
257
|
+
* exactly **one** question when an image is present;
|
|
258
|
+
* PNG only, as a base64 data URL;
|
|
259
|
+
* body ≤ **1 MiB** without an image, ≤ **8 MiB** with one (image excluded, the rest must still fit 1 MiB);
|
|
260
|
+
* no silent truncation — oversized input comes back as `422`.
|
|
261
|
+
|
|
262
|
+
CLI:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
neohorse-kit photo.png --image --ask "这张图片里有猫吗?"
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Two Endpoints
|
|
271
|
+
|
|
272
|
+
Both endpoints take the **same request body**; they differ in the response
|
|
273
|
+
shape and token accounting:
|
|
274
|
+
|
|
275
|
+
| | `POST /v1/decision` (default) | `POST /v1/systemone` |
|
|
276
|
+
|---|---|---|
|
|
277
|
+
| Answers | same three types; `noul` also carries `probabilities` | same; `choice`/`score` carry `confidence` |
|
|
278
|
+
| Tokens | top-level `input_tokens`, falling back to `input_details.expanded_tokens` | `usage.input_tokens` + `usage.output_tokens` (serialized-answer length) |
|
|
279
|
+
| Extras | `input_details`, `batch_stats`, `probability_source`, `decision_seconds` | `extensions` (backend, definitions) |
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
# Per-call override, or construct with endpoint="systemone"
|
|
283
|
+
r = client.decide(state, questions, endpoint="systemone")
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`neohorse-kit` never calls JEV through `/v1/chat/completions` — it is a
|
|
287
|
+
decision model, not a chat model.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Agent Setup (MCP & Skill)
|
|
292
|
+
|
|
293
|
+
### 1. MCP Server
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
claude mcp add neohorse uvx neohorse-kit-mcp -e NEOHORSE_API_KEYS=sk_tr_prod_1...,sk_tr_prod_2...
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Or in any MCP client config (`~/.claude.json`, `.cursor/mcp.json`, Zed settings, ...):
|
|
300
|
+
|
|
301
|
+
```json
|
|
302
|
+
{
|
|
303
|
+
"mcpServers": {
|
|
304
|
+
"neohorse": {
|
|
305
|
+
"command": "uvx",
|
|
306
|
+
"args": ["neohorse-kit-mcp"],
|
|
307
|
+
"env": {"NEOHORSE_API_KEYS": "sk_tr_prod_1...,sk_tr_prod_2..."}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Tools: `decide` (batch), `ask` (single question), `list_models` (key health check).
|
|
314
|
+
|
|
315
|
+
### 2. Agent Skill
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
npx skills add lincong1987/neohorse-kit # via skills.sh
|
|
319
|
+
# or, with the package installed:
|
|
320
|
+
neohorse-kit --install-skill # ~/.agents/skills/neohorse-kit/SKILL.md
|
|
321
|
+
neohorse-kit --install-skill --claude # ~/.claude/skills/neohorse-kit/SKILL.md
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## FAQ
|
|
327
|
+
|
|
328
|
+
<details>
|
|
329
|
+
<summary><strong>Q: Which model does neohorse-kit call?</strong></summary>
|
|
330
|
+
|
|
331
|
+
`NeoHorse-Jev-4B`, the only JEV decision model (fixed ID per the platform docs). It does not appear in `GET /v1/models` — that catalog lists chat models, and `neohorse-kit --models` doubles as a key health check.
|
|
332
|
+
</details>
|
|
333
|
+
|
|
334
|
+
<details>
|
|
335
|
+
<summary><strong>Q: My key works for chat models but gets 403 on decisions?</strong></summary>
|
|
336
|
+
|
|
337
|
+
JEV is grayscale-gated: the key needs the JEV permission *and* the account must be on the grayscale list. Keep such keys in the pool — the kit rotates off them instantly, but a single such key will still fail fast with the platform's `traceId`.
|
|
338
|
+
</details>
|
|
339
|
+
|
|
340
|
+
<details>
|
|
341
|
+
<summary><strong>Q: Where do I put API keys?</strong></summary>
|
|
342
|
+
|
|
343
|
+
`NEOHORSE_API_KEYS` (comma-separated) or `NEOHORSE_API_KEY`, or the `env` block of the MCP server config. Never hardcode keys in source code — and never commit them.
|
|
344
|
+
</details>
|
|
345
|
+
|
|
346
|
+
<details>
|
|
347
|
+
<summary><strong>Q: Are the probabilities correctness rates?</strong></summary>
|
|
348
|
+
|
|
349
|
+
No. The docs are explicit: probabilities and `confidence` are **not calibrated correctness rates** (the `systemone` `extensions` even flag the confidence formula as unverified). Treat them as risk measures and set your own thresholds.
|
|
350
|
+
</details>
|
|
351
|
+
|
|
352
|
+
<details>
|
|
353
|
+
<summary><strong>Q: What happens when every key is rate-limited?</strong></summary>
|
|
354
|
+
|
|
355
|
+
The kit cycles the pool, then applies exponential backoff with jitter honouring `Retry-After` within a 30 s budget (default). If nothing recovers, it raises with the last upstream error and its `traceId`.
|
|
356
|
+
</details>
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Contributing
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
git clone https://github.com/lincong1987/neohorse-kit.git
|
|
364
|
+
cd neohorse-kit
|
|
365
|
+
|
|
366
|
+
uv sync
|
|
367
|
+
uv run pytest --basetemp=.tmp/pytest # 100% mocked; no network or keys needed
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
[MIT](LICENSE) © neohorse-kit contributors.
|