jevper 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.
- jevper-0.1.0/.github/workflows/release.yml +43 -0
- jevper-0.1.0/.gitignore +8 -0
- jevper-0.1.0/LICENSE +202 -0
- jevper-0.1.0/PKG-INFO +240 -0
- jevper-0.1.0/README.md +212 -0
- jevper-0.1.0/docs/api.md +219 -0
- jevper-0.1.0/docs/few-shot.md +81 -0
- jevper-0.1.0/docs/internals.md +149 -0
- jevper-0.1.0/docs/methods.md +174 -0
- jevper-0.1.0/docs/reasoning.md +94 -0
- jevper-0.1.0/pyproject.toml +41 -0
- jevper-0.1.0/src/jevper/__init__.py +77 -0
- jevper-0.1.0/src/jevper/client.py +671 -0
- jevper-0.1.0/src/jevper/errors.py +37 -0
- jevper-0.1.0/src/jevper/labels.py +41 -0
- jevper-0.1.0/src/jevper/methods.py +322 -0
- jevper-0.1.0/src/jevper/normalize.py +57 -0
- jevper-0.1.0/src/jevper/prompts.py +226 -0
- jevper-0.1.0/src/jevper/py.typed +0 -0
- jevper-0.1.0/src/jevper/reasoning.py +72 -0
- jevper-0.1.0/src/jevper/transport.py +398 -0
- jevper-0.1.0/src/jevper/types.py +204 -0
- jevper-0.1.0/tests/conftest.py +28 -0
- jevper-0.1.0/tests/fakes.py +205 -0
- jevper-0.1.0/tests/test_client_behaviour.py +250 -0
- jevper-0.1.0/tests/test_few_shot.py +232 -0
- jevper-0.1.0/tests/test_grammar_structured.py +217 -0
- jevper-0.1.0/tests/test_live.py +60 -0
- jevper-0.1.0/tests/test_logprobs_methods.py +139 -0
- jevper-0.1.0/tests/test_reasoning.py +136 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Release: tag `vX.Y.Z` -> run the suite, build, publish to PyPI.
|
|
2
|
+
#
|
|
3
|
+
# Publishing uses PyPI trusted publishing (OIDC), so no API token is stored in
|
|
4
|
+
# this repository. One-time setup on PyPI:
|
|
5
|
+
#
|
|
6
|
+
# pypi.org -> Account -> Publishing -> "Add a pending publisher"
|
|
7
|
+
# PyPI project name: jevper
|
|
8
|
+
# Owner: zhulinchng
|
|
9
|
+
# Repository name: jevper
|
|
10
|
+
# Workflow name: release.yml
|
|
11
|
+
# Environment name: pypi
|
|
12
|
+
#
|
|
13
|
+
# Then: bump `version` in pyproject.toml, commit, and `git push origin vX.Y.Z`.
|
|
14
|
+
# If the project is instead published with an API token, replace the publish
|
|
15
|
+
# step's `password` with `${{ secrets.PYPI_API_TOKEN }}` and drop `id-token`.
|
|
16
|
+
|
|
17
|
+
name: release
|
|
18
|
+
|
|
19
|
+
on:
|
|
20
|
+
push:
|
|
21
|
+
tags: ["v*"]
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
test:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- uses: astral-sh/setup-uv@v5
|
|
29
|
+
- run: uv venv --python 3.12
|
|
30
|
+
- run: uv pip install --python .venv/bin/python -e '.[test]'
|
|
31
|
+
- run: .venv/bin/python -m pytest -q
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
needs: test
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
environment: pypi
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: astral-sh/setup-uv@v5
|
|
42
|
+
- run: uv build
|
|
43
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
jevper-0.1.0/.gitignore
ADDED
jevper-0.1.0/LICENSE
ADDED
|
@@ -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 Zhu Lin
|
|
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.
|
jevper-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: jevper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Jev-shaped (TypeSafe System One) classification wrapper over OpenAI-like clients
|
|
5
|
+
Project-URL: Homepage, https://github.com/zhulinchng/jevper
|
|
6
|
+
Project-URL: Repository, https://github.com/zhulinchng/jevper
|
|
7
|
+
Project-URL: Issues, https://github.com/zhulinchng/jevper/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/zhulinchng/jevper/releases
|
|
9
|
+
Author-email: Zhu Lin <zhulin@czl.my>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: classification,confidence,jev,llm,logprobs,openai,structured-output,system-one
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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
|
+
Requires-Dist: pydantic>=2.7
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: openai>=1.40; extra == 'test'
|
|
26
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# jevper
|
|
30
|
+
|
|
31
|
+
`jevper` wraps any OpenAI-like client and gives you a [Jev](https://docs.typesafe.ai) (TypeSafe System One)
|
|
32
|
+
shaped answer instead of prose: you send a `state` plus typed `questions`, and you get back probabilities and
|
|
33
|
+
confidence.
|
|
34
|
+
|
|
35
|
+
It does not call the hosted TypeSafe API and does not depend on `typesafe-sdk` or `openai` at runtime — the
|
|
36
|
+
client object is duck-typed. Any object exposing `responses.create` or `chat.completions.create` works,
|
|
37
|
+
including a self-hosted llama.cpp server.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from openai import OpenAI
|
|
41
|
+
from jevper import Choice, SystemOneClient
|
|
42
|
+
|
|
43
|
+
client = SystemOneClient(OpenAI(), model="gpt-5.6-terra", method="logprobs")
|
|
44
|
+
|
|
45
|
+
response = client.system_one(
|
|
46
|
+
state="I was charged twice for the same subscription this month.",
|
|
47
|
+
questions={
|
|
48
|
+
"intent": Choice(
|
|
49
|
+
instructions="Pick the intent of the message.",
|
|
50
|
+
criteria={
|
|
51
|
+
"billing": "money, invoices, refunds, charges",
|
|
52
|
+
"technical": "errors, crashes, login or performance problems",
|
|
53
|
+
"sales": "pricing, plans, purchasing, upgrades",
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
answer = response.answers["intent"]
|
|
60
|
+
answer.choice # "billing"
|
|
61
|
+
answer.probabilities # {"billing": 0.88, "technical": 0.08, "sales": 0.03}
|
|
62
|
+
answer.confidence # 0.83
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
pip install jevper
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Python 3.10+. The only runtime dependency is `pydantic>=2.7`.
|
|
72
|
+
|
|
73
|
+
For development:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
git clone https://github.com/zhulinchng/jevper && cd jevper
|
|
77
|
+
uv venv && uv pip install -e '.[test]'
|
|
78
|
+
pytest -q
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## What one call does
|
|
82
|
+
|
|
83
|
+
```mermaid
|
|
84
|
+
flowchart LR
|
|
85
|
+
A["state + questions"] --> B["build_messages: system prompt, state turns, few-shot turns, question block"]
|
|
86
|
+
B --> C{"method"}
|
|
87
|
+
C -->|logprobs| D["logprobs=true, top_logprobs=20"]
|
|
88
|
+
C -->|grammar| E["+ GBNF grammar in extra_body"]
|
|
89
|
+
C -->|structured| F["strict JSON schema: probabilities"]
|
|
90
|
+
C -->|discrete| G["strict JSON schema: one label"]
|
|
91
|
+
D --> H["first label token -> softmax over the labels"]
|
|
92
|
+
E --> H
|
|
93
|
+
F --> I["probability dict from JSON"]
|
|
94
|
+
G --> J["one-hot from the chosen label"]
|
|
95
|
+
H --> K["Answer: choice / noul / score"]
|
|
96
|
+
I --> K
|
|
97
|
+
J --> K
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Each question becomes its own provider call, so questions are independent and run concurrently
|
|
101
|
+
(`max_concurrency`, default 8). Answers come back keyed by your question ids, in insertion order.
|
|
102
|
+
|
|
103
|
+
## Questions
|
|
104
|
+
|
|
105
|
+
Three types, mirroring the Jev API:
|
|
106
|
+
|
|
107
|
+
| Type | Criteria | Answer |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `Noul(instructions=..., criteria={"true": ..., "false": ...})` | optional | `{"type": "noul", "noul": 0.93}` |
|
|
110
|
+
| `Choice(instructions=..., criteria={"billing": "...", ...})` | 2–26 keys | `{"type": "choice", "choice": "billing", "probabilities": {...}, "confidence": 0.83}` |
|
|
111
|
+
| `Score(instructions=..., criteria=["Calm", "Frustrated", "Very angry"])` | 2–10 levels | `{"type": "score", "score": 1.05, "legend": {...}, "probabilities": {...}, "confidence": 0.92}` |
|
|
112
|
+
|
|
113
|
+
`Score.score` is the probability-weighted level index (`Σ i·pᵢ`, levels zero-based), as in the Jev API.
|
|
114
|
+
`Choice` is capped at 26 options because every method labels options with single letters `A`–`Z`; a larger
|
|
115
|
+
question raises `InvalidQuestionError` telling you to split it.
|
|
116
|
+
|
|
117
|
+
Questions can also be passed as raw mappings (`{"type": "choice", "criteria": {...}}`) and are validated the
|
|
118
|
+
same way.
|
|
119
|
+
|
|
120
|
+
## Methods
|
|
121
|
+
|
|
122
|
+
`method=` decides how the decision is elicited. All four share the same 26-label cap and the same
|
|
123
|
+
label→option mapping, so switching methods does not change your types.
|
|
124
|
+
|
|
125
|
+
| Method | Request | Readout | Needs |
|
|
126
|
+
| --- | --- | --- | --- |
|
|
127
|
+
| `logprobs` (default) | `logprobs=true, top_logprobs=20` | softmax over the labels' logprobs of the first answer token | a provider that returns chat logprobs (or the Responses surface with `include` logprobs) |
|
|
128
|
+
| `grammar` | the same plus a GBNF `grammar` in `extra_body` | same as `logprobs` | a Chat Completions server that accepts `grammar` (llama.cpp and friends) |
|
|
129
|
+
| `structured` | strict JSON schema, model returns a probability per option | the model's own numbers, rescaled to sum 1 when off by more than `1e-6` | JSON-schema structured output |
|
|
130
|
+
| `discrete` | strict JSON schema, model returns one option | one-hot distribution | JSON-schema structured output |
|
|
131
|
+
|
|
132
|
+
`logprobs` is the default because it needs no provider-specific field beyond `logprobs`, and it reads the
|
|
133
|
+
model's real distribution rather than a sampled answer. See [docs/methods.md](docs/methods.md) for the exact
|
|
134
|
+
request bodies, readout rules and failure modes.
|
|
135
|
+
|
|
136
|
+
## Reasoning
|
|
137
|
+
|
|
138
|
+
Pass `reasoning=ReasoningConfig(...)` to make the model think before it classifies:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from jevper import ReasoningConfig, reasoning_text
|
|
142
|
+
|
|
143
|
+
client = SystemOneClient(OpenAI(), model="gpt-5.6-terra", reasoning=ReasoningConfig(effort="medium"))
|
|
144
|
+
|
|
145
|
+
response = client.system_one(state=..., questions=...)
|
|
146
|
+
reasoning_text(response.reasoning) # the trace, as text
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`mode="auto"` (the default) uses native provider reasoning on the Responses surface and a two-step
|
|
150
|
+
think-then-classify path on Chat Completions, where the analysis text is replayed as an assistant turn before
|
|
151
|
+
the answer. The trace always lands on `response.reasoning`, and the two-step analysis call's usage is counted
|
|
152
|
+
in `response.usage`. See [docs/reasoning.md](docs/reasoning.md).
|
|
153
|
+
|
|
154
|
+
## Few-shot examples
|
|
155
|
+
|
|
156
|
+
Examples are chat turns (example state + question block, then the expected answer), so the demonstration is
|
|
157
|
+
always in the format the active method expects. They can be attached at three levels:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from jevper import Choice, Example, SystemOneClient
|
|
161
|
+
|
|
162
|
+
question = Choice(
|
|
163
|
+
criteria={"billing": "...", "technical": "..."},
|
|
164
|
+
examples=[Example(state="Charged twice for one order", answer="billing")],
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
client = SystemOneClient(OpenAI(), model="gpt-5.6-terra",
|
|
168
|
+
examples=[Example(state="Login fails", answer="technical")]) # fallback for every question
|
|
169
|
+
|
|
170
|
+
client.system_one(state=..., questions={"intent": question},
|
|
171
|
+
examples={"intent": [...]}) # or a bare sequence for all questions
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Precedence is question → per call → constructor, and the first non-empty level wins. `examples` is excluded
|
|
175
|
+
from `model_dump()`, so question dumps keep exactly the Jev wire keys. See
|
|
176
|
+
[docs/few-shot.md](docs/few-shot.md).
|
|
177
|
+
|
|
178
|
+
## Response
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
response.model # the model actually used
|
|
182
|
+
response.answers # {"intent": ChoiceAnswer(...)}
|
|
183
|
+
response.nouls / .choices / .scores # filtered views
|
|
184
|
+
response.usage # input_tokens, output_tokens, reasoning_tokens, n_calls, n_retries, latency
|
|
185
|
+
response.reasoning # tuple[ReasoningContentPart, ...]
|
|
186
|
+
response.debug # per-attempt requests/responses, retry reasons, normalization notes
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`response.model_dump_json()` serializes to the Jev answer shape — the answer field names and JSON keys match
|
|
190
|
+
`POST /v1/systemone`. Token counts are `None` when any constituent call omitted them; `n_calls` counts every
|
|
191
|
+
provider call including analysis passes and corrective retries, while `n_retries` counts transient-failure
|
|
192
|
+
retries only. See [docs/api.md](docs/api.md) for the full reference.
|
|
193
|
+
|
|
194
|
+
## Failures
|
|
195
|
+
|
|
196
|
+
Local problems fail before any request is sent: an invalid question, an empty `questions` mapping, an
|
|
197
|
+
unusable `state`, or `grammar` on a surface that cannot carry a grammar.
|
|
198
|
+
|
|
199
|
+
| Error | Raised when |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `InvalidQuestionError` | question or few-shot example is locally invalid |
|
|
202
|
+
| `UnsupportedMethodError` | `method="grammar"` on the Responses surface |
|
|
203
|
+
| `ClientCapabilityError` | the client lacks the attribute the chosen surface needs, or returned no choices |
|
|
204
|
+
| `LabelReadoutError` | the first answer token is not a label, or no logprobs came back |
|
|
205
|
+
| `MalformedAnswerError` | the JSON answer had an unusable shape after corrective retries |
|
|
206
|
+
| `ProviderError` | a provider call failed; `.attempts` carries the attempt history |
|
|
207
|
+
|
|
208
|
+
Transient failures (HTTP 429/500/502/503/504/529, or an exception whose class name contains `Connection` or
|
|
209
|
+
`Timeout`) are retried per call with `RetryPolicy(n_retries=2, base_delay=0.5, max_delay=8.0)` and exponential
|
|
210
|
+
backoff `min(base_delay · 3ⁿ, max_delay)`. Unreadable answers get one corrective retry
|
|
211
|
+
(`n_retry_malformed`) with the failure appended to the conversation. `ProviderError` propagates after all
|
|
212
|
+
questions have settled, in question insertion order.
|
|
213
|
+
|
|
214
|
+
## Verification
|
|
215
|
+
|
|
216
|
+
```sh
|
|
217
|
+
pytest -q # the whole suite runs against a local stub HTTP server; no network, no API keys
|
|
218
|
+
ruff check src tests # clean except three PYI034 hints (see docs/internals.md)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The suite drives a real `openai` SDK client at a stdlib `ThreadingHTTPServer` stub, so the SDK's own
|
|
222
|
+
serialization path is exercised; see [docs/internals.md](docs/internals.md#testing).
|
|
223
|
+
|
|
224
|
+
Optional live check, skipped unless both variables are set:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
LLM_MODEL=gpt-5.6-terra OPENAI_API_KEY=... pytest -q tests/test_live.py
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Docs
|
|
231
|
+
|
|
232
|
+
- [docs/api.md](docs/api.md) — constructor and `system_one` parameters, answer/usage/debug shapes, errors
|
|
233
|
+
- [docs/methods.md](docs/methods.md) — the four methods, request bodies, readout rules, surface selection
|
|
234
|
+
- [docs/reasoning.md](docs/reasoning.md) — native vs two-step reasoning, traces, encrypted content
|
|
235
|
+
- [docs/few-shot.md](docs/few-shot.md) — example levels, precedence, rendering, structured examples
|
|
236
|
+
- [docs/internals.md](docs/internals.md) — module map, call flow, concurrency, retries, testing
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|