typellm 0.1.0__py3-none-any.whl
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.
- typellm-0.1.0.dist-info/METADATA +412 -0
- typellm-0.1.0.dist-info/RECORD +13 -0
- typellm-0.1.0.dist-info/WHEEL +5 -0
- typellm-0.1.0.dist-info/entry_points.txt +2 -0
- typellm-0.1.0.dist-info/licenses/LICENSE +202 -0
- typellm-0.1.0.dist-info/top_level.txt +7 -0
- typellm.py +44 -0
- typellm_benchmark.py +79 -0
- typellm_cli.py +104 -0
- typellm_numeric.py +139 -0
- typellm_runtime.py +924 -0
- typellm_schema.py +195 -0
- typellm_sglang.py +489 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: typellm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Type-Safe Decoding for Autoregressive LLMs
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://typellm.ai/
|
|
7
|
+
Project-URL: Repository, https://github.com/TypeLLM/TypeLLM
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: jinja2>=3.1
|
|
12
|
+
Requires-Dist: tokenizers>=0.23
|
|
13
|
+
Requires-Dist: transformers>=5.0
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<div align="center">
|
|
19
|
+
|
|
20
|
+
<img width="1500" height="500" alt="typellm-banner" src="https://github.com/user-attachments/assets/b1f2dbc6-21b7-4222-a0fb-dacfe1650797" />
|
|
21
|
+
|
|
22
|
+
# TypeLLM: LLMs with type-safe generation
|
|
23
|
+
|
|
24
|
+
<h4 align="center">
|
|
25
|
+
<a href="https://typellm.ai/">Homepage</a> •
|
|
26
|
+
<a href="https://typellm.ai/blog/introducing-typellm">Blog</a> •
|
|
27
|
+
<a href="https://typellm.ai/contact">Contact</a>
|
|
28
|
+
</h4>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Updates
|
|
36
|
+
|
|
37
|
+
- **[2026/09/19]** Added optional [thinking mode](#thinking-mode) with
|
|
38
|
+
`thinking=True/False` and a configurable per-field thinking budget, followed
|
|
39
|
+
by type-safe constrained decoding. Thinking is off by default.
|
|
40
|
+
- [2026/09/18] Added integer and float outputs through tokenizer-native
|
|
41
|
+
constrained decoding for JSON Schema `integer` and `number` fields.
|
|
42
|
+
|
|
43
|
+
## Introduction
|
|
44
|
+
|
|
45
|
+
TypeLLM extends autoregressive LLMs with type-safe generation. Models can still think and generate freely when needed, while producing guaranteed typed outputs when structure matters. Define the output with a JSON Schema, and TypeLLM returns values your software can use directly.
|
|
46
|
+
|
|
47
|
+
### Supported output types
|
|
48
|
+
|
|
49
|
+
- **Text** — Free text (`string`).
|
|
50
|
+
- **Integer** — Whole numbers (`integer`).
|
|
51
|
+
- **Number** — Numeric values (`number`).
|
|
52
|
+
- **Boolean** — `true` or `false`.
|
|
53
|
+
- **Enum choice** — One of your allowed string or numeric values.
|
|
54
|
+
|
|
55
|
+
Enum and boolean fields select from finite candidates; numeric and text fields
|
|
56
|
+
without `enum` generate values token by token. See [schemas and examples](#output-types).
|
|
57
|
+
|
|
58
|
+
### Features
|
|
59
|
+
|
|
60
|
+
1. **No out-of-schema hallucinations** — Choices stay within the allowed values.
|
|
61
|
+
2. **Negligible output-token cost** — Single-token categorical selection and bounded numeric decoding; optional thinking adds tokens.
|
|
62
|
+
3. **Linear input computation cost** — Prefix caching avoids reprocessing shared context.
|
|
63
|
+
4. **Batch or sequential execution** — Run independent decisions together or condition on earlier results.
|
|
64
|
+
5. **Made for open autoregressive LLMs** — Use compatible models you already serve with SGLang.
|
|
65
|
+
6. **Supports thinking mode** — Enable reasoning before the final constrained answer.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
### 1. Serve a model with SGLang
|
|
70
|
+
|
|
71
|
+
Use [SGLang](https://github.com/sgl-project/sglang) to configure and serve a
|
|
72
|
+
compatible autoregressive model on your local GPU server. This example uses
|
|
73
|
+
Qwen3.8-27B; follow the
|
|
74
|
+
[Qwen3.8-27B SGLang deployment guide](https://lmsysorg.mintlify.app/cookbook/autoregressive/Qwen/Qwen3.8-27B)
|
|
75
|
+
to start it with prefix caching enabled.
|
|
76
|
+
|
|
77
|
+
**Qwen3.5-4B and Qwen3.5-9B are also supported and GPU-tested, including thinking mode.**
|
|
78
|
+
|
|
79
|
+
Serve the chosen checkpoint with SGLang and use the same model ID in the client:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from typellm import TypeLLMClient
|
|
83
|
+
|
|
84
|
+
client = TypeLLMClient(
|
|
85
|
+
"http://127.0.0.1:30000",
|
|
86
|
+
model="Qwen/Qwen3.8-27B", # or "Qwen/Qwen3.5-4B", "Qwen/Qwen3.5-9B"
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Install the lightweight client-side tokenizer dependencies:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -r requirements.txt
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. Run TypeLLM
|
|
97
|
+
|
|
98
|
+
Point `TypeLLMClient` at the SGLang server's HTTP endpoint:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from typellm import TypeLLMClient
|
|
102
|
+
|
|
103
|
+
client = TypeLLMClient(
|
|
104
|
+
"http://127.0.0.1:30000",
|
|
105
|
+
model="Qwen/Qwen3.8-27B",
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
result = client.generate(
|
|
109
|
+
context="""
|
|
110
|
+
Receipt from Hilton London
|
|
111
|
+
Total: £324
|
|
112
|
+
Employee travelled to London for a client meeting.
|
|
113
|
+
""",
|
|
114
|
+
questions={
|
|
115
|
+
"expense_type": {
|
|
116
|
+
"type": "string",
|
|
117
|
+
"enum": ["meal", "travel", "equipment"],
|
|
118
|
+
"instructions": "What type of expense is this?",
|
|
119
|
+
},
|
|
120
|
+
"reimbursable": {
|
|
121
|
+
"type": "boolean",
|
|
122
|
+
"instructions": "Should this expense be reimbursed?",
|
|
123
|
+
},
|
|
124
|
+
"confidence": {
|
|
125
|
+
"type": "number",
|
|
126
|
+
"enum": [0.0, 0.25, 0.5, 0.75, 1.0],
|
|
127
|
+
"instructions": "How confident are you?",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
print(result)
|
|
133
|
+
# {
|
|
134
|
+
# "expense_type": "travel",
|
|
135
|
+
# "reimbursable": True,
|
|
136
|
+
# "confidence": 0.75,
|
|
137
|
+
# }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`questions` maps output field names to their definitions. Every field is answered.
|
|
141
|
+
The existing `schema=` JSON Schema interface is also supported; pass only one.
|
|
142
|
+
`state=` is an alias for `context=`; pass only one of them.
|
|
143
|
+
|
|
144
|
+
Python dictionary insertion order determines the decision order. Each later
|
|
145
|
+
field is conditioned on the original context and the values selected for all
|
|
146
|
+
earlier fields.
|
|
147
|
+
|
|
148
|
+
## Thinking mode
|
|
149
|
+
|
|
150
|
+
Thinking is off by default. Enable it when constructing the client:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
client = TypeLLMClient(
|
|
154
|
+
"http://127.0.0.1:30000",
|
|
155
|
+
model="Qwen/Qwen3.8-27B",
|
|
156
|
+
thinking=True, # False disables thinking (the default)
|
|
157
|
+
)
|
|
158
|
+
result = client.generate(context=context, questions=questions)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
No thinking-token budget is set by default. Optionally pass `thinking_budget=2048`
|
|
162
|
+
to cap reasoning per field. TypeLLM reserves context space for the final answer;
|
|
163
|
+
if thinking reaches its length limit, it keeps the partial reasoning, closes the
|
|
164
|
+
thinking block, and proceeds with constrained decoding. Server and network errors
|
|
165
|
+
still propagate.
|
|
166
|
+
|
|
167
|
+
## Testing
|
|
168
|
+
|
|
169
|
+
To run the 128-case numeric regression, first serve `Qwen/Qwen3.8-27B` with SGLang
|
|
170
|
+
at `http://127.0.0.1:30000`, then run:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
python3 _numeric_eval.py
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The evaluation covers integer and number extraction, arithmetic, negative
|
|
177
|
+
integers, and sequential dependencies. Its deterministic test cases are stored
|
|
178
|
+
in `evals/numeric_eval_cases.jsonl`; the script writes detailed results to
|
|
179
|
+
`evals/numeric_eval_formal_results.jsonl` and prints an aggregate summary.
|
|
180
|
+
|
|
181
|
+
## Output types
|
|
182
|
+
|
|
183
|
+
TypeLLM supports finite decisions, numeric fields, and free text:
|
|
184
|
+
|
|
185
|
+
| Field | Schema | Returned value |
|
|
186
|
+
|---|---|---|
|
|
187
|
+
| Text | `{"type": "string"}` | `str` |
|
|
188
|
+
| Integer | `{"type": "integer"}` | `int` |
|
|
189
|
+
| Number | `{"type": "number"}` | `float` |
|
|
190
|
+
| Boolean | `{"type": "boolean"}` | `bool` |
|
|
191
|
+
| Enum choice | `{"type": "string", "enum": ["meal", "travel"]}` | Candidate type: `str`, `int`, or `float` |
|
|
192
|
+
|
|
193
|
+
Enum choices support `string`, `integer`, and `number` types, with at most 16 values. The declared `type` validates the candidate values.
|
|
194
|
+
|
|
195
|
+
Generation works in three ways:
|
|
196
|
+
|
|
197
|
+
- **Choice** — Selects from finite candidates for enum and boolean fields.
|
|
198
|
+
- **Numeric** — Generates integers or numbers without `enum` token by token under numeric constraints.
|
|
199
|
+
- **Text** — Generates a JSON string for strings without `enum`, then decodes it to `str`.
|
|
200
|
+
|
|
201
|
+
A string without `enum` generates free text:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
result = client.generate(
|
|
205
|
+
context="The train ticket is for a client meeting.",
|
|
206
|
+
questions={
|
|
207
|
+
"summary": {"type": "string", "instructions": "Summarize in one sentence."},
|
|
208
|
+
},
|
|
209
|
+
)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`maxLength` is optional: add `"maxLength": 100` to limit Unicode character count.
|
|
213
|
+
Omitting it adds no character limit. Set `TypeLLMClient(text_max_tokens=512)` to
|
|
214
|
+
control the separate per-field generation budget (default 512 tokens).
|
|
215
|
+
Incomplete, invalid, or over-length text raises `SGLangError`.
|
|
216
|
+
Sequential fields can use earlier text; batch text fields generate independently.
|
|
217
|
+
Text generation uses
|
|
218
|
+
multiple tokens; type safety does not guarantee factual accuracy. Text fields
|
|
219
|
+
currently support `maxLength`, but not `minLength`, `pattern`, or `format`.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
For example, ask for a numeric answer without enumerating every possible value:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
result = client.generate(
|
|
226
|
+
context="Calculate the requested value accurately.",
|
|
227
|
+
questions={
|
|
228
|
+
"answer": {
|
|
229
|
+
"type": "number",
|
|
230
|
+
"instructions": "What is 17.5 multiplied by 4?",
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
print(result)
|
|
236
|
+
# {"answer": 70.0}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Use `instructions` to tell the model what decision to make:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
{
|
|
243
|
+
"type": "string",
|
|
244
|
+
"enum": ["billing", "technical", "account"],
|
|
245
|
+
"instructions": "Which team should handle this ticket?",
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
If `instructions` is omitted, TypeLLM uses `description` or an instruction
|
|
250
|
+
generated from the field name. Rename old `question` / `x-question` fields
|
|
251
|
+
to `instructions`.
|
|
252
|
+
|
|
253
|
+
## Sequential and batch execution
|
|
254
|
+
|
|
255
|
+
Sequential execution is the default:
|
|
256
|
+
|
|
257
|
+
Questions can express a complete decision workflow. For example, incident
|
|
258
|
+
triage might select, in order:
|
|
259
|
+
|
|
260
|
+
1. the affected system;
|
|
261
|
+
2. the severity, conditioned on that system;
|
|
262
|
+
3. whether to roll back, conditioned on both earlier decisions;
|
|
263
|
+
4. a confidence score.
|
|
264
|
+
|
|
265
|
+
Each field becomes a new user turn, and the assistant directly emits its
|
|
266
|
+
single-token label or constrained numeric value. The completed turn is appended
|
|
267
|
+
before the next question, so later decisions see the complete decision history.
|
|
268
|
+
The final accumulated prompt is available as `client.last_prompt`, or can be
|
|
269
|
+
printed with `print_final_prompt=True`.
|
|
270
|
+
|
|
271
|
+
When the fields are independent, run them as one native SGLang batch:
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
result = client.generate(
|
|
275
|
+
context=context,
|
|
276
|
+
questions=questions,
|
|
277
|
+
execution="batch",
|
|
278
|
+
)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Batch execution prefills the shared context once, then forks it into one branch
|
|
282
|
+
per field. Each branch appends only its own question and generates one token.
|
|
283
|
+
The completed branch prompts are available as `client.last_prompts`.
|
|
284
|
+
|
|
285
|
+
Use `sequential` when later decisions depend on earlier values. Use `batch`
|
|
286
|
+
only when every field may be decided independently from the shared context.
|
|
287
|
+
For actual concurrent execution, configure the SGLang server with
|
|
288
|
+
`--max-running-requests` at least as large as the desired number of branches.
|
|
289
|
+
|
|
290
|
+
### Batch performance
|
|
291
|
+
|
|
292
|
+
Batch execution supports any number of independent fields, subject to the
|
|
293
|
+
SGLang server's concurrency and memory limits. The shared context is prefilled
|
|
294
|
+
once, and every field becomes a branch containing only its own question and
|
|
295
|
+
one-token answer.
|
|
296
|
+
|
|
297
|
+
As one illustrative measurement, a local run used Qwen3.8-27B NVFP4 on one
|
|
298
|
+
NVIDIA RTX PRO 6000 Blackwell GPU, a roughly 1,100-token shared context, and
|
|
299
|
+
`K=16` one-token Boolean decisions. SGLang was configured with
|
|
300
|
+
`--max-running-requests 16`.
|
|
301
|
+
|
|
302
|
+
| Execution | End-to-end latency | Latency per decision | Relative throughput |
|
|
303
|
+
|---|---:|---:|---:|
|
|
304
|
+
| Sequential | 9.35 s | 0.584 s | 1.0x |
|
|
305
|
+
| Batch | 1.61 s | 0.101 s | 5.8x |
|
|
306
|
+
|
|
307
|
+
In this run, every branch reused 1,088 cached tokens, for 17,408 reused token
|
|
308
|
+
positions in total. This is a single example of the general batch method, not
|
|
309
|
+
a fixed-width design or a portable hardware benchmark. Latency depends on
|
|
310
|
+
`K`, the model, questions, context length, GPU, and server configuration.
|
|
311
|
+
|
|
312
|
+
The two modes intentionally compute different conditionals. Sequential mode
|
|
313
|
+
includes all earlier selected values in every later prompt. Batch mode gives
|
|
314
|
+
each branch only the common context and its own question, which enables
|
|
315
|
+
parallelism but removes cross-decision dependencies.
|
|
316
|
+
|
|
317
|
+
## Probabilities and sampling
|
|
318
|
+
|
|
319
|
+
Set `return_probabilities` on individual enum or boolean fields:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
result = client.generate(
|
|
323
|
+
context=context,
|
|
324
|
+
questions={
|
|
325
|
+
"expense_type": {
|
|
326
|
+
"type": "string",
|
|
327
|
+
"enum": ["meal", "travel", "equipment"],
|
|
328
|
+
"return_probabilities": True,
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
{
|
|
336
|
+
"expense_type": {
|
|
337
|
+
"value": "travel",
|
|
338
|
+
"probabilities": {
|
|
339
|
+
"meal": 0.04,
|
|
340
|
+
"travel": 0.93,
|
|
341
|
+
"equipment": 0.03,
|
|
342
|
+
},
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Only opted-in fields return `value` and `probabilities`; other fields return plain values.
|
|
348
|
+
The option is not supported on open Numeric or Text fields.
|
|
349
|
+
|
|
350
|
+
Argmax is the default. To enable sampling:
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
client = TypeLLMClient(
|
|
354
|
+
"http://127.0.0.1:30000",
|
|
355
|
+
mode="sample",
|
|
356
|
+
temperature=0.8,
|
|
357
|
+
seed=42,
|
|
358
|
+
)
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Sampling applies to finite candidates for Choice fields and to token generation
|
|
362
|
+
for Numeric and Text fields. `temperature` controls sampling in each case.
|
|
363
|
+
|
|
364
|
+
For a one-off request, use the convenience function:
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
from typellm import run_schema
|
|
368
|
+
|
|
369
|
+
result = run_schema(
|
|
370
|
+
context=context,
|
|
371
|
+
questions=questions,
|
|
372
|
+
base_url="http://127.0.0.1:30000",
|
|
373
|
+
model="Qwen/Qwen3.8-27B",
|
|
374
|
+
)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## Cost analysis
|
|
378
|
+
|
|
379
|
+
**Closed decisions generate one token per field, and prefix reuse makes the
|
|
380
|
+
newly processed input grow approximately linearly with the unique context
|
|
381
|
+
added across the workflow.** An open number requires one constrained step per
|
|
382
|
+
generated tokenizer token. The long original context is normally prefilled once
|
|
383
|
+
rather than recomputed for every decision.
|
|
384
|
+
|
|
385
|
+
For `D` decisions, an original context of `C` tokens, and roughly `S` newly
|
|
386
|
+
appended tokens per decision:
|
|
387
|
+
|
|
388
|
+
```text
|
|
389
|
+
without prefix reuse: O(D*C + D^2*S)
|
|
390
|
+
with prefix reuse: O(C + D*S)
|
|
391
|
+
output generation: O(D + N)
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Here `N` is the total number of generated tokenizer tokens in open numeric
|
|
395
|
+
fields, including their end-of-message tokens, and is zero for a fully finite
|
|
396
|
+
schema.
|
|
397
|
+
|
|
398
|
+
For `K` independent closed batch decisions with question lengths
|
|
399
|
+
`Q_1, ..., Q_K`, the corresponding prefill count is approximately
|
|
400
|
+
`C + sum(Q_k)`, followed by one batched decode step that produces `K` output
|
|
401
|
+
tokens. Open numeric fields require additional constrained token steps.
|
|
402
|
+
|
|
403
|
+
These are prefill token-position counts, not exact GPU FLOPs. New tokens still
|
|
404
|
+
attend to the cached prefix, and real latency also depends on cache alignment,
|
|
405
|
+
context length, batching, memory bandwidth, and cache eviction.
|
|
406
|
+
|
|
407
|
+
This describes self-hosted compute. A hosted provider may still bill the full
|
|
408
|
+
submitted input unless it offers cached-input pricing.
|
|
409
|
+
|
|
410
|
+
## License
|
|
411
|
+
|
|
412
|
+
[Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
typellm.py,sha256=nVjms8TaSRB-53E6L3JZgdiymXZ7XES9DUtRTQk2pm4,1009
|
|
2
|
+
typellm_benchmark.py,sha256=RTiH-UTH-cd370ZK15dx01WZXpOJN2iOKoSZesCt4e0,2887
|
|
3
|
+
typellm_cli.py,sha256=v0i5BlkIpUC8bNeTnVNwcJEQtWc5_eCqIjxiK2j8qaQ,3617
|
|
4
|
+
typellm_numeric.py,sha256=wC5ii-OOPgSmnkkvxYxzE1GUKJEzhavV1EjKQNUTe1s,4928
|
|
5
|
+
typellm_runtime.py,sha256=E1Ots8vmeRJ63HEmipOpBQVlKm9eFRlGeuhyDoHBs1I,35103
|
|
6
|
+
typellm_schema.py,sha256=3zuNMWSpJYan25US_l2o1UNLkucp8Q6DZv9tjfTKoyQ,8408
|
|
7
|
+
typellm_sglang.py,sha256=9i9hhmC2tpyR7uQVoMj2ViYmOYmeZZBAAY6gSDyK6A4,22343
|
|
8
|
+
typellm-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
9
|
+
typellm-0.1.0.dist-info/METADATA,sha256=TIXUmDgiVeTX-q9nd34keY3yvKeLm1aJhx7k62pcg6M,13751
|
|
10
|
+
typellm-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
11
|
+
typellm-0.1.0.dist-info/entry_points.txt,sha256=IRyCcV44CIIWyjUeC_hAJZINPVO1Kr-7Gu2F10U0NYo,45
|
|
12
|
+
typellm-0.1.0.dist-info/top_level.txt,sha256=P3QUKjOhXxB-h75RsKlA_QHzWXXlW0lXZcKZzivHSkA,100
|
|
13
|
+
typellm-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
typellm.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Public compatibility facade for the TypeLLM prototype.
|
|
3
|
+
|
|
4
|
+
The implementation is split by responsibility; imports from this module remain
|
|
5
|
+
stable for existing callers, and ``python typellm.py`` still launches the demo.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typellm_benchmark import benchmark_prefix_cache
|
|
9
|
+
from typellm_cli import example_schema, main
|
|
10
|
+
from typellm_runtime import (
|
|
11
|
+
Choice,
|
|
12
|
+
TypeLLMClient,
|
|
13
|
+
candidate_softmax,
|
|
14
|
+
run_schema,
|
|
15
|
+
run_sequential_decisions,
|
|
16
|
+
)
|
|
17
|
+
from typellm_schema import (
|
|
18
|
+
MAX_ENUM_CHOICES,
|
|
19
|
+
Decision,
|
|
20
|
+
SchemaError,
|
|
21
|
+
compile_json_schema,
|
|
22
|
+
)
|
|
23
|
+
from typellm_sglang import SGLangClient, SGLangError, extract_candidate_logprobs
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"Choice",
|
|
28
|
+
"Decision",
|
|
29
|
+
"MAX_ENUM_CHOICES",
|
|
30
|
+
"SGLangClient",
|
|
31
|
+
"SGLangError",
|
|
32
|
+
"SchemaError",
|
|
33
|
+
"TypeLLMClient",
|
|
34
|
+
"benchmark_prefix_cache",
|
|
35
|
+
"candidate_softmax",
|
|
36
|
+
"compile_json_schema",
|
|
37
|
+
"example_schema",
|
|
38
|
+
"run_schema",
|
|
39
|
+
"run_sequential_decisions",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|