polyglot-stream-heal 1.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.
- polyglot_stream_heal-1.1.0/Cargo.lock +321 -0
- polyglot_stream_heal-1.1.0/Cargo.toml +16 -0
- polyglot_stream_heal-1.1.0/PKG-INFO +118 -0
- polyglot_stream_heal-1.1.0/README.md +85 -0
- polyglot_stream_heal-1.1.0/bindings/python/Cargo.toml +18 -0
- polyglot_stream_heal-1.1.0/bindings/python/README.md +85 -0
- polyglot_stream_heal-1.1.0/bindings/python/polyglot_stream_heal.pyi +30 -0
- polyglot_stream_heal-1.1.0/bindings/python/src/lib.rs +111 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/Cargo.toml +21 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/README.md +114 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/examples/demo.rs +39 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/bin/polyglot_heal.rs +60 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/discriminator.rs +130 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/html_pda.rs +311 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/json_pda.rs +669 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/lib.rs +670 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/mermaid_pda.rs +640 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/partitioner.rs +173 -0
- polyglot_stream_heal-1.1.0/crates/polyglot-stream-heal/src/sse.rs +219 -0
- polyglot_stream_heal-1.1.0/polyglot_stream_heal.pyi +30 -0
- polyglot_stream_heal-1.1.0/pyproject.toml +113 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.1"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "bumpalo"
|
|
13
|
+
version = "3.20.3"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "cfg-if"
|
|
19
|
+
version = "1.0.5"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "heck"
|
|
25
|
+
version = "0.5.0"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "indoc"
|
|
31
|
+
version = "2.0.8"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"rustversion",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "itoa"
|
|
40
|
+
version = "1.0.18"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|
43
|
+
|
|
44
|
+
[[package]]
|
|
45
|
+
name = "libc"
|
|
46
|
+
version = "0.2.191"
|
|
47
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
48
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
49
|
+
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "memchr"
|
|
52
|
+
version = "2.8.3"
|
|
53
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
54
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
55
|
+
|
|
56
|
+
[[package]]
|
|
57
|
+
name = "memoffset"
|
|
58
|
+
version = "0.9.1"
|
|
59
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
60
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
61
|
+
dependencies = [
|
|
62
|
+
"autocfg",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[[package]]
|
|
66
|
+
name = "once_cell"
|
|
67
|
+
version = "1.21.4"
|
|
68
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
69
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
70
|
+
|
|
71
|
+
[[package]]
|
|
72
|
+
name = "polyglot-stream-heal"
|
|
73
|
+
version = "1.1.0"
|
|
74
|
+
dependencies = [
|
|
75
|
+
"serde",
|
|
76
|
+
"serde_json",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[[package]]
|
|
80
|
+
name = "polyglot-stream-heal-py"
|
|
81
|
+
version = "1.1.0"
|
|
82
|
+
dependencies = [
|
|
83
|
+
"polyglot-stream-heal",
|
|
84
|
+
"pyo3",
|
|
85
|
+
"serde_json",
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
[[package]]
|
|
89
|
+
name = "polyglot-stream-heal-wasm"
|
|
90
|
+
version = "1.1.0"
|
|
91
|
+
dependencies = [
|
|
92
|
+
"polyglot-stream-heal",
|
|
93
|
+
"serde_json",
|
|
94
|
+
"wasm-bindgen",
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
[[package]]
|
|
98
|
+
name = "portable-atomic"
|
|
99
|
+
version = "1.15.0"
|
|
100
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
101
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "proc-macro2"
|
|
105
|
+
version = "1.0.107"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"unicode-ident",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[[package]]
|
|
113
|
+
name = "pyo3"
|
|
114
|
+
version = "0.22.6"
|
|
115
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
|
+
checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
|
|
117
|
+
dependencies = [
|
|
118
|
+
"cfg-if",
|
|
119
|
+
"indoc",
|
|
120
|
+
"libc",
|
|
121
|
+
"memoffset",
|
|
122
|
+
"once_cell",
|
|
123
|
+
"portable-atomic",
|
|
124
|
+
"pyo3-build-config",
|
|
125
|
+
"pyo3-ffi",
|
|
126
|
+
"pyo3-macros",
|
|
127
|
+
"unindent",
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
[[package]]
|
|
131
|
+
name = "pyo3-build-config"
|
|
132
|
+
version = "0.22.6"
|
|
133
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
134
|
+
checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
|
|
135
|
+
dependencies = [
|
|
136
|
+
"once_cell",
|
|
137
|
+
"target-lexicon",
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
[[package]]
|
|
141
|
+
name = "pyo3-ffi"
|
|
142
|
+
version = "0.22.6"
|
|
143
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
144
|
+
checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
|
|
145
|
+
dependencies = [
|
|
146
|
+
"libc",
|
|
147
|
+
"pyo3-build-config",
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
[[package]]
|
|
151
|
+
name = "pyo3-macros"
|
|
152
|
+
version = "0.22.6"
|
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
154
|
+
checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
|
|
155
|
+
dependencies = [
|
|
156
|
+
"proc-macro2",
|
|
157
|
+
"pyo3-macros-backend",
|
|
158
|
+
"quote",
|
|
159
|
+
"syn 2.0.119",
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
[[package]]
|
|
163
|
+
name = "pyo3-macros-backend"
|
|
164
|
+
version = "0.22.6"
|
|
165
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
166
|
+
checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
|
|
167
|
+
dependencies = [
|
|
168
|
+
"heck",
|
|
169
|
+
"proc-macro2",
|
|
170
|
+
"pyo3-build-config",
|
|
171
|
+
"quote",
|
|
172
|
+
"syn 2.0.119",
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
[[package]]
|
|
176
|
+
name = "quote"
|
|
177
|
+
version = "1.0.47"
|
|
178
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
179
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
180
|
+
dependencies = [
|
|
181
|
+
"proc-macro2",
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
[[package]]
|
|
185
|
+
name = "rustversion"
|
|
186
|
+
version = "1.0.23"
|
|
187
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
188
|
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
189
|
+
|
|
190
|
+
[[package]]
|
|
191
|
+
name = "serde"
|
|
192
|
+
version = "1.0.229"
|
|
193
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
194
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
195
|
+
dependencies = [
|
|
196
|
+
"serde_core",
|
|
197
|
+
"serde_derive",
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
[[package]]
|
|
201
|
+
name = "serde_core"
|
|
202
|
+
version = "1.0.229"
|
|
203
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
204
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
205
|
+
dependencies = [
|
|
206
|
+
"serde_derive",
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
[[package]]
|
|
210
|
+
name = "serde_derive"
|
|
211
|
+
version = "1.0.229"
|
|
212
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
213
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
214
|
+
dependencies = [
|
|
215
|
+
"proc-macro2",
|
|
216
|
+
"quote",
|
|
217
|
+
"syn 3.0.9",
|
|
218
|
+
]
|
|
219
|
+
|
|
220
|
+
[[package]]
|
|
221
|
+
name = "serde_json"
|
|
222
|
+
version = "1.0.154"
|
|
223
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
224
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
225
|
+
dependencies = [
|
|
226
|
+
"itoa",
|
|
227
|
+
"memchr",
|
|
228
|
+
"serde",
|
|
229
|
+
"serde_core",
|
|
230
|
+
"zmij",
|
|
231
|
+
]
|
|
232
|
+
|
|
233
|
+
[[package]]
|
|
234
|
+
name = "syn"
|
|
235
|
+
version = "2.0.119"
|
|
236
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
237
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
238
|
+
dependencies = [
|
|
239
|
+
"proc-macro2",
|
|
240
|
+
"quote",
|
|
241
|
+
"unicode-ident",
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
[[package]]
|
|
245
|
+
name = "syn"
|
|
246
|
+
version = "3.0.9"
|
|
247
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
248
|
+
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
|
249
|
+
dependencies = [
|
|
250
|
+
"proc-macro2",
|
|
251
|
+
"quote",
|
|
252
|
+
"unicode-ident",
|
|
253
|
+
]
|
|
254
|
+
|
|
255
|
+
[[package]]
|
|
256
|
+
name = "target-lexicon"
|
|
257
|
+
version = "0.12.16"
|
|
258
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
260
|
+
|
|
261
|
+
[[package]]
|
|
262
|
+
name = "unicode-ident"
|
|
263
|
+
version = "1.0.27"
|
|
264
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
265
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
266
|
+
|
|
267
|
+
[[package]]
|
|
268
|
+
name = "unindent"
|
|
269
|
+
version = "0.2.4"
|
|
270
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
271
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
272
|
+
|
|
273
|
+
[[package]]
|
|
274
|
+
name = "wasm-bindgen"
|
|
275
|
+
version = "0.2.130"
|
|
276
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
277
|
+
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
|
|
278
|
+
dependencies = [
|
|
279
|
+
"cfg-if",
|
|
280
|
+
"rustversion",
|
|
281
|
+
"wasm-bindgen-macro",
|
|
282
|
+
"wasm-bindgen-shared",
|
|
283
|
+
]
|
|
284
|
+
|
|
285
|
+
[[package]]
|
|
286
|
+
name = "wasm-bindgen-macro"
|
|
287
|
+
version = "0.2.130"
|
|
288
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
289
|
+
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
|
|
290
|
+
dependencies = [
|
|
291
|
+
"quote",
|
|
292
|
+
"wasm-bindgen-macro-support",
|
|
293
|
+
]
|
|
294
|
+
|
|
295
|
+
[[package]]
|
|
296
|
+
name = "wasm-bindgen-macro-support"
|
|
297
|
+
version = "0.2.130"
|
|
298
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
299
|
+
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
|
|
300
|
+
dependencies = [
|
|
301
|
+
"bumpalo",
|
|
302
|
+
"proc-macro2",
|
|
303
|
+
"quote",
|
|
304
|
+
"syn 3.0.9",
|
|
305
|
+
"wasm-bindgen-shared",
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
[[package]]
|
|
309
|
+
name = "wasm-bindgen-shared"
|
|
310
|
+
version = "0.2.130"
|
|
311
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
312
|
+
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
|
|
313
|
+
dependencies = [
|
|
314
|
+
"unicode-ident",
|
|
315
|
+
]
|
|
316
|
+
|
|
317
|
+
[[package]]
|
|
318
|
+
name = "zmij"
|
|
319
|
+
version = "1.0.23"
|
|
320
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
321
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
resolver = "2"
|
|
3
|
+
members = ["crates/polyglot-stream-heal", "bindings/python"]
|
|
4
|
+
|
|
5
|
+
[workspace.package]
|
|
6
|
+
version = "1.1.0"
|
|
7
|
+
edition = "2021"
|
|
8
|
+
authors = ["David Charles Michael <davidchar@gmail.com>"]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
homepage = "https://github.com/davidhcar/polyglot_stream_heal"
|
|
11
|
+
documentation = "https://docs.rs/polyglot-stream-heal"
|
|
12
|
+
repository = "https://github.com/davidhcar/polyglot_stream_heal"
|
|
13
|
+
|
|
14
|
+
[workspace.dependencies]
|
|
15
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
16
|
+
serde_json = "1.0"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polyglot-stream-heal
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Intended Audience :: Science/Research
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
9
|
+
Classifier: Programming Language :: Rust
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Summary: Ultra-fast 6us incremental streaming JSON repair, Mermaid diagram healer, and HTML5 sandbox balancer for LLM token streams (60x faster drop-in alternative to json-repair and partial-json)
|
|
21
|
+
Keywords: llm,streaming,json-repair,partial-json,streaming-json,incomplete-json,truncated-json,malformed-json,json-parser,json-stream,mermaid,mermaid-parser,mermaid-repair,streaming-mermaid,markdown-stream,html-stream,sse,server-sent-events,openai,anthropic,gemini,langchain,llamaindex,vercel-ai-sdk,tool-calling,function-calling,structured-outputs,pushdown-transducer,pushdown-automaton,error-recovery,rust,pyo3,wasm,ai-agents,agentic-ai,sse-parser,sse-streaming,llm-streaming,llm-gateway,openai-responses-api,openai-streaming,anthropic-claude,claude-api,gemini-api,vllm,sglang,litellm,ollama,openrouter,fastapi,fastapi-sse,mcp,model-context-protocol,langgraph,autogen,crewai,pydantic-ai,context-engineering,thinking-tokens,reasoning-models,streaming-parser,incremental-parsing,syntax-repair,type-stubs
|
|
22
|
+
Author-email: David Charles Michael <davidchar@gmail.com>
|
|
23
|
+
Maintainer-email: David Charles Michael <davidchar@gmail.com>
|
|
24
|
+
License: MIT
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
27
|
+
Project-URL: Author ORCID, https://orcid.org/0009-0007-8679-6941
|
|
28
|
+
Project-URL: Companion Paper, https://github.com/davidhcar/polyglot_stream_heal/blob/main/paper/paper.pdf
|
|
29
|
+
Project-URL: Documentation, https://docs.rs/polyglot-stream-heal
|
|
30
|
+
Project-URL: Homepage, https://github.com/davidhcar/polyglot_stream_heal
|
|
31
|
+
Project-URL: Repository, https://github.com/davidhcar/polyglot_stream_heal
|
|
32
|
+
|
|
33
|
+
# `polyglot-stream-heal` (Python Native `PyO3` Extension, `PyPI`)
|
|
34
|
+
|
|
35
|
+
**Ultra-fast $6.3\,\mu\text{s}$ incremental $O(n)$ streaming JSON repair, 14-dialect Mermaid diagram healer, and HTML5 sandbox balancer for LLM token streams ($61.3\times$ faster drop-in alternative to `json-repair` and `partial-json`).**
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/polyglot-stream-heal/)
|
|
38
|
+
[](https://crates.io/crates/polyglot-stream-heal)
|
|
39
|
+
[](https://www.npmjs.com/package/polyglot-stream-heal)
|
|
40
|
+
[](https://colab.research.google.com/github/davidhcar/polyglot_stream_heal/blob/main/examples/colab_quickstart.ipynb)
|
|
41
|
+
|
|
42
|
+
- **Author:** **David Charles Michael** (`davidchar@gmail.com` | [ORCID: `0009-0007-8679-6941`](https://orcid.org/0009-0007-8679-6941))
|
|
43
|
+
- **License:** MIT
|
|
44
|
+
- **Native Rust Performance in Python:** Compiled via `PyO3` + `maturin` (`abi3-py39+`), delivering **$61.3\times$ lower median chunk latency** ($6.3\,\mu\text{s}$ vs. $386.8\,\mu\text{s}$) and **$264.2\times$ lower cumulative stream overhead** at $32\text{ KB}$ than pure-Python `json-repair`, while additionally healing nested escaped tool-call JSON strings, 14 Mermaid diagram dialects, HTML5 sandboxes, and wide tables.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## What's New in `v1.1.0`: Frontier LLM SSE Stream Extraction & Static Type Stubs (`.pyi`)
|
|
49
|
+
|
|
50
|
+
Pipe raw Server-Sent Event lines directly from **OpenAI Chat Completions** (+ `vLLM`/`SGLang`/`Ollama`), **OpenAI Responses API**, **Anthropic Messages API** (auto-skipping `thinking_delta`), and **Google Gemini `alt=sse`** (auto-skipping `thought: true`), with full PEP 561 `.pyi` IDE autocomplete:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import polyglot_stream_heal as psh
|
|
54
|
+
|
|
55
|
+
tx = psh.IncrementalTransducer()
|
|
56
|
+
# 1. OpenAI Chat Completions (and vLLM / SGLang / LiteLLM / Ollama)
|
|
57
|
+
tx.push_sse_line('data: {"choices":[{"delta":{"content":"```json\\n{\\"openai\\":true,"}}]}')
|
|
58
|
+
# 2. OpenAI Responses API
|
|
59
|
+
tx.push_sse_line('data: {"type":"response.output_text.delta","delta":"\\"responses\\":true,"}')
|
|
60
|
+
# 3. Anthropic Messages API (thinking_delta is skipped automatically)
|
|
61
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"thinking_delta","thinking":"hidden"}}')
|
|
62
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"\\"anthropic\\":true,"}}')
|
|
63
|
+
# 4. Google Gemini alt=sse (thought:true parts are skipped automatically)
|
|
64
|
+
tx.push_sse_line('data: {"candidates":[{"content":{"parts":[{"thought":true,"text":"skip"},{"text":"\\"gemini\\":[1,2"}]}}]}')
|
|
65
|
+
tx.push_sse_line('data: [DONE]')
|
|
66
|
+
print(tx.snapshot_markdown())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 1. Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install -U polyglot-stream-heal
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 2. How to Implement & Verified Output
|
|
80
|
+
|
|
81
|
+
### Runnable Code Snippet (`python3 examples/demo_python.py`)
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import json
|
|
85
|
+
import polyglot_stream_heal as psh
|
|
86
|
+
|
|
87
|
+
print("=== 1. Stateful Streaming Transducer (Python PyO3) ===")
|
|
88
|
+
transducer = psh.IncrementalTransducer(max_table_cols=5, max_chart_bars=10)
|
|
89
|
+
stream_chunks = [
|
|
90
|
+
"### Telemetry Stream\n```json\n",
|
|
91
|
+
'{"service": "router", "active": tru, "p99_ms": 12.',
|
|
92
|
+
]
|
|
93
|
+
for chunk in stream_chunks:
|
|
94
|
+
transducer.push_chunk(chunk)
|
|
95
|
+
|
|
96
|
+
active_seg = json.loads(transducer.snapshot_active_json())
|
|
97
|
+
print("Active Segment Modality:", active_seg["modality"])
|
|
98
|
+
print("Healed JSON Content :", active_seg["content"])
|
|
99
|
+
|
|
100
|
+
print("\n=== 2. Context-Free Mermaid Dyck Node Healing ===")
|
|
101
|
+
raw_mermaid = "flowchart TD\n subgraph Shard_A (Primary: US-East)\n N1[Compute O(f(g(x)))] -- rpc --> N2[(Ledger (v2))]"
|
|
102
|
+
print(psh.heal_mermaid(raw_mermaid))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Exact Verified Output (`examples/VERIFIED_OUTPUT.txt`)
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
=== 1. Stateful Streaming Transducer (Python PyO3) ===
|
|
109
|
+
Active Segment Modality: json
|
|
110
|
+
Healed JSON Content : {"active":true,"p99_ms":12.0,"service":"router"}
|
|
111
|
+
|
|
112
|
+
=== 2. Context-Free Mermaid Dyck Node Healing ===
|
|
113
|
+
flowchart TD
|
|
114
|
+
subgraph sg_Shard_A__Primary__US ["Shard_A (Primary: US-East)"]
|
|
115
|
+
N1["Compute O(f(g(x)))"] -->|rpc| N2[("Ledger (v2)")]
|
|
116
|
+
end
|
|
117
|
+
```
|
|
118
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# `polyglot-stream-heal` (Python Native `PyO3` Extension, `PyPI`)
|
|
2
|
+
|
|
3
|
+
**Ultra-fast $6.3\,\mu\text{s}$ incremental $O(n)$ streaming JSON repair, 14-dialect Mermaid diagram healer, and HTML5 sandbox balancer for LLM token streams ($61.3\times$ faster drop-in alternative to `json-repair` and `partial-json`).**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/polyglot-stream-heal/)
|
|
6
|
+
[](https://crates.io/crates/polyglot-stream-heal)
|
|
7
|
+
[](https://www.npmjs.com/package/polyglot-stream-heal)
|
|
8
|
+
[](https://colab.research.google.com/github/davidhcar/polyglot_stream_heal/blob/main/examples/colab_quickstart.ipynb)
|
|
9
|
+
|
|
10
|
+
- **Author:** **David Charles Michael** (`davidchar@gmail.com` | [ORCID: `0009-0007-8679-6941`](https://orcid.org/0009-0007-8679-6941))
|
|
11
|
+
- **License:** MIT
|
|
12
|
+
- **Native Rust Performance in Python:** Compiled via `PyO3` + `maturin` (`abi3-py39+`), delivering **$61.3\times$ lower median chunk latency** ($6.3\,\mu\text{s}$ vs. $386.8\,\mu\text{s}$) and **$264.2\times$ lower cumulative stream overhead** at $32\text{ KB}$ than pure-Python `json-repair`, while additionally healing nested escaped tool-call JSON strings, 14 Mermaid diagram dialects, HTML5 sandboxes, and wide tables.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## What's New in `v1.1.0`: Frontier LLM SSE Stream Extraction & Static Type Stubs (`.pyi`)
|
|
17
|
+
|
|
18
|
+
Pipe raw Server-Sent Event lines directly from **OpenAI Chat Completions** (+ `vLLM`/`SGLang`/`Ollama`), **OpenAI Responses API**, **Anthropic Messages API** (auto-skipping `thinking_delta`), and **Google Gemini `alt=sse`** (auto-skipping `thought: true`), with full PEP 561 `.pyi` IDE autocomplete:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import polyglot_stream_heal as psh
|
|
22
|
+
|
|
23
|
+
tx = psh.IncrementalTransducer()
|
|
24
|
+
# 1. OpenAI Chat Completions (and vLLM / SGLang / LiteLLM / Ollama)
|
|
25
|
+
tx.push_sse_line('data: {"choices":[{"delta":{"content":"```json\\n{\\"openai\\":true,"}}]}')
|
|
26
|
+
# 2. OpenAI Responses API
|
|
27
|
+
tx.push_sse_line('data: {"type":"response.output_text.delta","delta":"\\"responses\\":true,"}')
|
|
28
|
+
# 3. Anthropic Messages API (thinking_delta is skipped automatically)
|
|
29
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"thinking_delta","thinking":"hidden"}}')
|
|
30
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"\\"anthropic\\":true,"}}')
|
|
31
|
+
# 4. Google Gemini alt=sse (thought:true parts are skipped automatically)
|
|
32
|
+
tx.push_sse_line('data: {"candidates":[{"content":{"parts":[{"thought":true,"text":"skip"},{"text":"\\"gemini\\":[1,2"}]}}]}')
|
|
33
|
+
tx.push_sse_line('data: [DONE]')
|
|
34
|
+
print(tx.snapshot_markdown())
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 1. Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -U polyglot-stream-heal
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 2. How to Implement & Verified Output
|
|
48
|
+
|
|
49
|
+
### Runnable Code Snippet (`python3 examples/demo_python.py`)
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import json
|
|
53
|
+
import polyglot_stream_heal as psh
|
|
54
|
+
|
|
55
|
+
print("=== 1. Stateful Streaming Transducer (Python PyO3) ===")
|
|
56
|
+
transducer = psh.IncrementalTransducer(max_table_cols=5, max_chart_bars=10)
|
|
57
|
+
stream_chunks = [
|
|
58
|
+
"### Telemetry Stream\n```json\n",
|
|
59
|
+
'{"service": "router", "active": tru, "p99_ms": 12.',
|
|
60
|
+
]
|
|
61
|
+
for chunk in stream_chunks:
|
|
62
|
+
transducer.push_chunk(chunk)
|
|
63
|
+
|
|
64
|
+
active_seg = json.loads(transducer.snapshot_active_json())
|
|
65
|
+
print("Active Segment Modality:", active_seg["modality"])
|
|
66
|
+
print("Healed JSON Content :", active_seg["content"])
|
|
67
|
+
|
|
68
|
+
print("\n=== 2. Context-Free Mermaid Dyck Node Healing ===")
|
|
69
|
+
raw_mermaid = "flowchart TD\n subgraph Shard_A (Primary: US-East)\n N1[Compute O(f(g(x)))] -- rpc --> N2[(Ledger (v2))]"
|
|
70
|
+
print(psh.heal_mermaid(raw_mermaid))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Exact Verified Output (`examples/VERIFIED_OUTPUT.txt`)
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
=== 1. Stateful Streaming Transducer (Python PyO3) ===
|
|
77
|
+
Active Segment Modality: json
|
|
78
|
+
Healed JSON Content : {"active":true,"p99_ms":12.0,"service":"router"}
|
|
79
|
+
|
|
80
|
+
=== 2. Context-Free Mermaid Dyck Node Healing ===
|
|
81
|
+
flowchart TD
|
|
82
|
+
subgraph sg_Shard_A__Primary__US ["Shard_A (Primary: US-East)"]
|
|
83
|
+
N1["Compute O(f(g(x)))"] -->|rpc| N2[("Ledger (v2)")]
|
|
84
|
+
end
|
|
85
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "polyglot-stream-heal-py"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
authors.workspace = true
|
|
6
|
+
license.workspace = true
|
|
7
|
+
repository.workspace = true
|
|
8
|
+
description = "Python PyO3 native extension bindings for polyglot-stream-heal"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
name = "polyglot_stream_heal"
|
|
13
|
+
crate-type = ["cdylib"]
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
polyglot-stream-heal = { path = "../../crates/polyglot-stream-heal" }
|
|
17
|
+
pyo3 = { version = "0.22", features = ["extension-module", "abi3-py39"] }
|
|
18
|
+
serde_json = { workspace = true }
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# `polyglot-stream-heal` (Python Native `PyO3` Extension, `PyPI`)
|
|
2
|
+
|
|
3
|
+
**Ultra-fast $6.3\,\mu\text{s}$ incremental $O(n)$ streaming JSON repair, 14-dialect Mermaid diagram healer, and HTML5 sandbox balancer for LLM token streams ($61.3\times$ faster drop-in alternative to `json-repair` and `partial-json`).**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/polyglot-stream-heal/)
|
|
6
|
+
[](https://crates.io/crates/polyglot-stream-heal)
|
|
7
|
+
[](https://www.npmjs.com/package/polyglot-stream-heal)
|
|
8
|
+
[](https://colab.research.google.com/github/davidhcar/polyglot_stream_heal/blob/main/examples/colab_quickstart.ipynb)
|
|
9
|
+
|
|
10
|
+
- **Author:** **David Charles Michael** (`davidchar@gmail.com` | [ORCID: `0009-0007-8679-6941`](https://orcid.org/0009-0007-8679-6941))
|
|
11
|
+
- **License:** MIT
|
|
12
|
+
- **Native Rust Performance in Python:** Compiled via `PyO3` + `maturin` (`abi3-py39+`), delivering **$61.3\times$ lower median chunk latency** ($6.3\,\mu\text{s}$ vs. $386.8\,\mu\text{s}$) and **$264.2\times$ lower cumulative stream overhead** at $32\text{ KB}$ than pure-Python `json-repair`, while additionally healing nested escaped tool-call JSON strings, 14 Mermaid diagram dialects, HTML5 sandboxes, and wide tables.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## What's New in `v1.1.0`: Frontier LLM SSE Stream Extraction & Static Type Stubs (`.pyi`)
|
|
17
|
+
|
|
18
|
+
Pipe raw Server-Sent Event lines directly from **OpenAI Chat Completions** (+ `vLLM`/`SGLang`/`Ollama`), **OpenAI Responses API**, **Anthropic Messages API** (auto-skipping `thinking_delta`), and **Google Gemini `alt=sse`** (auto-skipping `thought: true`), with full PEP 561 `.pyi` IDE autocomplete:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import polyglot_stream_heal as psh
|
|
22
|
+
|
|
23
|
+
tx = psh.IncrementalTransducer()
|
|
24
|
+
# 1. OpenAI Chat Completions (and vLLM / SGLang / LiteLLM / Ollama)
|
|
25
|
+
tx.push_sse_line('data: {"choices":[{"delta":{"content":"```json\\n{\\"openai\\":true,"}}]}')
|
|
26
|
+
# 2. OpenAI Responses API
|
|
27
|
+
tx.push_sse_line('data: {"type":"response.output_text.delta","delta":"\\"responses\\":true,"}')
|
|
28
|
+
# 3. Anthropic Messages API (thinking_delta is skipped automatically)
|
|
29
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"thinking_delta","thinking":"hidden"}}')
|
|
30
|
+
tx.push_sse_line('data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"\\"anthropic\\":true,"}}')
|
|
31
|
+
# 4. Google Gemini alt=sse (thought:true parts are skipped automatically)
|
|
32
|
+
tx.push_sse_line('data: {"candidates":[{"content":{"parts":[{"thought":true,"text":"skip"},{"text":"\\"gemini\\":[1,2"}]}}]}')
|
|
33
|
+
tx.push_sse_line('data: [DONE]')
|
|
34
|
+
print(tx.snapshot_markdown())
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 1. Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -U polyglot-stream-heal
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 2. How to Implement & Verified Output
|
|
48
|
+
|
|
49
|
+
### Runnable Code Snippet (`python3 examples/demo_python.py`)
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import json
|
|
53
|
+
import polyglot_stream_heal as psh
|
|
54
|
+
|
|
55
|
+
print("=== 1. Stateful Streaming Transducer (Python PyO3) ===")
|
|
56
|
+
transducer = psh.IncrementalTransducer(max_table_cols=5, max_chart_bars=10)
|
|
57
|
+
stream_chunks = [
|
|
58
|
+
"### Telemetry Stream\n```json\n",
|
|
59
|
+
'{"service": "router", "active": tru, "p99_ms": 12.',
|
|
60
|
+
]
|
|
61
|
+
for chunk in stream_chunks:
|
|
62
|
+
transducer.push_chunk(chunk)
|
|
63
|
+
|
|
64
|
+
active_seg = json.loads(transducer.snapshot_active_json())
|
|
65
|
+
print("Active Segment Modality:", active_seg["modality"])
|
|
66
|
+
print("Healed JSON Content :", active_seg["content"])
|
|
67
|
+
|
|
68
|
+
print("\n=== 2. Context-Free Mermaid Dyck Node Healing ===")
|
|
69
|
+
raw_mermaid = "flowchart TD\n subgraph Shard_A (Primary: US-East)\n N1[Compute O(f(g(x)))] -- rpc --> N2[(Ledger (v2))]"
|
|
70
|
+
print(psh.heal_mermaid(raw_mermaid))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Exact Verified Output (`examples/VERIFIED_OUTPUT.txt`)
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
=== 1. Stateful Streaming Transducer (Python PyO3) ===
|
|
77
|
+
Active Segment Modality: json
|
|
78
|
+
Healed JSON Content : {"active":true,"p99_ms":12.0,"service":"router"}
|
|
79
|
+
|
|
80
|
+
=== 2. Context-Free Mermaid Dyck Node Healing ===
|
|
81
|
+
flowchart TD
|
|
82
|
+
subgraph sg_Shard_A__Primary__US ["Shard_A (Primary: US-East)"]
|
|
83
|
+
N1["Compute O(f(g(x)))"] -->|rpc| N2[("Ledger (v2)")]
|
|
84
|
+
end
|
|
85
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Type stubs for polyglot_stream_heal (v1.1.0)."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
class IncrementalTransducer:
|
|
6
|
+
"""Linear-time O(n) incremental pushdown transducer for polyglot LLM token streams."""
|
|
7
|
+
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
max_table_cols: int = 5,
|
|
11
|
+
max_chart_bars: int = 10,
|
|
12
|
+
partition_visuals: bool = True,
|
|
13
|
+
repair_nested_escaped_json: bool = True,
|
|
14
|
+
) -> None: ...
|
|
15
|
+
def push_chunk(self, chunk: str) -> None: ...
|
|
16
|
+
def push_bytes(self, data: bytes) -> None: ...
|
|
17
|
+
def push_sse_line(self, line: str) -> Optional[str]: ...
|
|
18
|
+
def snapshot_json(self) -> str: ...
|
|
19
|
+
def snapshot_active_json(self) -> str: ...
|
|
20
|
+
def snapshot_markdown(self) -> str: ...
|
|
21
|
+
def reset(self) -> None: ...
|
|
22
|
+
|
|
23
|
+
def heal_json(raw: str) -> str: ...
|
|
24
|
+
def heal_mermaid(raw: str) -> str: ...
|
|
25
|
+
def heal_html(raw: str) -> str: ...
|
|
26
|
+
def partition_visual_spec(
|
|
27
|
+
raw_json: str, max_table_cols: int = 5, max_chart_bars: int = 10
|
|
28
|
+
) -> str: ...
|
|
29
|
+
def extract_sse_delta(line: str) -> Optional[str]: ...
|
|
30
|
+
def heal_stream_json(raw: str) -> str: ...
|