urim 0.0.1a1__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.
- urim-0.0.1a1/LICENSE +202 -0
- urim-0.0.1a1/MANIFEST.in +1 -0
- urim-0.0.1a1/NOTICE +4 -0
- urim-0.0.1a1/PKG-INFO +105 -0
- urim-0.0.1a1/README.md +77 -0
- urim-0.0.1a1/pyproject.toml +58 -0
- urim-0.0.1a1/setup.cfg +4 -0
- urim-0.0.1a1/src/urim/__init__.py +60 -0
- urim-0.0.1a1/src/urim/__main__.py +7 -0
- urim-0.0.1a1/src/urim/adapters.py +80 -0
- urim-0.0.1a1/src/urim/boundary.py +100 -0
- urim-0.0.1a1/src/urim/camps/__init__.py +81 -0
- urim-0.0.1a1/src/urim/camps/decisions.py +89 -0
- urim-0.0.1a1/src/urim/camps/shared.py +124 -0
- urim-0.0.1a1/src/urim/camps/systemone.py +71 -0
- urim-0.0.1a1/src/urim/canonical.py +18 -0
- urim-0.0.1a1/src/urim/classify.py +55 -0
- urim-0.0.1a1/src/urim/cli.py +283 -0
- urim-0.0.1a1/src/urim/client.py +430 -0
- urim-0.0.1a1/src/urim/cuts.py +45 -0
- urim-0.0.1a1/src/urim/define.py +96 -0
- urim-0.0.1a1/src/urim/descriptors.py +214 -0
- urim-0.0.1a1/src/urim/diff.py +28 -0
- urim-0.0.1a1/src/urim/emit.py +50 -0
- urim-0.0.1a1/src/urim/envelope.py +106 -0
- urim-0.0.1a1/src/urim/envelope_read.py +63 -0
- urim-0.0.1a1/src/urim/errors.py +91 -0
- urim-0.0.1a1/src/urim/fit.py +251 -0
- urim-0.0.1a1/src/urim/fit_math.py +119 -0
- urim-0.0.1a1/src/urim/freeze.py +24 -0
- urim-0.0.1a1/src/urim/jsonfmt.py +120 -0
- urim-0.0.1a1/src/urim/lock.py +89 -0
- urim-0.0.1a1/src/urim/plan.py +55 -0
- urim-0.0.1a1/src/urim/providers.py +95 -0
- urim-0.0.1a1/src/urim/py.typed +0 -0
- urim-0.0.1a1/src/urim/schema.py +47 -0
- urim-0.0.1a1/src/urim/testing.py +72 -0
- urim-0.0.1a1/src/urim/types.py +322 -0
- urim-0.0.1a1/src/urim.egg-info/PKG-INFO +105 -0
- urim-0.0.1a1/src/urim.egg-info/SOURCES.txt +42 -0
- urim-0.0.1a1/src/urim.egg-info/dependency_links.txt +1 -0
- urim-0.0.1a1/src/urim.egg-info/entry_points.txt +2 -0
- urim-0.0.1a1/src/urim.egg-info/requires.txt +9 -0
- urim-0.0.1a1/src/urim.egg-info/top_level.txt +1 -0
urim-0.0.1a1/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 David Thomason
|
|
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.
|
urim-0.0.1a1/MANIFEST.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prune tests
|
urim-0.0.1a1/NOTICE
ADDED
urim-0.0.1a1/PKG-INFO
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: urim
|
|
3
|
+
Version: 0.0.1a1
|
|
4
|
+
Summary: Client library for decision models: define a decision once in code, call it through provider tiers, get typed answers.
|
|
5
|
+
Author: David Thomason
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://urim.sh
|
|
8
|
+
Project-URL: Repository, https://github.com/voidal-ubiety/urim
|
|
9
|
+
Project-URL: Issues, https://github.com/voidal-ubiety/urim/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/voidal-ubiety/urim/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: llm,decisions,classification,confidence,ai
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Provides-Extra: pydantic
|
|
22
|
+
Requires-Dist: pydantic<3,>=2; extra == "pydantic"
|
|
23
|
+
Provides-Extra: httpx
|
|
24
|
+
Requires-Dist: httpx>=0.27; extra == "httpx"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# urim
|
|
30
|
+
|
|
31
|
+
A typed client for system-1 decision APIs: define a decision once, call it across providers,
|
|
32
|
+
and get every answer back with its confidence, the tier that served it and a stable envelope.
|
|
33
|
+
The Python package matches the `urim` npm package byte for byte on canonical JSON, contract hashes and envelopes.
|
|
34
|
+
|
|
35
|
+
**Status:** alpha (0.0.1a1). The API may change, and it has not been tested against live providers yet. Python 3.11 or later, no runtime dependencies.
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pip install --pre urim # core (alpha: needs --pre)
|
|
39
|
+
pip install "urim[httpx]" # network adapters
|
|
40
|
+
pip install "urim[pydantic]" # Pydantic v2 input schemas
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quickstart (offline)
|
|
44
|
+
|
|
45
|
+
This runs without a network or API key: `fake_provider` from `urim.testing` scripts the provider's reply.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import asyncio
|
|
49
|
+
|
|
50
|
+
from urim import create_client, define_decision, json_schema_adapter, noul, tier
|
|
51
|
+
from urim.testing import fake_provider
|
|
52
|
+
|
|
53
|
+
# OpenAI publishes no model version, so "0.0.0" is a placeholder.
|
|
54
|
+
openai = tier(provider="openai", model="gpt-6-luna", version="0.0.0", camp="decisions", question_types=["noul"])
|
|
55
|
+
|
|
56
|
+
triage = define_decision(
|
|
57
|
+
contract="incident-triage@1.0.0",
|
|
58
|
+
tiers=[openai],
|
|
59
|
+
# json_schema_adapter(schema, validate); `pydantic_schema` adapts a Pydantic model (extra: urim[pydantic]).
|
|
60
|
+
input=json_schema_adapter({"type": "object"}, lambda value: []),
|
|
61
|
+
questions={"page": noul("Should someone be paged right now?", yes="Active customer impact", no="No impact")},
|
|
62
|
+
failover_on=["timeout", "provider_unavailable"],
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Offline: a scripted provider stands in for the network. For real calls use `openai_decisions()` from urim.adapters.
|
|
66
|
+
provider = fake_provider(
|
|
67
|
+
{
|
|
68
|
+
openai.id: [
|
|
69
|
+
{"body": {"model": "gpt-6-luna", "answers": [{"type": "predicate", "name": "page", "probability": 0.95}]}}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
async def main() -> None:
|
|
76
|
+
result = await create_client(adapters=[provider]).decide(triage, {"report": "checkout API returns 500s"})
|
|
77
|
+
print(result.value["page"] if result.ok else result.error.type)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
It prints the answer: `value='yes'`, `confidence=0.9` and where the confidence came from.
|
|
84
|
+
|
|
85
|
+
## What's included
|
|
86
|
+
- define, emit, canonical JSON and sha256 contract hashes
|
|
87
|
+
- the async client: `create_client(...)`, `await client.decide(...)`, `explain`, `flush`
|
|
88
|
+
- `urim.testing` (`fake_provider`)
|
|
89
|
+
- lock parse/serialize (`parse_lock`, `serialize_lock`), fit math and `run_fit`
|
|
90
|
+
- httpx adapters in `urim.adapters`, one per request format (`systemone` and `decisions`, e.g. `openai_decisions`)
|
|
91
|
+
- the `urim emit|fit|providers` CLI, also `python -m urim`, with the same exit codes and bytes as the npm package
|
|
92
|
+
|
|
93
|
+
Casing: the Python API is snake_case. All JSON is camelCase. The mapping lives only in `urim/boundary.py`.
|
|
94
|
+
Credentials are read from the `env` you pass (no default), at send time, and never logged.
|
|
95
|
+
|
|
96
|
+
Hooks: `on_settled` and `on_hook_error` run as asyncio tasks after `decide()` returns. `await client.flush()`
|
|
97
|
+
waits for them. Tasks still pending when the event loop ends are lost, so call `flush()` before shutdown.
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
Parity: `../shared-fixtures/*.vectors.json` are generated from the TypeScript package and both test suites
|
|
102
|
+
assert against them. `bash ../check.sh` runs pytest, `ruff check`, `ruff format --check` and `mypy --strict`,
|
|
103
|
+
plus the TypeScript tests and `tsc`.
|
|
104
|
+
|
|
105
|
+
python -m pytest # pydantic tests skip if it is not installed
|
urim-0.0.1a1/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# urim
|
|
2
|
+
|
|
3
|
+
A typed client for system-1 decision APIs: define a decision once, call it across providers,
|
|
4
|
+
and get every answer back with its confidence, the tier that served it and a stable envelope.
|
|
5
|
+
The Python package matches the `urim` npm package byte for byte on canonical JSON, contract hashes and envelopes.
|
|
6
|
+
|
|
7
|
+
**Status:** alpha (0.0.1a1). The API may change, and it has not been tested against live providers yet. Python 3.11 or later, no runtime dependencies.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pip install --pre urim # core (alpha: needs --pre)
|
|
11
|
+
pip install "urim[httpx]" # network adapters
|
|
12
|
+
pip install "urim[pydantic]" # Pydantic v2 input schemas
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quickstart (offline)
|
|
16
|
+
|
|
17
|
+
This runs without a network or API key: `fake_provider` from `urim.testing` scripts the provider's reply.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import asyncio
|
|
21
|
+
|
|
22
|
+
from urim import create_client, define_decision, json_schema_adapter, noul, tier
|
|
23
|
+
from urim.testing import fake_provider
|
|
24
|
+
|
|
25
|
+
# OpenAI publishes no model version, so "0.0.0" is a placeholder.
|
|
26
|
+
openai = tier(provider="openai", model="gpt-6-luna", version="0.0.0", camp="decisions", question_types=["noul"])
|
|
27
|
+
|
|
28
|
+
triage = define_decision(
|
|
29
|
+
contract="incident-triage@1.0.0",
|
|
30
|
+
tiers=[openai],
|
|
31
|
+
# json_schema_adapter(schema, validate); `pydantic_schema` adapts a Pydantic model (extra: urim[pydantic]).
|
|
32
|
+
input=json_schema_adapter({"type": "object"}, lambda value: []),
|
|
33
|
+
questions={"page": noul("Should someone be paged right now?", yes="Active customer impact", no="No impact")},
|
|
34
|
+
failover_on=["timeout", "provider_unavailable"],
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Offline: a scripted provider stands in for the network. For real calls use `openai_decisions()` from urim.adapters.
|
|
38
|
+
provider = fake_provider(
|
|
39
|
+
{
|
|
40
|
+
openai.id: [
|
|
41
|
+
{"body": {"model": "gpt-6-luna", "answers": [{"type": "predicate", "name": "page", "probability": 0.95}]}}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async def main() -> None:
|
|
48
|
+
result = await create_client(adapters=[provider]).decide(triage, {"report": "checkout API returns 500s"})
|
|
49
|
+
print(result.value["page"] if result.ok else result.error.type)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
asyncio.run(main())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
It prints the answer: `value='yes'`, `confidence=0.9` and where the confidence came from.
|
|
56
|
+
|
|
57
|
+
## What's included
|
|
58
|
+
- define, emit, canonical JSON and sha256 contract hashes
|
|
59
|
+
- the async client: `create_client(...)`, `await client.decide(...)`, `explain`, `flush`
|
|
60
|
+
- `urim.testing` (`fake_provider`)
|
|
61
|
+
- lock parse/serialize (`parse_lock`, `serialize_lock`), fit math and `run_fit`
|
|
62
|
+
- httpx adapters in `urim.adapters`, one per request format (`systemone` and `decisions`, e.g. `openai_decisions`)
|
|
63
|
+
- the `urim emit|fit|providers` CLI, also `python -m urim`, with the same exit codes and bytes as the npm package
|
|
64
|
+
|
|
65
|
+
Casing: the Python API is snake_case. All JSON is camelCase. The mapping lives only in `urim/boundary.py`.
|
|
66
|
+
Credentials are read from the `env` you pass (no default), at send time, and never logged.
|
|
67
|
+
|
|
68
|
+
Hooks: `on_settled` and `on_hook_error` run as asyncio tasks after `decide()` returns. `await client.flush()`
|
|
69
|
+
waits for them. Tasks still pending when the event loop ends are lost, so call `flush()` before shutdown.
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
Parity: `../shared-fixtures/*.vectors.json` are generated from the TypeScript package and both test suites
|
|
74
|
+
assert against them. `bash ../check.sh` runs pytest, `ruff check`, `ruff format --check` and `mypy --strict`,
|
|
75
|
+
plus the TypeScript tests and `tsc`.
|
|
76
|
+
|
|
77
|
+
python -m pytest # pydantic tests skip if it is not installed
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "urim"
|
|
7
|
+
version = "0.0.1a1"
|
|
8
|
+
description = "Client library for decision models: define a decision once in code, call it through provider tiers, get typed answers."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
keywords = ["llm", "decisions", "classification", "confidence", "ai"]
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "David Thomason" }]
|
|
14
|
+
requires-python = ">=3.11"
|
|
15
|
+
dependencies = []
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://urim.sh"
|
|
26
|
+
Repository = "https://github.com/voidal-ubiety/urim"
|
|
27
|
+
Issues = "https://github.com/voidal-ubiety/urim/issues"
|
|
28
|
+
Changelog = "https://github.com/voidal-ubiety/urim/blob/main/CHANGELOG.md"
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
urim = "urim.cli:main"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
pydantic = ["pydantic>=2,<3"]
|
|
35
|
+
httpx = ["httpx>=0.27"]
|
|
36
|
+
dev = ["pytest>=8"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 120
|
|
43
|
+
target-version = "py311"
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF"]
|
|
47
|
+
|
|
48
|
+
[tool.mypy]
|
|
49
|
+
# mypy --strict over the library. Chosen over pyright strict: both are "strict", but pyright's
|
|
50
|
+
# reportUnknown* rules flag every isinstance(x, dict) narrowing of untyped JSON (190 findings, almost all
|
|
51
|
+
# that), while mypy --strict surfaced the real defects (ABSENT not narrowing, ErrorType as str, codec Any).
|
|
52
|
+
strict = true
|
|
53
|
+
python_version = "3.11"
|
|
54
|
+
files = ["src"]
|
|
55
|
+
mypy_path = "src"
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.package-data]
|
|
58
|
+
urim = ["py.typed"]
|
urim-0.0.1a1/setup.cfg
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""urim (Python port). Same canonical JSON, hashes and envelope as the TypeScript port."""
|
|
2
|
+
|
|
3
|
+
from .camps import decode_reply, encode_request, request_id_of
|
|
4
|
+
from .canonical import canonicalize, sha256
|
|
5
|
+
from .classify import classify_reply, classify_vendor_reply
|
|
6
|
+
from .client import Client, create_client
|
|
7
|
+
from .cuts import resolve_cuts
|
|
8
|
+
from .define import choice, define_decision, noul, score, threshold, tier
|
|
9
|
+
from .descriptors import DESCRIPTORS, GENERIC_ERRORS, descriptor_for, model_spec_for
|
|
10
|
+
from .emit import emit
|
|
11
|
+
from .envelope import build_envelope
|
|
12
|
+
from .envelope_read import read_envelope
|
|
13
|
+
from .errors import FAILOVER_TYPES, Issue, UrimError
|
|
14
|
+
from .fit import estimate_fit_cost, parse_cases, run_fit
|
|
15
|
+
from .lock import parse_lock, serialize_lock
|
|
16
|
+
from .plan import estimate_input_tokens, explain, next_step, plan_attempts
|
|
17
|
+
from .schema import json_schema_adapter, pydantic_schema
|
|
18
|
+
from .types import CONFIDENCE_RULE, Objective
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"CONFIDENCE_RULE",
|
|
22
|
+
"DESCRIPTORS",
|
|
23
|
+
"FAILOVER_TYPES",
|
|
24
|
+
"GENERIC_ERRORS",
|
|
25
|
+
"Client",
|
|
26
|
+
"Issue",
|
|
27
|
+
"Objective",
|
|
28
|
+
"UrimError",
|
|
29
|
+
"build_envelope",
|
|
30
|
+
"canonicalize",
|
|
31
|
+
"choice",
|
|
32
|
+
"classify_reply",
|
|
33
|
+
"classify_vendor_reply",
|
|
34
|
+
"create_client",
|
|
35
|
+
"decode_reply",
|
|
36
|
+
"define_decision",
|
|
37
|
+
"descriptor_for",
|
|
38
|
+
"emit",
|
|
39
|
+
"encode_request",
|
|
40
|
+
"estimate_fit_cost",
|
|
41
|
+
"estimate_input_tokens",
|
|
42
|
+
"explain",
|
|
43
|
+
"json_schema_adapter",
|
|
44
|
+
"model_spec_for",
|
|
45
|
+
"next_step",
|
|
46
|
+
"noul",
|
|
47
|
+
"parse_cases",
|
|
48
|
+
"parse_lock",
|
|
49
|
+
"plan_attempts",
|
|
50
|
+
"pydantic_schema",
|
|
51
|
+
"read_envelope",
|
|
52
|
+
"request_id_of",
|
|
53
|
+
"resolve_cuts",
|
|
54
|
+
"run_fit",
|
|
55
|
+
"score",
|
|
56
|
+
"serialize_lock",
|
|
57
|
+
"sha256",
|
|
58
|
+
"threshold",
|
|
59
|
+
"tier",
|
|
60
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""A: real HTTP adapters over httpx (opt-in: ``from urim.adapters import typesafe_jev, openai_decisions``).
|
|
2
|
+
|
|
3
|
+
Nothing here runs unless you import it AND pass it to ``create_client``. The credential arrives from the client,
|
|
4
|
+
which reads the env var named by ``credential_env`` at send time. It is put in one request header and never
|
|
5
|
+
logged, stored, or placed in any error message. Pass ``create_client(http=httpx.AsyncClient(...))`` to share a
|
|
6
|
+
connection pool (tests use ``httpx.MockTransport``); otherwise one client is opened per send.
|
|
7
|
+
Requires the optional extra: ``pip install urim[httpx]``. Mirrors urim-ts src/adapters/index.ts.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import time
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from .descriptors import DESCRIPTORS, AuthSpec, Descriptor
|
|
18
|
+
from .errors import UrimError
|
|
19
|
+
from .jsonfmt import stringify
|
|
20
|
+
from .testing import SendIO
|
|
21
|
+
from .types import WireReply, WireRequest
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _reject_constant(name: str) -> Any:
|
|
25
|
+
raise ValueError(name) # NaN/Infinity are not JSON (JSON.parse rejects them too)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _read_body(text: str) -> Any:
|
|
29
|
+
try:
|
|
30
|
+
return json.loads(text, parse_constant=_reject_constant)
|
|
31
|
+
except ValueError:
|
|
32
|
+
return text # non-JSON -> the decoder reports nonconformant_response
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class HttpAdapter:
|
|
37
|
+
provider: str
|
|
38
|
+
credential_env: str
|
|
39
|
+
_url: str
|
|
40
|
+
_auth: AuthSpec
|
|
41
|
+
|
|
42
|
+
async def send(self, req: WireRequest, io: SendIO) -> WireReply:
|
|
43
|
+
if io.credential == "":
|
|
44
|
+
raise UrimError("auth", f"missing credential: set {self.credential_env}", tier=req.tier_id)
|
|
45
|
+
value = io.credential if self._auth.scheme is None else f"{self._auth.scheme} {io.credential}"
|
|
46
|
+
headers = {"content-type": "application/json", self._auth.header: value}
|
|
47
|
+
content = stringify(req.body).encode("utf-8")
|
|
48
|
+
started = time.monotonic()
|
|
49
|
+
if io.http is not None:
|
|
50
|
+
res = await io.http.post(req.url, content=content, headers=headers)
|
|
51
|
+
else:
|
|
52
|
+
import httpx # optional extra, imported only when a real send happens
|
|
53
|
+
|
|
54
|
+
async with httpx.AsyncClient() as http:
|
|
55
|
+
res = await http.post(req.url, content=content, headers=headers)
|
|
56
|
+
return WireReply(
|
|
57
|
+
res.status_code,
|
|
58
|
+
{k.lower(): v for k, v in res.headers.items()},
|
|
59
|
+
_read_body(res.text),
|
|
60
|
+
(time.monotonic() - started) * 1000,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def http_adapter(d: Descriptor) -> HttpAdapter:
|
|
65
|
+
"""One adapter per descriptor whose URL needs no caller-supplied placeholders."""
|
|
66
|
+
if not d.auth or "{" in d.url:
|
|
67
|
+
raise UrimError(
|
|
68
|
+
"invalid_definition", f"{d.provider}: descriptor needs URL/auth options this slice does not support"
|
|
69
|
+
)
|
|
70
|
+
return HttpAdapter(d.provider, d.auth[0].env, d.url, d.auth[0])
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def typesafe_jev() -> HttpAdapter:
|
|
74
|
+
"""TypeSafe Jev, systemone camp. Bearer TYPESAFE_API_KEY -> the descriptor URL."""
|
|
75
|
+
return http_adapter(DESCRIPTORS["typesafe"])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def openai_decisions() -> HttpAdapter:
|
|
79
|
+
"""OpenAI, decisions camp. Bearer OPENAI_API_KEY -> the descriptor URL."""
|
|
80
|
+
return http_adapter(DESCRIPTORS["openai"])
|