llm2decision 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm2decision-0.1.0/.github/workflows/tests.yml +18 -0
- llm2decision-0.1.0/.gitignore +7 -0
- llm2decision-0.1.0/LICENSE +202 -0
- llm2decision-0.1.0/PKG-INFO +343 -0
- llm2decision-0.1.0/README.md +316 -0
- llm2decision-0.1.0/pyproject.toml +53 -0
- llm2decision-0.1.0/src/llm2decision/__init__.py +20 -0
- llm2decision-0.1.0/src/llm2decision/__main__.py +63 -0
- llm2decision-0.1.0/src/llm2decision/_http.py +127 -0
- llm2decision-0.1.0/src/llm2decision/auth.py +144 -0
- llm2decision-0.1.0/src/llm2decision/bench.py +189 -0
- llm2decision-0.1.0/src/llm2decision/check.py +194 -0
- llm2decision-0.1.0/src/llm2decision/client.py +289 -0
- llm2decision-0.1.0/src/llm2decision/config.py +217 -0
- llm2decision-0.1.0/src/llm2decision/configs/forms.json +5 -0
- llm2decision-0.1.0/src/llm2decision/configs/models.json +250 -0
- llm2decision-0.1.0/src/llm2decision/configs/providers.json +42 -0
- llm2decision-0.1.0/src/llm2decision/errors.py +39 -0
- llm2decision-0.1.0/src/llm2decision/marks.py +237 -0
- llm2decision-0.1.0/src/llm2decision/prompt.py +60 -0
- llm2decision-0.1.0/src/llm2decision/py.typed +0 -0
- llm2decision-0.1.0/src/llm2decision/transports.py +316 -0
- llm2decision-0.1.0/src/llm2decision/types.py +205 -0
- llm2decision-0.1.0/tests/fake.py +63 -0
- llm2decision-0.1.0/tests/llm_server.py +262 -0
- llm2decision-0.1.0/tests/test_anthropic.py +101 -0
- llm2decision-0.1.0/tests/test_auth.py +217 -0
- llm2decision-0.1.0/tests/test_bench.py +131 -0
- llm2decision-0.1.0/tests/test_check.py +133 -0
- llm2decision-0.1.0/tests/test_client.py +448 -0
- llm2decision-0.1.0/tests/test_config.py +123 -0
- llm2decision-0.1.0/tests/test_failures.py +94 -0
- llm2decision-0.1.0/tests/test_marks.py +311 -0
- llm2decision-0.1.0/tests/test_transports.py +86 -0
- llm2decision-0.1.0/uv.lock +1046 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v6
|
|
18
|
+
- run: uv run --python ${{ matrix.python }} --group dev pytest -q tests
|
|
@@ -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 2026 Mikhail Gribov
|
|
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.
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: llm2decision
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn any LLM into a decision model: a probability for each predefined option of a question about a text, through a Jev-compatible API
|
|
5
|
+
Project-URL: Homepage, https://github.com/mihail-gribov/llm2decision
|
|
6
|
+
Project-URL: Source, https://github.com/mihail-gribov/llm2decision
|
|
7
|
+
Project-URL: Issues, https://github.com/mihail-gribov/llm2decision/issues
|
|
8
|
+
Author-email: Mikhail Gribov <mihail.gribov.rs@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: calibration,classification,decision,guardrails,llm,llm-as-judge,logprobs
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Provides-Extra: template
|
|
24
|
+
Requires-Dist: jinja2>=3.1; extra == 'template'
|
|
25
|
+
Requires-Dist: transformers>=5.0; extra == 'template'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# llm2decision
|
|
29
|
+
|
|
30
|
+
[](https://github.com/mihail-gribov/llm2decision/actions/workflows/tests.yml)
|
|
31
|
+
[](https://pypi.org/project/llm2decision/)
|
|
32
|
+
[](https://pypi.org/project/llm2decision/)
|
|
33
|
+
[](https://github.com/mihail-gribov/llm2decision/blob/main/pyproject.toml)
|
|
34
|
+
[](https://github.com/mihail-gribov/llm2decision/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
**Turn any LLM into a decision model.** Ask a question about a text and get a probability for
|
|
37
|
+
each predefined option, from the model you already use, hosted or on your own server.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Text: I love the headphones, but the left ear cushion already came off after a week.
|
|
41
|
+
Question: Is the customer complaining?
|
|
42
|
+
|
|
43
|
+
Qwen3.8-27B in a chat:
|
|
44
|
+
Yes, the customer is complaining. While they start with a positive statement ("I love the
|
|
45
|
+
headphones"), the core of their message is reporting a significant defect or failure of the
|
|
46
|
+
product (the left ear cushion detaching after just one week). This indicates dissatisfaction
|
|
47
|
+
with the quality, durability, or performance of the item, which constitutes a complaint that
|
|
48
|
+
likely requires customer service intervention, such as a repair or replacement.
|
|
49
|
+
|
|
50
|
+
The same model through llm2decision:
|
|
51
|
+
0.97 (the probability of "yes")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- **Your choice of model.** Use the model that does best on your tasks: large or small, through an
|
|
55
|
+
API (Nebius, OpenAI, Anthropic, OpenRouter, Mistral) or on your own server (vLLM, SGLang,
|
|
56
|
+
llama.cpp, Ollama). The code stays the same, and switching is one string. Code written for
|
|
57
|
+
TypeSafe Jev moves over by changing the import.
|
|
58
|
+
- **Probabilities you can set thresholds on.** Where the provider returns token probabilities, they
|
|
59
|
+
are calibrated per model, so an answer given with 0.9 is right about 90% of the time. Act on
|
|
60
|
+
confident answers and send the rest to a person.
|
|
61
|
+
- **Nothing to parse.** The answer is always one of your options, or explicitly marked undecided.
|
|
62
|
+
- **Cheap.** Output tokens cost several times more than input ones, and the model writes a token or
|
|
63
|
+
a few instead of an explanation, so you pay mostly for the cheaper input.
|
|
64
|
+
- **Measured.** Every tested model has its accuracy, undecided share and calibration error on the
|
|
65
|
+
same 3 358 questions (section 4), and one command measures your own.
|
|
66
|
+
- **Zero required dependencies**, only the standard library of Python 3.10+.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
pip install llm2decision
|
|
72
|
+
export NEBIUS_API_KEY=...
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import llm2decision as l2d
|
|
77
|
+
|
|
78
|
+
client = l2d.DecisionClient("qwen3.8-27b@nebius")
|
|
79
|
+
|
|
80
|
+
document = "I love the headphones, but the left ear cushion already came off after a week."
|
|
81
|
+
questions = {"complaint": l2d.Noul(instructions="Is the customer complaining?")}
|
|
82
|
+
answers = client.system_one(document, questions)
|
|
83
|
+
|
|
84
|
+
print(answers.nouls["complaint"].noul) # the probability of "yes": 0.97
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`Noul` is a yes/no question; section 3 lists the other types. The numbers in the examples come
|
|
88
|
+
from real runs: a rerun can differ in the second decimal, and another model gives other numbers.
|
|
89
|
+
|
|
90
|
+
## 1. Connect
|
|
91
|
+
|
|
92
|
+
Name a tested model or a provider and any of its models. `qwen3.8-27b@nebius`, used in the
|
|
93
|
+
examples, and `gpt-5.4@openai` are good to start with; section 4 compares all 21.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import llm2decision as l2d
|
|
97
|
+
|
|
98
|
+
l2d.DecisionClient("qwen3.8-27b@nebius") # a tested model (section 4)
|
|
99
|
+
l2d.DecisionClient("qwen3.8-27b") # the same, when the name is unique
|
|
100
|
+
l2d.DecisionClient("google/gemini-2.5-flash", provider="openrouter") # any model of a provider
|
|
101
|
+
l2d.DecisionClient("Qwen/Qwen3-8B", base_url="http://localhost:8000/v1") # your own server, no key
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
| provider | `provider=` | key variable | answers |
|
|
105
|
+
|---|---|---|---|
|
|
106
|
+
| your own server (vLLM, SGLang, llama.cpp, Ollama) | `"local"`, or just `base_url=` | — | with probabilities |
|
|
107
|
+
| Nebius | `"nebius"` | `NEBIUS_API_KEY` | with probabilities |
|
|
108
|
+
| OpenRouter | `"openrouter"` | `OPENROUTER_API_KEY` | with probabilities where the model gives them |
|
|
109
|
+
| OpenAI | `"openai"` | `OPENAI_API_KEY` | text |
|
|
110
|
+
| Anthropic | `"anthropic"` | `ANTHROPIC_API_KEY` | text |
|
|
111
|
+
| Mistral | `"mistral"` | `MISTRAL_API_KEY` | text |
|
|
112
|
+
|
|
113
|
+
Keys: the provider's variable, `api_key=` (a string or a function), `key_env=` or `env_file=`.
|
|
114
|
+
|
|
115
|
+
## 2. Check the model
|
|
116
|
+
|
|
117
|
+
Before relying on a model that is not in the table of section 4, run the check with the same
|
|
118
|
+
arguments you connect with — a provider, or the `base_url` of your own server:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
llm2decision check google/gemini-2.5-flash --provider openrouter
|
|
122
|
+
llm2decision check Qwen/Qwen3-8B --base-url http://localhost:8000/v1
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
It sends about a dozen easy questions and reports, point by point, whether the model is reachable,
|
|
126
|
+
answers in the expected form, gets the easy questions right, returns probabilities and keeps
|
|
127
|
+
reasoning off. A failed point names the reason. `client.check()` does the same in code, and
|
|
128
|
+
`--save` remembers a pass so that later answers carry `meta.checked`.
|
|
129
|
+
|
|
130
|
+
Then try the model on a few dozen questions of your own and look at `meta.answered`: a model that
|
|
131
|
+
passes the easy questions can still refuse to decide on hard ones.
|
|
132
|
+
|
|
133
|
+
To compare a model with the table of section 4, measure it on the same
|
|
134
|
+
[Decision Questions](https://huggingface.co/datasets/mihailgribov/decision-questions) set:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
llm2decision bench Qwen/Qwen3-8B --base-url http://localhost:8000/v1
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
It asks the 3 358 questions one by one (on a hosted model, at your provider's prices; `--limit`
|
|
141
|
+
takes the first N), saves the answers as they come, continues where it stopped when run again, and
|
|
142
|
+
prints accuracy by question type, the share of undecided questions and the calibration error.
|
|
143
|
+
|
|
144
|
+
## 3. Ask questions
|
|
145
|
+
|
|
146
|
+
Several questions about one text go in a single call:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import llm2decision as l2d
|
|
150
|
+
|
|
151
|
+
message = "Hi, I was charged twice for order #4411, please refund the extra payment."
|
|
152
|
+
|
|
153
|
+
with l2d.DecisionClient("qwen3.8-27b@nebius") as client:
|
|
154
|
+
answers = client.system_one(
|
|
155
|
+
message,
|
|
156
|
+
{
|
|
157
|
+
"refund": l2d.Noul(instructions="Does the customer ask for money back?"),
|
|
158
|
+
"team": l2d.Choice(instructions="Which team should handle this?",
|
|
159
|
+
criteria={"billing": "Payments and refunds", "shipping": "Delivery",
|
|
160
|
+
"tech": "Bugs and errors"}),
|
|
161
|
+
},
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
answers.nouls["refund"].noul # 0.998 — P(yes)
|
|
165
|
+
answers.choices["team"].choice # "billing"
|
|
166
|
+
answers.choices["team"].probabilities # {"billing": 0.999, "shipping": 0.0, "tech": 0.001}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
| type | question | use it when | answer |
|
|
170
|
+
|---|---|---|---|
|
|
171
|
+
| `l2d.Noul(instructions=…, criteria={"true": …, "false": …})` | yes / no | the text settles it either way | `.noul` — P(yes) |
|
|
172
|
+
| `l2d.Tfu(instructions=…, criteria={"true": …, "false": …, "unknown": …})` | **t**rue / **f**alse / **u**nknown | the text may not settle it, and "unknown" should be an answer rather than a guess | `.tfu` — `"true"`, `"false"` or `"unknown"`, with `.probabilities` |
|
|
173
|
+
| `l2d.Choice(instructions=…, criteria={label: description, …})` | choice | one of several named options | `.choice`, `.confidence`, `.probabilities` |
|
|
174
|
+
| `l2d.Score(instructions=…, criteria=[level 0, level 1, …])` | score | a level on an ordered scale | `.score` — the expected level, `.probabilities` per level |
|
|
175
|
+
|
|
176
|
+
The answers come back grouped by type, under the names you gave the questions: `answers.nouls`,
|
|
177
|
+
`.tfus`, `.choices` and `.scores`.
|
|
178
|
+
|
|
179
|
+
When the text may not settle the question, `Tfu` makes "unknown" an answer of its own:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
import llm2decision as l2d
|
|
183
|
+
|
|
184
|
+
client = l2d.DecisionClient("qwen3.8-27b@nebius")
|
|
185
|
+
document = "The parcel came a week late and the box was dented, but everything inside works fine."
|
|
186
|
+
questions = {"satisfied": l2d.Tfu(instructions="Is the customer satisfied with the order?")}
|
|
187
|
+
|
|
188
|
+
client.system_one(document, questions).tfus["satisfied"].probabilities
|
|
189
|
+
# {"true": 0.082, "false": 0.107, "unknown": 0.811}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`criteria` are optional for yes/no questions; write them when "yes" needs defining. For a `Choice`,
|
|
193
|
+
describe every option, because the description is what the model judges by. The questions of a
|
|
194
|
+
call run in parallel, and the text can be a string or any JSON-serialisable object.
|
|
195
|
+
|
|
196
|
+
Every answer carries `meta`, and `meta.answered` is the field to act on: it is False when the
|
|
197
|
+
model refused to decide, and the probabilities of such an answer mean nothing. A typical handler
|
|
198
|
+
acts on confident answers and passes the rest on:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
answer = answers.choices["team"]
|
|
202
|
+
if answer.meta.answered and answer.confidence >= 0.9:
|
|
203
|
+
route(message, answer.choice)
|
|
204
|
+
else:
|
|
205
|
+
send_to_person(message) # undecided or unsure
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
With `strict=True` an undecided answer raises `l2d.UnreadableAnswer` instead. The other `meta`
|
|
209
|
+
fields say how the answer was obtained:
|
|
210
|
+
|
|
211
|
+
| field | meaning |
|
|
212
|
+
|---|---|
|
|
213
|
+
| `logprobs` | True: read from the model's token probabilities; False: from the text it wrote, so the probabilities are 1 and 0 and a threshold does nothing |
|
|
214
|
+
| `calibrated` | the probabilities were calibrated for this model (section 5) |
|
|
215
|
+
| `checked` | the model passed `check()` and the pass was saved (section 2) |
|
|
216
|
+
|
|
217
|
+
`answers.to_dict()` gives the whole response as plain data.
|
|
218
|
+
|
|
219
|
+
## 4. Choose a model
|
|
220
|
+
|
|
221
|
+
The models tested with the package, by accuracy on Decision Questions:
|
|
222
|
+
|
|
223
|
+
| model | Decision Questions | JevBench | undecided | calibration error |
|
|
224
|
+
|---|---|---|---|---|
|
|
225
|
+
| `claude-sonnet-5.5@anthropic` | **0.948** | 0.954 | 5.7% | no probabilities |
|
|
226
|
+
| `gpt-5.4@openai` | **0.936** | 0.896 | 1.4% | no probabilities |
|
|
227
|
+
| `kimi-k2.6@nebius` | **0.917** | 0.882 | 1.1% | 0.017 |
|
|
228
|
+
| `claude-haiku-5.5@anthropic` | **0.915** | 0.862 | 5.7% | no probabilities |
|
|
229
|
+
| `qwen3.8-27b@nebius` | **0.913** | 0.885 | 0.8% | 0.023 |
|
|
230
|
+
| `minimax-m3@nebius` | **0.912** | 0.850 | 1.7% | 0.024 |
|
|
231
|
+
| `deepseek-v4-pro@nebius` | **0.912** | 0.864 | 1.5% | 0.021 |
|
|
232
|
+
| `qwen3.5-397b@nebius` | **0.907** | 0.860 | 0.8% | 0.024 |
|
|
233
|
+
| `claude-haiku-4.5@anthropic` | **0.905** | 0.855 | 1.7% | no probabilities |
|
|
234
|
+
| `nemotron-3-ultra@nebius` | **0.901** | 0.855 | 0.8% | 0.020 |
|
|
235
|
+
| `gemini-2.5-flash@openrouter` | **0.896** | 0.878 | 1.0% | no probabilities |
|
|
236
|
+
| `hermes-4-405b@nebius` | **0.888** | 0.857 | 0.4% | 0.022 |
|
|
237
|
+
| `qwen3-235b@nebius` | **0.884** | 0.838 | 0.8% | 0.024 |
|
|
238
|
+
| `gpt-5.4-mini@openai` | **0.875** | 0.840 | 0.5% | no probabilities |
|
|
239
|
+
| `nemotron-3-super@nebius` | **0.842** | 0.804 | 0.2% | 0.028 |
|
|
240
|
+
| `ministral-14b@mistral` | **0.836** | 0.830 | 0.7% | no probabilities |
|
|
241
|
+
| `qwen3-30b-a3b@nebius` | **0.833** | 0.800 | 0.5% | 0.034 |
|
|
242
|
+
| `gpt-oss-120b@nebius` | **0.830** | 0.779 | 0.7% | 0.031 |
|
|
243
|
+
| `gemma-3-27b@nebius` | **0.818** | 0.730 | 0.4% | 0.064 |
|
|
244
|
+
| `nemotron-3-nano@nebius` | **0.756** | 0.709 | 1.1% | 0.051 |
|
|
245
|
+
| `nemotron-3.5-lightning@nebius` | **0.734** | 0.753 | 0.1% | 0.051 |
|
|
246
|
+
|
|
247
|
+
- **Decision Questions** — accuracy on
|
|
248
|
+
[Decision Questions](https://huggingface.co/datasets/mihailgribov/decision-questions), 3 358
|
|
249
|
+
questions across many domains; `llm2decision bench` measures it for any model (section 2), and
|
|
250
|
+
[`benchmark/`](https://github.com/mihail-gribov/llm2decision/tree/main/benchmark) has every
|
|
251
|
+
model's answers.
|
|
252
|
+
- **JevBench** — accuracy on the 231 public tasks of
|
|
253
|
+
[JevBench](https://github.com/fstandhartinger/jevbench), not its own score; differences under
|
|
254
|
+
~5 points are noise.
|
|
255
|
+
- **undecided** — share of questions the model refused to decide. Accuracy leaves them out, so read
|
|
256
|
+
the two columns together.
|
|
257
|
+
- **calibration error** — how far the stated probabilities are from how often the model is right
|
|
258
|
+
(lower is better). *no probabilities*: the provider answers in text.
|
|
259
|
+
|
|
260
|
+
How to pick:
|
|
261
|
+
|
|
262
|
+
- **The most accurate:** `claude-sonnet-5.5`, but it refuses to decide about 6% of questions, so
|
|
263
|
+
you need a fallback for those; `gpt-5.4` decides nearly everything and comes next.
|
|
264
|
+
- **A confidence you can set thresholds on:** a model with a low calibration error. `qwen3.8-27b`,
|
|
265
|
+
`kimi-k2.6` and `qwen3.5-397b` are within 3 points of `gpt-5.4`.
|
|
266
|
+
- **Volume at a lower price:** `qwen3-30b-a3b` (0.833) and `gpt-oss-120b` (0.830) are calibrated and
|
|
267
|
+
cost $0.10 and $0.15 per million input tokens on Nebius, against $0.45 for `qwen3.8-27b`.
|
|
268
|
+
- **The lowest price, when accuracy around 0.75 is enough:** `nemotron-3-nano` and
|
|
269
|
+
`nemotron-3.5-lightning`, $0.06 per million input tokens on Nebius.
|
|
270
|
+
- **Data that must not leave your hardware:** any model on your own OpenAI-compatible server,
|
|
271
|
+
checked as in section 2.
|
|
272
|
+
|
|
273
|
+
Prices are Nebius list prices of October 2026.
|
|
274
|
+
|
|
275
|
+
Whatever the model, yes/no/unknown and rubric scores are the hardest question types (`bench`
|
|
276
|
+
prints accuracy per type), so where a decision matters, a yes/no or a choice question gets better
|
|
277
|
+
answers.
|
|
278
|
+
|
|
279
|
+
## 5. Tune
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
l2d.DecisionClient(model, *, provider=None, base_url=None, api_key=None, key_env=None, env_file=None,
|
|
283
|
+
timeout=120.0, retries=6, workers=8, calibrated=True, strict=False)
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
`workers` is how many questions of one call go out in parallel. `timeout` and `retries` apply per
|
|
287
|
+
request: rate limits, server errors and dropped connections are retried with backoff, while a
|
|
288
|
+
refused request or an exhausted balance fails at once. The connection arguments (`provider`,
|
|
289
|
+
`base_url`, `api_key`, `key_env`, `env_file`) are described in section 1, and `strict` in section 3.
|
|
290
|
+
|
|
291
|
+
By default (`calibrated=True`) the probabilities of a model from the table are calibrated: the
|
|
292
|
+
model's own ones are rescaled so that an answer given with 0.8 is right about 80% of the time. The
|
|
293
|
+
rescaling makes them sharper or softer but never changes which answer is the most likely. A model
|
|
294
|
+
without a calibration (your own, or one that answers in text) is returned as it is, and
|
|
295
|
+
`meta.calibrated` says which case you got. `calibrated=False` returns the model's own probabilities.
|
|
296
|
+
|
|
297
|
+
A single call can override the model, the timeout and the request:
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
client.system_one(text, questions,
|
|
301
|
+
model="qwen3-235b", # same provider and key
|
|
302
|
+
timeout=10,
|
|
303
|
+
extra_headers={"X-Trace": "…"},
|
|
304
|
+
extra_body={"priority": 1}) # merged into the request
|
|
305
|
+
|
|
306
|
+
async with l2d.AsyncDecisionClient("qwen3.8-27b@nebius") as client:
|
|
307
|
+
answers = await client.system_one(text, questions)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
All errors derive from `l2d.LLM2DecisionError`: `QuestionError` names a malformed question before
|
|
311
|
+
any request is sent, `AuthError` and `ConfigError` come from the setup, `TransportError` means the
|
|
312
|
+
provider refused or kept failing, and `UnreadableAnswer` means the model refused to decide
|
|
313
|
+
(`meta.answered` is False) and is raised only with `strict=True`.
|
|
314
|
+
|
|
315
|
+
## 6. Your own models
|
|
316
|
+
|
|
317
|
+
Files named `models.json`, `providers.json` and `forms.json` in `$LLM2DECISION_HOME` (default
|
|
318
|
+
`~/.config/llm2decision`) are read on top of the package's own, field by field. A model of your own
|
|
319
|
+
gets a short name, and a model that answers in another language learns its words for yes and no:
|
|
320
|
+
|
|
321
|
+
```json
|
|
322
|
+
{
|
|
323
|
+
"my-qwen@local": {"provider": "local", "model": "Qwen/Qwen3-8B"},
|
|
324
|
+
"my-french@local": {"provider": "local", "model": "…", "forms": {"true": ["oui"], "false": ["non"]}}
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
`llm2decision models` and `l2d.list_models()` include your models.
|
|
329
|
+
|
|
330
|
+
Some servers cannot continue an answer that the package has started. For your own model on such a
|
|
331
|
+
server, the package renders the model's chat template itself, which needs the only optional extra:
|
|
332
|
+
`pip install "llm2decision[template]"` (transformers and jinja2).
|
|
333
|
+
|
|
334
|
+
## Limits
|
|
335
|
+
|
|
336
|
+
- This version answers without reasoning, so models that cannot switch reasoning off, such as
|
|
337
|
+
Gemini 3, are not supported.
|
|
338
|
+
- Text only: images are not supported yet.
|
|
339
|
+
- Calibration was done on English decision questions and may be off on very different material.
|
|
340
|
+
|
|
341
|
+
## License
|
|
342
|
+
|
|
343
|
+
Apache-2.0. The base install has no third-party dependencies to license.
|