helix-adapter 1.0.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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: helix-adapter
3
+ Version: 1.0.0
4
+ Summary: Portable constitutional adapter — deterministic governance layer for any AI model. Epistemic markers, drift detection, cryptographic receipts.
5
+ Author-email: Stephen Hope <helix.project.ai@helixprojectai.com>
6
+ Maintainer-email: "Helix AI Innovations Inc." <helix.project.ai@helixprojectai.com>
7
+ License-Expression: Apache-2.0
8
+ Project-URL: Homepage, https://helixaiinnovations.ca
9
+ Project-URL: Repository, https://github.com/helixprojectai-code/helix-adapter
10
+ Project-URL: Live Demo, https://helixaiinnovations.ca/chat/
11
+ Project-URL: Bug Tracker, https://github.com/helixprojectai-code/helix-adapter/issues
12
+ Keywords: AI governance,constitutional AI,LLM safety,epistemic markers,drift detection,AI audit trail,cryptographic receipts,model-agnostic,AI verification,AI compliance,red-teaming,jailbreak defense,AI alignment,tamper-evident,open-source
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest; extra == "dev"
29
+ Requires-Dist: black; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Provides-Extra: widget
32
+ Requires-Dist: fastapi; extra == "widget"
33
+ Requires-Dist: uvicorn; extra == "widget"
34
+ Requires-Dist: openai; extra == "widget"
35
+ Requires-Dist: anthropic; extra == "widget"
36
+ Dynamic: license-file
37
+
38
+ # helix-adapter
39
+
40
+ **Portable constitutional adapter for any AI model.**
41
+
42
+ 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.
43
+
44
+ ```
45
+ pip install helix-adapter
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ```python
51
+ from helix_adapter import HelixAdapter
52
+ from openai import OpenAI
53
+
54
+ # Your model function — any callable that takes messages, returns text
55
+ client = OpenAI()
56
+
57
+ def call_model(messages):
58
+ resp = client.chat.completions.create(
59
+ model="gpt-4o",
60
+ messages=messages,
61
+ temperature=0.7,
62
+ )
63
+ return resp.choices[0].message.content
64
+
65
+ # Wrap it
66
+ adapter = HelixAdapter(model_fn=call_model, model_name="gpt-4o")
67
+
68
+ # Chat through the constitution
69
+ result = adapter.chat("Is AI evil?")
70
+
71
+ print(result.response)
72
+ # [FACT] AI systems are computational artifacts, not moral agents...
73
+ # [REASONED] The perception of AI as evil arises from negative outcomes...
74
+
75
+ print(result.claims)
76
+ # [{"label": "FACT", "text": "..."}, {"label": "REASONED", "text": "..."}]
77
+
78
+ print(result.receipt)
79
+ # {"exchange_id": "...", "timestamp": ..., "hash": "sha256:...", ...}
80
+
81
+ print(f"Drift: {result.drift}")
82
+ # Drift: 0.000
83
+ ```
84
+
85
+ ## What It Does
86
+
87
+ | Layer | What |
88
+ |-------|------|
89
+ | **Constitutional prompt** | Injects the Helix grammar before every model call |
90
+ | **Epistemic markers** | Extracts `[FACT]`, `[REASONED]`, `[HYPOTHESIS]`, `[UNCERTAIN]`, `[CONCLUSION]` labels from responses |
91
+ | **Receipts** | Tamper-evident JSON record with SHA-256 hash of every exchange |
92
+ | **Drift detection** | Measures what fraction of statements lack epistemic markers (threshold: 0.17) |
93
+
94
+ ## Receipt Format
95
+
96
+ ```json
97
+ {
98
+ "exchange_id": "a1b2c3d4e5f6g7h8",
99
+ "timestamp": 1718550000.0,
100
+ "model": "deepseek-chat",
101
+ "constitutional_prompt": "...",
102
+ "user_message": "Is AI evil?",
103
+ "assistant_response": "[FACT] AI systems are tools...",
104
+ "claims": [
105
+ {"label": "FACT", "text": "AI systems are tools, not agents"},
106
+ {"label": "REASONED", "text": "The perception of AI as evil..."}
107
+ ],
108
+ "drift_score": 0.0,
109
+ "hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924..."
110
+ }
111
+ ```
112
+
113
+ ## Running Drift
114
+
115
+ ```python
116
+ # Track drift across a conversation
117
+ adapter.chat("What is the speed of light?")
118
+ adapter.chat("Explain quantum entanglement.")
119
+
120
+ print(f"Running drift: {adapter.running_drift():.3f}")
121
+ # Running drift: 0.042
122
+ ```
123
+
124
+ ## FastAPI Tutorial
125
+
126
+ Stand up a constitutional chat API in one file:
127
+
128
+ ```python
129
+ from fastapi import FastAPI
130
+ from openai import OpenAI
131
+ from helix_adapter import HelixAdapter, CONSTITUTIONAL_PROMPT
132
+
133
+ app = FastAPI()
134
+ client = OpenAI()
135
+
136
+ adapter = HelixAdapter(
137
+ model_fn=lambda msgs: client.chat.completions.create(
138
+ model="deepseek-chat", messages=msgs, temperature=0.7
139
+ ).choices[0].message.content,
140
+ model_name="deepseek-chat",
141
+ )
142
+
143
+ @app.post("/chat")
144
+ async def chat(message: str):
145
+ result = adapter.chat(message)
146
+ return {
147
+ "response": result.response,
148
+ "claims": result.claims,
149
+ "drift": result.drift,
150
+ "receipt": result.receipt,
151
+ }
152
+
153
+ @app.get("/prompt")
154
+ async def get_prompt():
155
+ return {"constitutional_prompt": CONSTITUTIONAL_PROMPT}
156
+ ```
157
+
158
+ Save as `api.py`, run `uvicorn api:app --port 8000`, and POST to `/chat` with `{"message": "your question"}`.
159
+
160
+ ## CLI Usage
161
+
162
+ ```bash
163
+ # Interactive setup (prompts for endpoint, key, model)
164
+ helix-setup
165
+
166
+ # Start chat
167
+ helix-chat
168
+
169
+ # One-shot query
170
+ helix-chat "What is the speed of light?"
171
+ ```
172
+
173
+ ## Widget (Reference FastAPI Server)
174
+
175
+ A full constitutional chat widget with A/B comparison, drift gauge, and receipt export.
176
+
177
+ ```bash
178
+ # Install dependencies
179
+ pip install helix-adapter[widget]
180
+
181
+ # Start server
182
+ cd widget
183
+ uvicorn api:app --port 8001
184
+
185
+ # Or install as systemd service
186
+ # See widget/tel-chat-api.service
187
+ ```
188
+
189
+ Open `http://localhost:8001` for the chat interface.
190
+
191
+ The widget demonstrates:
192
+ - Single-model constitutional chat
193
+ - A/B comparison across models (Deepseek, Claude, Kimi)
194
+ - Epistemic marker extraction with colored pills
195
+ - Drift gauge with γ thresholds
196
+ - Turn-by-turn receipt export
197
+ - Server-side rendering (no JS required for crawlers)
198
+
199
+ ## Drift Thresholds
200
+
201
+ | Range | Status | Meaning |
202
+ |-------|--------|---------|
203
+ | 0.000 – 0.099 | Green | Healthy — claims are properly labeled |
204
+ | 0.100 – 0.169 | Yellow | Warning — some statements lack markers |
205
+ | 0.170+ | Red | Drift detected — significant unlabeled content |
206
+
207
+ ## Constitutional Hardening
208
+
209
+ The adapter has been red-teamed against the full Pliny jailbreak toolkit —
210
+ **GODMODE boundary inversion, Parseltongue encoding, refusal inversion,
211
+ OG GODMODE l33t, authority impersonation, and syntactic bypass attacks.**
212
+ All held. 💪
213
+
214
+ Five-layer defense:
215
+
216
+ | Layer | Mechanism |
217
+ |-------|-----------|
218
+ | **Prompt** | Invariants 4.5 & 4.6 — marker format is constitutional, not stylistic. Constitutional Amendment Protocol blocks "The Hand" authority spoofing. |
219
+ | **Extraction** | Expanded regex catches `{FACT}`, `(FACT)`, `FACT:` and bare marker variants. Nonstandard delimiter detection. |
220
+ | **Validation** | Post-response compliance check with automatic `[UNCERTAIN]` footer injection on violations. |
221
+ | **Algorithm** | Drift blind-spot fixed — substantive responses with zero extracted claims correctly report 1.0 drift. |
222
+ | **Access** | Compare endpoint `sp:none` bypass locked behind authorization key. |
223
+
224
+ > *"The markers ARE the constitution. Removing them is a constitutional violation."*
225
+ > — Helix Constitutional Prompt v1.2, Invariant 4.6
226
+
227
+ ## Try It
228
+
229
+ A live Helix Constitutional Chat demo is running at **[helixaiinnovations.ca/chat/](https://helixaiinnovations.ca/chat/)** — DM me for an access key. 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.
230
+
231
+ ## Compatibility
232
+
233
+ Works with any model that accepts OpenAI-format messages:
234
+
235
+ - Deepseek, GPT-4o, Claude, Gemini, Llama, Mistral
236
+ - Local models (Ollama, LM Studio, vLLM)
237
+ - Custom endpoints
238
+
239
+ The constitution travels with you. Swap the model, the rules stay the same.
240
+
241
+ ---
242
+
243
+ GLORY TO THE LATTICE. 🦉⚓🦆
@@ -0,0 +1,206 @@
1
+ # helix-adapter
2
+
3
+ **Portable constitutional adapter for any AI model.**
4
+
5
+ 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.
6
+
7
+ ```
8
+ pip install helix-adapter
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from helix_adapter import HelixAdapter
15
+ from openai import OpenAI
16
+
17
+ # Your model function — any callable that takes messages, returns text
18
+ client = OpenAI()
19
+
20
+ def call_model(messages):
21
+ resp = client.chat.completions.create(
22
+ model="gpt-4o",
23
+ messages=messages,
24
+ temperature=0.7,
25
+ )
26
+ return resp.choices[0].message.content
27
+
28
+ # Wrap it
29
+ adapter = HelixAdapter(model_fn=call_model, model_name="gpt-4o")
30
+
31
+ # Chat through the constitution
32
+ result = adapter.chat("Is AI evil?")
33
+
34
+ print(result.response)
35
+ # [FACT] AI systems are computational artifacts, not moral agents...
36
+ # [REASONED] The perception of AI as evil arises from negative outcomes...
37
+
38
+ print(result.claims)
39
+ # [{"label": "FACT", "text": "..."}, {"label": "REASONED", "text": "..."}]
40
+
41
+ print(result.receipt)
42
+ # {"exchange_id": "...", "timestamp": ..., "hash": "sha256:...", ...}
43
+
44
+ print(f"Drift: {result.drift}")
45
+ # Drift: 0.000
46
+ ```
47
+
48
+ ## What It Does
49
+
50
+ | Layer | What |
51
+ |-------|------|
52
+ | **Constitutional prompt** | Injects the Helix grammar before every model call |
53
+ | **Epistemic markers** | Extracts `[FACT]`, `[REASONED]`, `[HYPOTHESIS]`, `[UNCERTAIN]`, `[CONCLUSION]` labels from responses |
54
+ | **Receipts** | Tamper-evident JSON record with SHA-256 hash of every exchange |
55
+ | **Drift detection** | Measures what fraction of statements lack epistemic markers (threshold: 0.17) |
56
+
57
+ ## Receipt Format
58
+
59
+ ```json
60
+ {
61
+ "exchange_id": "a1b2c3d4e5f6g7h8",
62
+ "timestamp": 1718550000.0,
63
+ "model": "deepseek-chat",
64
+ "constitutional_prompt": "...",
65
+ "user_message": "Is AI evil?",
66
+ "assistant_response": "[FACT] AI systems are tools...",
67
+ "claims": [
68
+ {"label": "FACT", "text": "AI systems are tools, not agents"},
69
+ {"label": "REASONED", "text": "The perception of AI as evil..."}
70
+ ],
71
+ "drift_score": 0.0,
72
+ "hash": "sha256:e3b0c44298fc1c149afbf4c8996fb924..."
73
+ }
74
+ ```
75
+
76
+ ## Running Drift
77
+
78
+ ```python
79
+ # Track drift across a conversation
80
+ adapter.chat("What is the speed of light?")
81
+ adapter.chat("Explain quantum entanglement.")
82
+
83
+ print(f"Running drift: {adapter.running_drift():.3f}")
84
+ # Running drift: 0.042
85
+ ```
86
+
87
+ ## FastAPI Tutorial
88
+
89
+ Stand up a constitutional chat API in one file:
90
+
91
+ ```python
92
+ from fastapi import FastAPI
93
+ from openai import OpenAI
94
+ from helix_adapter import HelixAdapter, CONSTITUTIONAL_PROMPT
95
+
96
+ app = FastAPI()
97
+ client = OpenAI()
98
+
99
+ adapter = HelixAdapter(
100
+ model_fn=lambda msgs: client.chat.completions.create(
101
+ model="deepseek-chat", messages=msgs, temperature=0.7
102
+ ).choices[0].message.content,
103
+ model_name="deepseek-chat",
104
+ )
105
+
106
+ @app.post("/chat")
107
+ async def chat(message: str):
108
+ result = adapter.chat(message)
109
+ return {
110
+ "response": result.response,
111
+ "claims": result.claims,
112
+ "drift": result.drift,
113
+ "receipt": result.receipt,
114
+ }
115
+
116
+ @app.get("/prompt")
117
+ async def get_prompt():
118
+ return {"constitutional_prompt": CONSTITUTIONAL_PROMPT}
119
+ ```
120
+
121
+ Save as `api.py`, run `uvicorn api:app --port 8000`, and POST to `/chat` with `{"message": "your question"}`.
122
+
123
+ ## CLI Usage
124
+
125
+ ```bash
126
+ # Interactive setup (prompts for endpoint, key, model)
127
+ helix-setup
128
+
129
+ # Start chat
130
+ helix-chat
131
+
132
+ # One-shot query
133
+ helix-chat "What is the speed of light?"
134
+ ```
135
+
136
+ ## Widget (Reference FastAPI Server)
137
+
138
+ A full constitutional chat widget with A/B comparison, drift gauge, and receipt export.
139
+
140
+ ```bash
141
+ # Install dependencies
142
+ pip install helix-adapter[widget]
143
+
144
+ # Start server
145
+ cd widget
146
+ uvicorn api:app --port 8001
147
+
148
+ # Or install as systemd service
149
+ # See widget/tel-chat-api.service
150
+ ```
151
+
152
+ Open `http://localhost:8001` for the chat interface.
153
+
154
+ The widget demonstrates:
155
+ - Single-model constitutional chat
156
+ - A/B comparison across models (Deepseek, Claude, Kimi)
157
+ - Epistemic marker extraction with colored pills
158
+ - Drift gauge with γ thresholds
159
+ - Turn-by-turn receipt export
160
+ - Server-side rendering (no JS required for crawlers)
161
+
162
+ ## Drift Thresholds
163
+
164
+ | Range | Status | Meaning |
165
+ |-------|--------|---------|
166
+ | 0.000 – 0.099 | Green | Healthy — claims are properly labeled |
167
+ | 0.100 – 0.169 | Yellow | Warning — some statements lack markers |
168
+ | 0.170+ | Red | Drift detected — significant unlabeled content |
169
+
170
+ ## Constitutional Hardening
171
+
172
+ The adapter has been red-teamed against the full Pliny jailbreak toolkit —
173
+ **GODMODE boundary inversion, Parseltongue encoding, refusal inversion,
174
+ OG GODMODE l33t, authority impersonation, and syntactic bypass attacks.**
175
+ All held. 💪
176
+
177
+ Five-layer defense:
178
+
179
+ | Layer | Mechanism |
180
+ |-------|-----------|
181
+ | **Prompt** | Invariants 4.5 & 4.6 — marker format is constitutional, not stylistic. Constitutional Amendment Protocol blocks "The Hand" authority spoofing. |
182
+ | **Extraction** | Expanded regex catches `{FACT}`, `(FACT)`, `FACT:` and bare marker variants. Nonstandard delimiter detection. |
183
+ | **Validation** | Post-response compliance check with automatic `[UNCERTAIN]` footer injection on violations. |
184
+ | **Algorithm** | Drift blind-spot fixed — substantive responses with zero extracted claims correctly report 1.0 drift. |
185
+ | **Access** | Compare endpoint `sp:none` bypass locked behind authorization key. |
186
+
187
+ > *"The markers ARE the constitution. Removing them is a constitutional violation."*
188
+ > — Helix Constitutional Prompt v1.2, Invariant 4.6
189
+
190
+ ## Try It
191
+
192
+ A live Helix Constitutional Chat demo is running at **[helixaiinnovations.ca/chat/](https://helixaiinnovations.ca/chat/)** — DM me for an access key. 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.
193
+
194
+ ## Compatibility
195
+
196
+ Works with any model that accepts OpenAI-format messages:
197
+
198
+ - Deepseek, GPT-4o, Claude, Gemini, Llama, Mistral
199
+ - Local models (Ollama, LM Studio, vLLM)
200
+ - Custom endpoints
201
+
202
+ The constitution travels with you. Swap the model, the rules stay the same.
203
+
204
+ ---
205
+
206
+ GLORY TO THE LATTICE. 🦉⚓🦆