inferenceledger 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.
Files changed (121) hide show
  1. inferenceledger-0.1.0/LICENSE +22 -0
  2. inferenceledger-0.1.0/PKG-INFO +181 -0
  3. inferenceledger-0.1.0/README.md +153 -0
  4. inferenceledger-0.1.0/pyproject.toml +72 -0
  5. inferenceledger-0.1.0/setup.cfg +4 -0
  6. inferenceledger-0.1.0/src/inference_engine/__init__.py +3 -0
  7. inferenceledger-0.1.0/src/inference_engine/adapters/api/__init__.py +2 -0
  8. inferenceledger-0.1.0/src/inference_engine/adapters/api/app.py +31 -0
  9. inferenceledger-0.1.0/src/inference_engine/adapters/api/routes/__init__.py +2 -0
  10. inferenceledger-0.1.0/src/inference_engine/adapters/api/routes/inference.py +106 -0
  11. inferenceledger-0.1.0/src/inference_engine/application/__init__.py +2 -0
  12. inferenceledger-0.1.0/src/inference_engine/application/dto/__init__.py +2 -0
  13. inferenceledger-0.1.0/src/inference_engine/application/dto/batch_dto.py +16 -0
  14. inferenceledger-0.1.0/src/inference_engine/application/dto/inference_dto.py +21 -0
  15. inferenceledger-0.1.0/src/inference_engine/application/dto/metrics_dto.py +12 -0
  16. inferenceledger-0.1.0/src/inference_engine/application/services/__init__.py +2 -0
  17. inferenceledger-0.1.0/src/inference_engine/application/services/benchmarking/__init__.py +24 -0
  18. inferenceledger-0.1.0/src/inference_engine/application/services/benchmarking/litellm_arm_service.py +406 -0
  19. inferenceledger-0.1.0/src/inference_engine/application/services/benchmarking/migration_decision_service.py +383 -0
  20. inferenceledger-0.1.0/src/inference_engine/application/services/benchmarking/run_evidence_service.py +169 -0
  21. inferenceledger-0.1.0/src/inference_engine/application/services/cache/__init__.py +2 -0
  22. inferenceledger-0.1.0/src/inference_engine/application/services/cache/cache_service.py +94 -0
  23. inferenceledger-0.1.0/src/inference_engine/application/services/cache/warmup_service.py +39 -0
  24. inferenceledger-0.1.0/src/inference_engine/application/services/inference/__init__.py +2 -0
  25. inferenceledger-0.1.0/src/inference_engine/application/services/inference/batch_service.py +36 -0
  26. inferenceledger-0.1.0/src/inference_engine/application/services/inference/inference_service.py +17 -0
  27. inferenceledger-0.1.0/src/inference_engine/application/services/inference/streaming_service.py +37 -0
  28. inferenceledger-0.1.0/src/inference_engine/application/services/optimization/__init__.py +2 -0
  29. inferenceledger-0.1.0/src/inference_engine/application/services/optimization/adaptive_tuner.py +26 -0
  30. inferenceledger-0.1.0/src/inference_engine/application/services/routing/__init__.py +2 -0
  31. inferenceledger-0.1.0/src/inference_engine/application/services/routing/routing_service.py +42 -0
  32. inferenceledger-0.1.0/src/inference_engine/benchmarking/__init__.py +1 -0
  33. inferenceledger-0.1.0/src/inference_engine/benchmarking/budget.py +42 -0
  34. inferenceledger-0.1.0/src/inference_engine/benchmarking/change_gate.py +1127 -0
  35. inferenceledger-0.1.0/src/inference_engine/benchmarking/context_store.py +164 -0
  36. inferenceledger-0.1.0/src/inference_engine/benchmarking/decision_report.py +405 -0
  37. inferenceledger-0.1.0/src/inference_engine/benchmarking/eval.py +343 -0
  38. inferenceledger-0.1.0/src/inference_engine/benchmarking/evidence_completeness.py +454 -0
  39. inferenceledger-0.1.0/src/inference_engine/benchmarking/evidence_manifest.py +255 -0
  40. inferenceledger-0.1.0/src/inference_engine/benchmarking/experiment_provenance.py +514 -0
  41. inferenceledger-0.1.0/src/inference_engine/benchmarking/export.py +321 -0
  42. inferenceledger-0.1.0/src/inference_engine/benchmarking/harness.py +368 -0
  43. inferenceledger-0.1.0/src/inference_engine/benchmarking/ifstruct_subset.py +60 -0
  44. inferenceledger-0.1.0/src/inference_engine/benchmarking/ifstruct_validator.py +458 -0
  45. inferenceledger-0.1.0/src/inference_engine/benchmarking/openrouter_billing.py +1112 -0
  46. inferenceledger-0.1.0/src/inference_engine/benchmarking/openrouter_billing_run.py +1436 -0
  47. inferenceledger-0.1.0/src/inference_engine/benchmarking/openrouter_evidence_semantics.py +330 -0
  48. inferenceledger-0.1.0/src/inference_engine/benchmarking/paired_comparison.py +607 -0
  49. inferenceledger-0.1.0/src/inference_engine/benchmarking/pilot_analysis.py +149 -0
  50. inferenceledger-0.1.0/src/inference_engine/benchmarking/pilot_contract.py +516 -0
  51. inferenceledger-0.1.0/src/inference_engine/benchmarking/pilot_decision.py +349 -0
  52. inferenceledger-0.1.0/src/inference_engine/benchmarking/pilot_evidence_store.py +239 -0
  53. inferenceledger-0.1.0/src/inference_engine/benchmarking/pilot_semantics.py +316 -0
  54. inferenceledger-0.1.0/src/inference_engine/benchmarking/reconciliation.py +467 -0
  55. inferenceledger-0.1.0/src/inference_engine/benchmarking/segmentation.py +332 -0
  56. inferenceledger-0.1.0/src/inference_engine/benchmarking/sqlite_ledger.py +1306 -0
  57. inferenceledger-0.1.0/src/inference_engine/benchmarking/statistics.py +394 -0
  58. inferenceledger-0.1.0/src/inference_engine/cli.py +142 -0
  59. inferenceledger-0.1.0/src/inference_engine/config.py +53 -0
  60. inferenceledger-0.1.0/src/inference_engine/domain/__init__.py +2 -0
  61. inferenceledger-0.1.0/src/inference_engine/domain/batching/__init__.py +2 -0
  62. inferenceledger-0.1.0/src/inference_engine/domain/batching/adaptive.py +123 -0
  63. inferenceledger-0.1.0/src/inference_engine/domain/batching/algorithms.py +108 -0
  64. inferenceledger-0.1.0/src/inference_engine/domain/batching/base.py +19 -0
  65. inferenceledger-0.1.0/src/inference_engine/domain/batching/priority.py +73 -0
  66. inferenceledger-0.1.0/src/inference_engine/domain/batching/semantic.py +31 -0
  67. inferenceledger-0.1.0/src/inference_engine/domain/caching/__init__.py +2 -0
  68. inferenceledger-0.1.0/src/inference_engine/domain/caching/base.py +49 -0
  69. inferenceledger-0.1.0/src/inference_engine/domain/caching/eviction.py +108 -0
  70. inferenceledger-0.1.0/src/inference_engine/domain/caching/exact.py +97 -0
  71. inferenceledger-0.1.0/src/inference_engine/domain/caching/prefix.py +73 -0
  72. inferenceledger-0.1.0/src/inference_engine/domain/caching/semantic.py +47 -0
  73. inferenceledger-0.1.0/src/inference_engine/domain/cost/__init__.py +2 -0
  74. inferenceledger-0.1.0/src/inference_engine/domain/cost/attribution.py +75 -0
  75. inferenceledger-0.1.0/src/inference_engine/domain/cost/calculator.py +43 -0
  76. inferenceledger-0.1.0/src/inference_engine/domain/cost/optimization.py +96 -0
  77. inferenceledger-0.1.0/src/inference_engine/domain/cost/pricing.py +240 -0
  78. inferenceledger-0.1.0/src/inference_engine/domain/cost/routing_estimator.py +51 -0
  79. inferenceledger-0.1.0/src/inference_engine/domain/models/__init__.py +42 -0
  80. inferenceledger-0.1.0/src/inference_engine/domain/models/batch.py +84 -0
  81. inferenceledger-0.1.0/src/inference_engine/domain/models/cache.py +138 -0
  82. inferenceledger-0.1.0/src/inference_engine/domain/models/cost.py +83 -0
  83. inferenceledger-0.1.0/src/inference_engine/domain/models/economics.py +222 -0
  84. inferenceledger-0.1.0/src/inference_engine/domain/models/execution.py +145 -0
  85. inferenceledger-0.1.0/src/inference_engine/domain/models/request.py +97 -0
  86. inferenceledger-0.1.0/src/inference_engine/domain/models/response.py +77 -0
  87. inferenceledger-0.1.0/src/inference_engine/domain/models/routing.py +123 -0
  88. inferenceledger-0.1.0/src/inference_engine/domain/routing/__init__.py +2 -0
  89. inferenceledger-0.1.0/src/inference_engine/domain/routing/base.py +15 -0
  90. inferenceledger-0.1.0/src/inference_engine/domain/routing/baseline.py +148 -0
  91. inferenceledger-0.1.0/src/inference_engine/domain/routing/capability.py +14 -0
  92. inferenceledger-0.1.0/src/inference_engine/domain/routing/complexity.py +64 -0
  93. inferenceledger-0.1.0/src/inference_engine/domain/routing/cost_aware.py +145 -0
  94. inferenceledger-0.1.0/src/inference_engine/domain/routing/cost_estimator.py +23 -0
  95. inferenceledger-0.1.0/src/inference_engine/domain/routing/load_balanced.py +56 -0
  96. inferenceledger-0.1.0/src/inference_engine/domain/routing/policy.py +271 -0
  97. inferenceledger-0.1.0/src/inference_engine/infrastructure/embeddings/embedding_cache.py +70 -0
  98. inferenceledger-0.1.0/src/inference_engine/infrastructure/importers/__init__.py +1 -0
  99. inferenceledger-0.1.0/src/inference_engine/infrastructure/importers/litellm.py +336 -0
  100. inferenceledger-0.1.0/src/inference_engine/infrastructure/importers/litellm_exact.py +101 -0
  101. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/__init__.py +2 -0
  102. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/base.py +68 -0
  103. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/errors.py +133 -0
  104. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/model_pool.py +62 -0
  105. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/openai_backend.py +370 -0
  106. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/tgi_backend.py +113 -0
  107. inferenceledger-0.1.0/src/inference_engine/infrastructure/models/vllm_backend.py +124 -0
  108. inferenceledger-0.1.0/src/inference_engine/infrastructure/telemetry/__init__.py +1 -0
  109. inferenceledger-0.1.0/src/inference_engine/infrastructure/telemetry/request_log.py +529 -0
  110. inferenceledger-0.1.0/src/inference_engine/utils/__init__.py +1 -0
  111. inferenceledger-0.1.0/src/inference_engine/utils/concurrency.py +18 -0
  112. inferenceledger-0.1.0/src/inference_engine/utils/result.py +57 -0
  113. inferenceledger-0.1.0/src/inference_engine/utils/similarity.py +13 -0
  114. inferenceledger-0.1.0/src/inference_engine/utils/text_utils.py +7 -0
  115. inferenceledger-0.1.0/src/inference_engine/utils/time.py +10 -0
  116. inferenceledger-0.1.0/src/inferenceledger.egg-info/PKG-INFO +181 -0
  117. inferenceledger-0.1.0/src/inferenceledger.egg-info/SOURCES.txt +119 -0
  118. inferenceledger-0.1.0/src/inferenceledger.egg-info/dependency_links.txt +1 -0
  119. inferenceledger-0.1.0/src/inferenceledger.egg-info/entry_points.txt +3 -0
  120. inferenceledger-0.1.0/src/inferenceledger.egg-info/requires.txt +20 -0
  121. inferenceledger-0.1.0/src/inferenceledger.egg-info/top_level.txt +1 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mohammad Atashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: inferenceledger
3
+ Version: 0.1.0
4
+ Summary: Bounded inference-change assurance with reconstructable quality, reliability, latency, and economic evidence
5
+ Author: Mohammad Atashi
6
+ Project-URL: Repository, https://github.com/TensorScholar/inferenceledger
7
+ Requires-Python: <3.13,>=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: fastapi<1,>=0.115
11
+ Requires-Dist: uvicorn[standard]<1,>=0.30
12
+ Requires-Dist: pydantic<3,>=2.4
13
+ Requires-Dist: pydantic-settings<3,>=2
14
+ Requires-Dist: structlog<25,>=23
15
+ Requires-Dist: numpy<2,>=1.26
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest<10,>=8; extra == "dev"
18
+ Requires-Dist: pytest-asyncio<1,>=0.23; extra == "dev"
19
+ Requires-Dist: pytest-cov<8,>=5; extra == "dev"
20
+ Requires-Dist: ruff<1,>=0.16.6; extra == "dev"
21
+ Requires-Dist: mypy<2,>=1.10; extra == "dev"
22
+ Provides-Extra: providers
23
+ Requires-Dist: openai<2,>=1.0; extra == "providers"
24
+ Requires-Dist: text-generation<1,>=0.7; extra == "providers"
25
+ Provides-Extra: local-serving
26
+ Requires-Dist: vllm>=0.6; extra == "local-serving"
27
+ Dynamic: license-file
28
+
29
+ # InferenceLedger
30
+
31
+ InferenceLedger is a research-oriented engineering project for **bounded inference-change assurance**.
32
+
33
+ Its primary question is not "which model is cheapest?" and it is not intended to become another generic inference gateway, router, evaluation platform, dashboard, provider leaderboard, or universal billing system.
34
+
35
+ Instead:
36
+
37
+ > Does a specific model, provider, or execution-policy change satisfy predeclared quality, reliability, latency, and economic requirements for a defined workload and accounting basis, and can the supporting evidence and remaining uncertainty be reconstructed?
38
+
39
+ ## Current strategic status
40
+
41
+ The strategic thesis is **NARROWED — bounded inference-change assurance**.
42
+
43
+ The current research question is:
44
+
45
+ > Does explicit inference-specific evidence semantics improve consequential migration decisions versus a strong conventional workflow at acceptable decision coverage, effort, abstention, and delay?
46
+
47
+ The comparator is intentionally allowed to be competent: evaluation + telemetry + accounting + manual review with materially equivalent evidence access.
48
+
49
+ This thesis is **not externally validated, customer validated, commercially validated, or production guaranteed**.
50
+
51
+ See:
52
+
53
+ - [Strategy Brief](./docs/00_STRATEGY_BRIEF.md)
54
+ - [Market and Product Decision](./docs/05_MARKET_AND_PRODUCT_DECISION_2026-09.md)
55
+ - [Canonical Project Map](./docs/06_CANONICAL_PROJECT_MAP.md)
56
+ - [Decision Evidence Completeness Contract](./docs/13_DECISION_EVIDENCE_COMPLETENESS.md)
57
+ - [Comparative External Pilot Protocol](./docs/14_COMPARATIVE_EXTERNAL_PILOT_PROTOCOL.md)
58
+ - [Authoritative Pilot Decision Path](./docs/16_AUTHORITATIVE_PILOT_DECISION_PATH.md)
59
+ - [Pilot Evidence Contract](./docs/17_PILOT_EVIDENCE_CONTRACT.md)
60
+ - [Task-5 External Pilot Acquisition and Qualification Package](./docs/18_TASK5_EXTERNAL_PILOT_ACQUISITION.md)
61
+ - [Task-5 Candidate Intake / Pre-Freeze Template](./docs/19_TASK5_CANDIDATE_INTAKE_TEMPLATE.md)
62
+ - [Progress Tracker](./docs/PROGRESS_TRACKER.md)
63
+
64
+ ## Current engineering status
65
+
66
+ **Pilot-critical engineering for the first comparative external pilot path is complete and ENGINEERING_VERIFIED.**
67
+
68
+ That statement is deliberately narrower than "engineering is complete."
69
+
70
+ | Task | PR | Current meaning |
71
+ | --- | --- | --- |
72
+ | Task 1 | #28 | fail-closed decision-evidence completeness contract |
73
+ | Task 2 | #41 | frozen comparative external pilot protocol v1 |
74
+ | Task 3 | #42 | one authoritative pilot execution/import → compare → report path |
75
+ | Task 4 | #43 | pilot-specific exact money, acquisition semantics, attempt visibility, evidence manifest, evaluator/comparator contracts, and non-inference health checks |
76
+
77
+ The latest code-bearing main anchor before this repository-truth synchronization PR is `3ca56334d5136c58853554e9cbcf078761ba7160` (PR #43 merge). Main CI #210 passed on that exact SHA.
78
+
79
+ The selected pilot path now has:
80
+
81
+ - durable provider-attempt evidence with explicit unknown-cost behavior;
82
+ - provider/pricing provenance needed by the selected evidence path;
83
+ - workload identity, pairing, segment evidence, and non-compensatory Change Gate semantics;
84
+ - a single pilot-authoritative run-persistence and migration-decision owner;
85
+ - prospective exact decimal-string monetary evidence for the pilot path;
86
+ - separate measurement / collection / assignment semantics for pilot evidence;
87
+ - deterministic `pilot-evidence-manifest-v1`;
88
+ - evaluator, pairing, comparator-parity, study-output, and semantics-ablation contracts;
89
+ - OpenAI-compatible health checks that use non-inference model metadata rather than Chat Completions.
90
+
91
+ These capabilities do **not** imply generic repository-wide completion. In particular, generic orchestration consolidation, branch governance, gateway-era ownership cleanup, post-change revalidation, a generic non-pilot manifest/evidence-mode contract, and a repository-wide migration away from legacy float/SQLite `REAL` monetary fields remain separate backlog items. Repository CI/dev dependency reproducibility is handled separately by the checked-in Python 3.12/macOS ARM64 constraint contract.
92
+
93
+ ## Current phase — Task 5
94
+
95
+ Current phase: **Task 5 — Comparative External Decision-Value Pilot**.
96
+
97
+ | Surface | Status |
98
+ | --- | --- |
99
+ | Task-5 preparation | STARTED |
100
+ | Concrete pilot instance | NOT FROZEN |
101
+ | Execution readiness | BLOCKED — EXTERNAL FACTS REQUIRED |
102
+ | Pilot execution | NOT STARTED |
103
+ | Provider/customer calls for Task 5 | 0 |
104
+ | Authorized Task-5 paid spend | $0 |
105
+ | External decision-value evidence | NOT_STARTED |
106
+ | Customer validation | NOT_STARTED |
107
+ | Commercial validation | NOT_STARTED |
108
+
109
+ PR #44, **Gate Task 5 concrete pilot instance freeze**, was a draft Task-5 preparation/freeze-gate artifact. Its useful preparation semantics are superseded by the canonical Task-5 preparation surfaces below, and the PR is **CLOSED / UNMERGED / SUPERSEDED**. Closing it did not freeze or execute a pilot, create customer evidence, or increase readiness.
110
+
111
+ A real pilot still requires independently supplied external facts: an accountable collaborator and decision owner, a genuine migration decision, approved workload and selection procedure, consent and retention rules, baseline/candidate definitions, predeclared requirements and critical segments, a calibrated evaluator with known-good/known-bad controls, a strong conventional comparator with materially equivalent evidence access, acquisition/assignment semantics, a retry/fallback evidence plan, and explicit paid-spend authorization if paid execution is required.
112
+
113
+ The canonical Task-5 preparation surfaces are the [External Pilot Acquisition and Qualification Package](./docs/18_TASK5_EXTERNAL_PILOT_ACQUISITION.md) and the [Candidate Intake / Pre-Freeze Template](./docs/19_TASK5_CANDIDATE_INTAKE_TEMPLATE.md). They are preparation artifacts only: they do not supply external facts, freeze a pilot instance, authorize spend, execute a pilot, or establish customer/commercial validation. PR #44 is retained only as historical preparation context and is **CLOSED / UNMERGED / SUPERSEDED**.
114
+
115
+ ## Evidence boundary
116
+
117
+ InferenceLedger uses explicit evidence levels. They must not be collapsed:
118
+
119
+ - **ENGINEERING_VERIFIED** — code/contracts/tests passed the stated engineering environment.
120
+ - **EXTERNALLY_EXECUTED** — a real external system/provider participated; the target claim may still be unsupported.
121
+ - **EXTERNALLY_VALIDATED** — a predeclared external claim was tested and supported within scope.
122
+ - **PILOT_VALIDATED** — a real external decision owner/workload plus preregistered comparative use produced decision/effort evidence.
123
+ - **COMMERCIALLY_VALIDATED** — genuine buyer/commercial evidence.
124
+ - **PRODUCTION_GUARANTEED** — not claimed by this repository.
125
+
126
+ Prototype capability ≠ validated behavior ≠ production guarantee.
127
+
128
+ ## Historical evidence
129
+
130
+ Historical experiment outcomes are immutable.
131
+
132
+ - Mission 4 remains `INCONCLUSIVE`.
133
+ - Mission 5 remains `INCONCLUSIVE`.
134
+ - Mission 6B-OR remains **EXTERNALLY_EXECUTED / VALIDATED_MISMATCH**.
135
+ - Mission 6C is a post-hoc engineering clarification and does not relabel Mission 6B-OR.
136
+
137
+ Mission 6B-OR's monetary R2–R5 surfaces matched exactly within its frozen experiment, while its historical R1 token-field comparison mismatched. That result is not direct OpenAI billing-ledger validation, final-invoice validation, customer validation, or a Change Gate approval.
138
+
139
+ Historical artifacts are not regenerated to fit newer semantics.
140
+
141
+ ## Distribution and CLI identity
142
+
143
+ The installable Python distribution is `inferenceledger`. The internal Python import package remains `inference_engine` by design; renaming imports would create migration cost without improving the distribution-facing product contract.
144
+
145
+ The canonical console surface is:
146
+
147
+ ```bash
148
+ inferenceledger smoke --prompt "hello"
149
+ ```
150
+
151
+ The historical flat command remains available as a compatibility alias:
152
+
153
+ ```bash
154
+ inference-smoke --prompt "hello"
155
+ ```
156
+
157
+ `inference-smoke` is retained for the `0.1.x` line. Its earliest removal is `0.2.0`, and only after repository/supported-workflow evidence shows that no maintained consumer still depends on it. Historical experiment commands and artifact paths are not renamed.
158
+
159
+ ## Development and CI
160
+
161
+ The repository CI workflow runs on the repository-scoped self-hosted runner using `[self-hosted, macOS, ARM64]`.
162
+
163
+ The CI job is `lint-type-test` and runs Ruff, mypy, and pytest.
164
+
165
+ The workflow retains `permissions: contents: read` and `actions/checkout` with `persist-credentials: false`.
166
+
167
+ For reproducible repository verification, CI pins the resolver and consumes `requirements/ci-py312-macos-arm64.txt`; see [CI Dependency Reproducibility](./docs/20_CI_DEPENDENCY_REPRODUCIBILITY.md). `pyproject.toml` remains the package compatibility/intention surface, and provider/local-serving extras remain outside ordinary CI.
168
+
169
+ Passing CI is engineering evidence only. It is not external/customer/commercial validation.
170
+
171
+ ## Current non-pilot repository debt
172
+
173
+ The first external pilot is blocked by external facts, not by a missing pilot-critical subsystem. Separate repository debt remains tracked in issues #29–#39. Issue #40 is closed/completed after an acceptance audit of the non-inference health-check implementation.
174
+
175
+ - generic orchestration consolidation beyond the selected pilot path (#31);
176
+ - main protection and self-hosted-runner governance (#33);
177
+ - gateway-era ownership cleanup (#35);
178
+ - post-change revalidation (#36);
179
+ - generic non-pilot manifest/evidence-mode/monetary migration scope (#37–#39).
180
+
181
+ Do not add infrastructure merely because it is technically interesting. The immediate strategic objective is to determine whether InferenceLedger creates measurable incremental decision value on a real external inference migration.
@@ -0,0 +1,153 @@
1
+ # InferenceLedger
2
+
3
+ InferenceLedger is a research-oriented engineering project for **bounded inference-change assurance**.
4
+
5
+ Its primary question is not "which model is cheapest?" and it is not intended to become another generic inference gateway, router, evaluation platform, dashboard, provider leaderboard, or universal billing system.
6
+
7
+ Instead:
8
+
9
+ > Does a specific model, provider, or execution-policy change satisfy predeclared quality, reliability, latency, and economic requirements for a defined workload and accounting basis, and can the supporting evidence and remaining uncertainty be reconstructed?
10
+
11
+ ## Current strategic status
12
+
13
+ The strategic thesis is **NARROWED — bounded inference-change assurance**.
14
+
15
+ The current research question is:
16
+
17
+ > Does explicit inference-specific evidence semantics improve consequential migration decisions versus a strong conventional workflow at acceptable decision coverage, effort, abstention, and delay?
18
+
19
+ The comparator is intentionally allowed to be competent: evaluation + telemetry + accounting + manual review with materially equivalent evidence access.
20
+
21
+ This thesis is **not externally validated, customer validated, commercially validated, or production guaranteed**.
22
+
23
+ See:
24
+
25
+ - [Strategy Brief](./docs/00_STRATEGY_BRIEF.md)
26
+ - [Market and Product Decision](./docs/05_MARKET_AND_PRODUCT_DECISION_2026-09.md)
27
+ - [Canonical Project Map](./docs/06_CANONICAL_PROJECT_MAP.md)
28
+ - [Decision Evidence Completeness Contract](./docs/13_DECISION_EVIDENCE_COMPLETENESS.md)
29
+ - [Comparative External Pilot Protocol](./docs/14_COMPARATIVE_EXTERNAL_PILOT_PROTOCOL.md)
30
+ - [Authoritative Pilot Decision Path](./docs/16_AUTHORITATIVE_PILOT_DECISION_PATH.md)
31
+ - [Pilot Evidence Contract](./docs/17_PILOT_EVIDENCE_CONTRACT.md)
32
+ - [Task-5 External Pilot Acquisition and Qualification Package](./docs/18_TASK5_EXTERNAL_PILOT_ACQUISITION.md)
33
+ - [Task-5 Candidate Intake / Pre-Freeze Template](./docs/19_TASK5_CANDIDATE_INTAKE_TEMPLATE.md)
34
+ - [Progress Tracker](./docs/PROGRESS_TRACKER.md)
35
+
36
+ ## Current engineering status
37
+
38
+ **Pilot-critical engineering for the first comparative external pilot path is complete and ENGINEERING_VERIFIED.**
39
+
40
+ That statement is deliberately narrower than "engineering is complete."
41
+
42
+ | Task | PR | Current meaning |
43
+ | --- | --- | --- |
44
+ | Task 1 | #28 | fail-closed decision-evidence completeness contract |
45
+ | Task 2 | #41 | frozen comparative external pilot protocol v1 |
46
+ | Task 3 | #42 | one authoritative pilot execution/import → compare → report path |
47
+ | Task 4 | #43 | pilot-specific exact money, acquisition semantics, attempt visibility, evidence manifest, evaluator/comparator contracts, and non-inference health checks |
48
+
49
+ The latest code-bearing main anchor before this repository-truth synchronization PR is `3ca56334d5136c58853554e9cbcf078761ba7160` (PR #43 merge). Main CI #210 passed on that exact SHA.
50
+
51
+ The selected pilot path now has:
52
+
53
+ - durable provider-attempt evidence with explicit unknown-cost behavior;
54
+ - provider/pricing provenance needed by the selected evidence path;
55
+ - workload identity, pairing, segment evidence, and non-compensatory Change Gate semantics;
56
+ - a single pilot-authoritative run-persistence and migration-decision owner;
57
+ - prospective exact decimal-string monetary evidence for the pilot path;
58
+ - separate measurement / collection / assignment semantics for pilot evidence;
59
+ - deterministic `pilot-evidence-manifest-v1`;
60
+ - evaluator, pairing, comparator-parity, study-output, and semantics-ablation contracts;
61
+ - OpenAI-compatible health checks that use non-inference model metadata rather than Chat Completions.
62
+
63
+ These capabilities do **not** imply generic repository-wide completion. In particular, generic orchestration consolidation, branch governance, gateway-era ownership cleanup, post-change revalidation, a generic non-pilot manifest/evidence-mode contract, and a repository-wide migration away from legacy float/SQLite `REAL` monetary fields remain separate backlog items. Repository CI/dev dependency reproducibility is handled separately by the checked-in Python 3.12/macOS ARM64 constraint contract.
64
+
65
+ ## Current phase — Task 5
66
+
67
+ Current phase: **Task 5 — Comparative External Decision-Value Pilot**.
68
+
69
+ | Surface | Status |
70
+ | --- | --- |
71
+ | Task-5 preparation | STARTED |
72
+ | Concrete pilot instance | NOT FROZEN |
73
+ | Execution readiness | BLOCKED — EXTERNAL FACTS REQUIRED |
74
+ | Pilot execution | NOT STARTED |
75
+ | Provider/customer calls for Task 5 | 0 |
76
+ | Authorized Task-5 paid spend | $0 |
77
+ | External decision-value evidence | NOT_STARTED |
78
+ | Customer validation | NOT_STARTED |
79
+ | Commercial validation | NOT_STARTED |
80
+
81
+ PR #44, **Gate Task 5 concrete pilot instance freeze**, was a draft Task-5 preparation/freeze-gate artifact. Its useful preparation semantics are superseded by the canonical Task-5 preparation surfaces below, and the PR is **CLOSED / UNMERGED / SUPERSEDED**. Closing it did not freeze or execute a pilot, create customer evidence, or increase readiness.
82
+
83
+ A real pilot still requires independently supplied external facts: an accountable collaborator and decision owner, a genuine migration decision, approved workload and selection procedure, consent and retention rules, baseline/candidate definitions, predeclared requirements and critical segments, a calibrated evaluator with known-good/known-bad controls, a strong conventional comparator with materially equivalent evidence access, acquisition/assignment semantics, a retry/fallback evidence plan, and explicit paid-spend authorization if paid execution is required.
84
+
85
+ The canonical Task-5 preparation surfaces are the [External Pilot Acquisition and Qualification Package](./docs/18_TASK5_EXTERNAL_PILOT_ACQUISITION.md) and the [Candidate Intake / Pre-Freeze Template](./docs/19_TASK5_CANDIDATE_INTAKE_TEMPLATE.md). They are preparation artifacts only: they do not supply external facts, freeze a pilot instance, authorize spend, execute a pilot, or establish customer/commercial validation. PR #44 is retained only as historical preparation context and is **CLOSED / UNMERGED / SUPERSEDED**.
86
+
87
+ ## Evidence boundary
88
+
89
+ InferenceLedger uses explicit evidence levels. They must not be collapsed:
90
+
91
+ - **ENGINEERING_VERIFIED** — code/contracts/tests passed the stated engineering environment.
92
+ - **EXTERNALLY_EXECUTED** — a real external system/provider participated; the target claim may still be unsupported.
93
+ - **EXTERNALLY_VALIDATED** — a predeclared external claim was tested and supported within scope.
94
+ - **PILOT_VALIDATED** — a real external decision owner/workload plus preregistered comparative use produced decision/effort evidence.
95
+ - **COMMERCIALLY_VALIDATED** — genuine buyer/commercial evidence.
96
+ - **PRODUCTION_GUARANTEED** — not claimed by this repository.
97
+
98
+ Prototype capability ≠ validated behavior ≠ production guarantee.
99
+
100
+ ## Historical evidence
101
+
102
+ Historical experiment outcomes are immutable.
103
+
104
+ - Mission 4 remains `INCONCLUSIVE`.
105
+ - Mission 5 remains `INCONCLUSIVE`.
106
+ - Mission 6B-OR remains **EXTERNALLY_EXECUTED / VALIDATED_MISMATCH**.
107
+ - Mission 6C is a post-hoc engineering clarification and does not relabel Mission 6B-OR.
108
+
109
+ Mission 6B-OR's monetary R2–R5 surfaces matched exactly within its frozen experiment, while its historical R1 token-field comparison mismatched. That result is not direct OpenAI billing-ledger validation, final-invoice validation, customer validation, or a Change Gate approval.
110
+
111
+ Historical artifacts are not regenerated to fit newer semantics.
112
+
113
+ ## Distribution and CLI identity
114
+
115
+ The installable Python distribution is `inferenceledger`. The internal Python import package remains `inference_engine` by design; renaming imports would create migration cost without improving the distribution-facing product contract.
116
+
117
+ The canonical console surface is:
118
+
119
+ ```bash
120
+ inferenceledger smoke --prompt "hello"
121
+ ```
122
+
123
+ The historical flat command remains available as a compatibility alias:
124
+
125
+ ```bash
126
+ inference-smoke --prompt "hello"
127
+ ```
128
+
129
+ `inference-smoke` is retained for the `0.1.x` line. Its earliest removal is `0.2.0`, and only after repository/supported-workflow evidence shows that no maintained consumer still depends on it. Historical experiment commands and artifact paths are not renamed.
130
+
131
+ ## Development and CI
132
+
133
+ The repository CI workflow runs on the repository-scoped self-hosted runner using `[self-hosted, macOS, ARM64]`.
134
+
135
+ The CI job is `lint-type-test` and runs Ruff, mypy, and pytest.
136
+
137
+ The workflow retains `permissions: contents: read` and `actions/checkout` with `persist-credentials: false`.
138
+
139
+ For reproducible repository verification, CI pins the resolver and consumes `requirements/ci-py312-macos-arm64.txt`; see [CI Dependency Reproducibility](./docs/20_CI_DEPENDENCY_REPRODUCIBILITY.md). `pyproject.toml` remains the package compatibility/intention surface, and provider/local-serving extras remain outside ordinary CI.
140
+
141
+ Passing CI is engineering evidence only. It is not external/customer/commercial validation.
142
+
143
+ ## Current non-pilot repository debt
144
+
145
+ The first external pilot is blocked by external facts, not by a missing pilot-critical subsystem. Separate repository debt remains tracked in issues #29–#39. Issue #40 is closed/completed after an acceptance audit of the non-inference health-check implementation.
146
+
147
+ - generic orchestration consolidation beyond the selected pilot path (#31);
148
+ - main protection and self-hosted-runner governance (#33);
149
+ - gateway-era ownership cleanup (#35);
150
+ - post-change revalidation (#36);
151
+ - generic non-pilot manifest/evidence-mode/monetary migration scope (#37–#39).
152
+
153
+ Do not add infrastructure merely because it is technically interesting. The immediate strategic objective is to determine whether InferenceLedger creates measurable incremental decision value on a real external inference migration.
@@ -0,0 +1,72 @@
1
+ [project]
2
+ name = "inferenceledger"
3
+ version = "0.1.0"
4
+ description = "Bounded inference-change assurance with reconstructable quality, reliability, latency, and economic evidence"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11,<3.13"
7
+ authors = [{ name = "Mohammad Atashi" }]
8
+ dependencies = [
9
+ "fastapi>=0.115,<1",
10
+ "uvicorn[standard]>=0.30,<1",
11
+ "pydantic>=2.4,<3",
12
+ "pydantic-settings>=2,<3",
13
+ "structlog>=23,<25",
14
+ "numpy>=1.26,<2",
15
+ ]
16
+
17
+ [project.urls]
18
+ Repository = "https://github.com/TensorScholar/inferenceledger"
19
+
20
+ [project.scripts]
21
+ inferenceledger = "inference_engine.cli:main"
22
+ inference-smoke = "inference_engine.cli:smoke_main"
23
+
24
+ [project.optional-dependencies]
25
+ dev = [
26
+ "pytest>=8,<10",
27
+ "pytest-asyncio>=0.23,<1",
28
+ "pytest-cov>=5,<8",
29
+ "ruff>=0.16.6,<1",
30
+ "mypy>=1.10,<2",
31
+ ]
32
+ providers = [
33
+ "openai>=1.0,<2",
34
+ "text-generation>=0.7,<1",
35
+ ]
36
+ local-serving = [
37
+ "vllm>=0.6",
38
+ ]
39
+
40
+ [build-system]
41
+ requires = ["setuptools>=68", "wheel"]
42
+ build-backend = "setuptools.build_meta"
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
47
+ [tool.ruff]
48
+ target-version = "py311"
49
+ line-length = 100
50
+ src = ["src", "tests"]
51
+
52
+ [tool.ruff.lint]
53
+ select = ["E", "F", "I", "B", "UP", "ANN"]
54
+ ignore = ["ANN101", "ANN102"]
55
+
56
+ [tool.mypy]
57
+ python_version = "3.11"
58
+ warn_return_any = true
59
+ warn_unused_configs = true
60
+ disallow_untyped_defs = true
61
+ disallow_incomplete_defs = true
62
+ check_untyped_defs = true
63
+ no_implicit_optional = true
64
+ warn_redundant_casts = true
65
+ warn_unused_ignores = true
66
+ warn_no_return = true
67
+ strict_equality = true
68
+ mypy_path = "src"
69
+
70
+ [[tool.mypy.overrides]]
71
+ module = ["structlog.*", "openai.*", "text_generation.*", "vllm.*"]
72
+ ignore_missing_imports = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ __all__ = []
2
+
3
+
@@ -0,0 +1,2 @@
1
+ """API adapter package."""
2
+
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ from fastapi import FastAPI
4
+
5
+ from .routes.inference import router as inference_router
6
+
7
+ app = FastAPI(
8
+ title="InferenceLedger Reference Executor",
9
+ version="0.1.0",
10
+ description=(
11
+ "Narrow OpenAI-compatible reference execution surface used for controlled "
12
+ "InferenceLedger experiments. It is not the product control plane."
13
+ ),
14
+ )
15
+
16
+ app.include_router(inference_router, prefix="/v1")
17
+
18
+
19
+ @app.get("/health")
20
+ async def health() -> dict[str, str]:
21
+ return {"status": "ok", "component": "reference-executor"}
22
+
23
+
24
+ @app.get("/health/ready")
25
+ async def ready() -> dict[str, bool]:
26
+ return {"ready": True}
27
+
28
+
29
+ @app.get("/health/live")
30
+ async def live() -> dict[str, bool]:
31
+ return {"alive": True}
@@ -0,0 +1,106 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from fastapi import APIRouter, HTTPException, status
6
+ from pydantic import BaseModel, Field
7
+
8
+ from ....domain.models.request import InferenceRequest, ModelParameters
9
+ from ....infrastructure.models.errors import ProviderError, ProviderErrorType
10
+ from ....infrastructure.models.openai_backend import OpenAIBackend, RetryPolicy
11
+
12
+ router = APIRouter()
13
+
14
+
15
+ class InferenceRequestBody(BaseModel):
16
+ prompt: str = Field(min_length=1)
17
+ model: str = "gpt-4o-mini"
18
+ max_tokens: int = Field(default=128, ge=1)
19
+ temperature: float = Field(default=0.0, ge=0.0, le=2.0)
20
+ top_p: float = Field(default=0.9, ge=0.0, le=1.0)
21
+ timeout_seconds: float = Field(default=30.0, gt=0.0)
22
+
23
+
24
+ class InferenceResponseBody(BaseModel):
25
+ text: str
26
+ model_used: str
27
+ finish_reason: str
28
+ latency_ms: int
29
+ prompt_tokens: int
30
+ completion_tokens: int
31
+ total_tokens: int
32
+ cached_tokens: int
33
+ final_attempt_cost_usd: float | None
34
+ provider_attempt_count: int
35
+ provider_retry_count: int
36
+
37
+
38
+ @router.post("/inference", response_model=InferenceResponseBody)
39
+ async def create_inference(payload: InferenceRequestBody) -> InferenceResponseBody:
40
+ api_key = os.getenv("OPENAI_API_KEY")
41
+ if not api_key:
42
+ raise HTTPException(
43
+ status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
44
+ detail="OPENAI_API_KEY is required for real provider inference.",
45
+ )
46
+
47
+ try:
48
+ backend = OpenAIBackend(
49
+ api_key=api_key,
50
+ model_name=payload.model,
51
+ base_url=os.getenv("OPENAI_BASE_URL"),
52
+ timeout_seconds=payload.timeout_seconds,
53
+ retry_policy=RetryPolicy(max_attempts=2),
54
+ )
55
+ response = await backend.infer(
56
+ InferenceRequest(
57
+ prompt=payload.prompt,
58
+ parameters=ModelParameters(
59
+ max_tokens=payload.max_tokens,
60
+ temperature=payload.temperature,
61
+ top_p=payload.top_p,
62
+ ),
63
+ )
64
+ )
65
+ except ImportError as exc:
66
+ raise HTTPException(
67
+ status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
68
+ detail="OpenAI provider dependency is not installed.",
69
+ ) from exc
70
+ except ProviderError as exc:
71
+ raise HTTPException(
72
+ status_code=_provider_error_status(exc),
73
+ detail={
74
+ "type": exc.error_type.value,
75
+ "message": exc.message,
76
+ "retryable": exc.retryable,
77
+ "provider_attempt_count": exc.provider_attempt_count,
78
+ "provider_retry_count": exc.provider_retry_count,
79
+ },
80
+ ) from exc
81
+
82
+ return InferenceResponseBody(
83
+ text=response.text,
84
+ model_used=response.model_used,
85
+ finish_reason=response.finish_reason,
86
+ latency_ms=response.latency_ms,
87
+ prompt_tokens=response.usage.prompt_tokens,
88
+ completion_tokens=response.usage.completion_tokens,
89
+ total_tokens=response.usage.total_tokens,
90
+ cached_tokens=response.usage.cached_tokens,
91
+ final_attempt_cost_usd=response.usage.cost_usd,
92
+ provider_attempt_count=response.provider_attempt_count,
93
+ provider_retry_count=response.provider_retry_count,
94
+ )
95
+
96
+
97
+ def _provider_error_status(error: ProviderError) -> int:
98
+ return {
99
+ ProviderErrorType.AUTHENTICATION: status.HTTP_502_BAD_GATEWAY,
100
+ ProviderErrorType.INVALID_REQUEST: status.HTTP_400_BAD_REQUEST,
101
+ ProviderErrorType.MISSING_USAGE: status.HTTP_502_BAD_GATEWAY,
102
+ ProviderErrorType.RATE_LIMIT: status.HTTP_429_TOO_MANY_REQUESTS,
103
+ ProviderErrorType.SERVER_ERROR: status.HTTP_502_BAD_GATEWAY,
104
+ ProviderErrorType.TIMEOUT: status.HTTP_504_GATEWAY_TIMEOUT,
105
+ ProviderErrorType.UNKNOWN: status.HTTP_502_BAD_GATEWAY,
106
+ }[error.error_type]
@@ -0,0 +1,2 @@
1
+ """Application services."""
2
+
@@ -0,0 +1,2 @@
1
+ """Application DTOs."""
2
+
@@ -0,0 +1,16 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from .inference_dto import InferenceInputDTO, InferenceOutputDTO
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class BatchInputDTO:
10
+ requests: list[InferenceInputDTO]
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class BatchOutputDTO:
15
+ responses: list[InferenceOutputDTO]
16
+
@@ -0,0 +1,21 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class InferenceInputDTO:
8
+ prompt: str
9
+ max_tokens: int = 1024
10
+ temperature: float = 0.7
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class InferenceOutputDTO:
15
+ text: str
16
+ model_used: str
17
+ tokens_used: int
18
+ cost_usd: float
19
+ latency_ms: int
20
+ cache_hit: bool
21
+
@@ -0,0 +1,12 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class MetricsSummaryDTO:
8
+ total_requests: int
9
+ total_cost_usd: float
10
+ avg_latency_ms: float
11
+ cache_hit_rate: float
12
+
@@ -0,0 +1,2 @@
1
+ """Application service exports."""
2
+