generic-ml-cache-core 0.2.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 (146) hide show
  1. generic_ml_cache_core-0.2.0/.gitignore +6 -0
  2. generic_ml_cache_core-0.2.0/LICENSE +201 -0
  3. generic_ml_cache_core-0.2.0/NOTICE +8 -0
  4. generic_ml_cache_core-0.2.0/PKG-INFO +104 -0
  5. generic_ml_cache_core-0.2.0/README.md +71 -0
  6. generic_ml_cache_core-0.2.0/pyproject.toml +48 -0
  7. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/__init__.py +64 -0
  8. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/__init__.py +1 -0
  9. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/inbound/__init__.py +1 -0
  10. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/inbound/composition.py +96 -0
  11. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/__init__.py +1 -0
  12. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/api/__init__.py +1 -0
  13. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/api/stub_api_client_adapter.py +30 -0
  14. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/__init__.py +28 -0
  15. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/claude.py +214 -0
  16. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/codex.py +171 -0
  17. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/cursor.py +208 -0
  18. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/discover.py +121 -0
  19. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/isolation.py +396 -0
  20. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/local_client_runner.py +54 -0
  21. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/passthrough_client_runner.py +47 -0
  22. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/prime_directive.py +53 -0
  23. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/client/registry.py +34 -0
  24. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/clock/__init__.py +1 -0
  25. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/clock/system_clock.py +16 -0
  26. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/fingerprint/__init__.py +1 -0
  27. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/fingerprint/filesystem_file_fingerprint.py +30 -0
  28. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/metrics/__init__.py +1 -0
  29. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/metrics/access_registry.py +147 -0
  30. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/metrics/journal_metrics.py +45 -0
  31. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/persistence/__init__.py +1 -0
  32. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/persistence/call_identity_serialization.py +100 -0
  33. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/persistence/in_memory_execution_repository.py +69 -0
  34. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/persistence/sqlite_execution_repository.py +398 -0
  35. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/storage/__init__.py +1 -0
  36. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/adapter/out/storage/filesystem_blob_store.py +47 -0
  37. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/__init__.py +1 -0
  38. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/__init__.py +1 -0
  39. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/__init__.py +1 -0
  40. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/client_status.py +17 -0
  41. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/__init__.py +1 -0
  42. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/artifact.py +78 -0
  43. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/execution_failure.py +32 -0
  44. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/execution_kind.py +26 -0
  45. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/execution_state.py +21 -0
  46. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/execution/ml_execution.py +41 -0
  47. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/identity/__init__.py +1 -0
  48. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/identity/api_call_identity.py +36 -0
  49. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/identity/call_identity.py +25 -0
  50. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/identity/managed_call_identity.py +54 -0
  51. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/identity/passthrough_call_identity.py +35 -0
  52. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/model_info.py +20 -0
  53. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/model_listing.py +29 -0
  54. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/parsed_output.py +23 -0
  55. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/probe/__init__.py +1 -0
  56. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/probe/probe_report.py +26 -0
  57. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/probe/probe_status.py +13 -0
  58. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/run/__init__.py +1 -0
  59. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/run/cache_mode.py +21 -0
  60. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/run/client_run_request.py +35 -0
  61. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/run/client_run_result.py +65 -0
  62. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/run/message.py +20 -0
  63. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/usage/__init__.py +1 -0
  64. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/usage/token_usage.py +53 -0
  65. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/model/usage/usage.py +108 -0
  66. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/service/__init__.py +1 -0
  67. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/service/cacheability.py +19 -0
  68. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/domain/service/message_fingerprinting.py +25 -0
  69. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/__init__.py +1 -0
  70. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/__init__.py +1 -0
  71. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/probe_command.py +35 -0
  72. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/probe_use_case.py +19 -0
  73. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_api_execution_command.py +40 -0
  74. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_api_execution_use_case.py +20 -0
  75. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_managed_local_execution_command.py +48 -0
  76. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_managed_local_execution_use_case.py +25 -0
  77. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_passthrough_execution_command.py +35 -0
  78. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/inbound/run_passthrough_execution_use_case.py +20 -0
  79. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/__init__.py +1 -0
  80. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/api_client_port.py +26 -0
  81. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/base.py +272 -0
  82. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/blob_store_port.py +37 -0
  83. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/client_runner_port.py +26 -0
  84. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/clock_port.py +22 -0
  85. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/execution_repository_port.py +40 -0
  86. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/file_fingerprint_port.py +25 -0
  87. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/metrics_port.py +54 -0
  88. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/port/out/passthrough_runner_port.py +25 -0
  89. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/__init__.py +1 -0
  90. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/cached_ml_execution_service.py +198 -0
  91. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/call_identity_building.py +60 -0
  92. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/journal_events.py +19 -0
  93. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/probe_service.py +44 -0
  94. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/run_api_execution_service.py +69 -0
  95. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/run_managed_local_execution_service.py +84 -0
  96. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/application/usecase/run_passthrough_execution_service.py +67 -0
  97. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/common/__init__.py +1 -0
  98. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/common/checksum.py +82 -0
  99. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/common/errors.py +76 -0
  100. generic_ml_cache_core-0.2.0/src/generic_ml_cache_core/stream.py +65 -0
  101. generic_ml_cache_core-0.2.0/tests/conftest.py +128 -0
  102. generic_ml_cache_core-0.2.0/tests/fake_client.py +111 -0
  103. generic_ml_cache_core-0.2.0/tests/test_adapters.py +249 -0
  104. generic_ml_cache_core-0.2.0/tests/test_api_call_identity.py +55 -0
  105. generic_ml_cache_core-0.2.0/tests/test_api_client_port.py +52 -0
  106. generic_ml_cache_core-0.2.0/tests/test_artifact.py +91 -0
  107. generic_ml_cache_core-0.2.0/tests/test_blob_store_port.py +114 -0
  108. generic_ml_cache_core-0.2.0/tests/test_cache_mode.py +28 -0
  109. generic_ml_cache_core-0.2.0/tests/test_cacheability.py +23 -0
  110. generic_ml_cache_core-0.2.0/tests/test_call_identity_building.py +70 -0
  111. generic_ml_cache_core-0.2.0/tests/test_call_identity_serialization.py +95 -0
  112. generic_ml_cache_core-0.2.0/tests/test_checksum.py +80 -0
  113. generic_ml_cache_core-0.2.0/tests/test_client_run_request.py +86 -0
  114. generic_ml_cache_core-0.2.0/tests/test_client_run_result.py +93 -0
  115. generic_ml_cache_core-0.2.0/tests/test_client_runner_port.py +60 -0
  116. generic_ml_cache_core-0.2.0/tests/test_clock_port.py +43 -0
  117. generic_ml_cache_core-0.2.0/tests/test_composition.py +88 -0
  118. generic_ml_cache_core-0.2.0/tests/test_execution_failure.py +43 -0
  119. generic_ml_cache_core-0.2.0/tests/test_execution_kind.py +37 -0
  120. generic_ml_cache_core-0.2.0/tests/test_execution_repository.py +224 -0
  121. generic_ml_cache_core-0.2.0/tests/test_execution_state.py +34 -0
  122. generic_ml_cache_core-0.2.0/tests/test_file_content_fingerprint.py +44 -0
  123. generic_ml_cache_core-0.2.0/tests/test_file_fingerprint_port.py +85 -0
  124. generic_ml_cache_core-0.2.0/tests/test_filesystem_blob_store.py +58 -0
  125. generic_ml_cache_core-0.2.0/tests/test_journal_metrics.py +48 -0
  126. generic_ml_cache_core-0.2.0/tests/test_local_client_runner.py +47 -0
  127. generic_ml_cache_core-0.2.0/tests/test_managed_call_identity.py +138 -0
  128. generic_ml_cache_core-0.2.0/tests/test_message.py +21 -0
  129. generic_ml_cache_core-0.2.0/tests/test_message_fingerprinting.py +40 -0
  130. generic_ml_cache_core-0.2.0/tests/test_metrics_port.py +100 -0
  131. generic_ml_cache_core-0.2.0/tests/test_ml_execution.py +154 -0
  132. generic_ml_cache_core-0.2.0/tests/test_passthrough_call_identity.py +56 -0
  133. generic_ml_cache_core-0.2.0/tests/test_passthrough_client_runner.py +45 -0
  134. generic_ml_cache_core-0.2.0/tests/test_passthrough_runner_port.py +29 -0
  135. generic_ml_cache_core-0.2.0/tests/test_probe_command.py +48 -0
  136. generic_ml_cache_core-0.2.0/tests/test_probe_report.py +30 -0
  137. generic_ml_cache_core-0.2.0/tests/test_probe_service.py +148 -0
  138. generic_ml_cache_core-0.2.0/tests/test_run_api_execution_command.py +53 -0
  139. generic_ml_cache_core-0.2.0/tests/test_run_api_execution_service.py +237 -0
  140. generic_ml_cache_core-0.2.0/tests/test_run_managed_local_execution_command.py +108 -0
  141. generic_ml_cache_core-0.2.0/tests/test_run_managed_local_execution_service.py +384 -0
  142. generic_ml_cache_core-0.2.0/tests/test_run_passthrough_execution_command.py +54 -0
  143. generic_ml_cache_core-0.2.0/tests/test_run_passthrough_execution_service.py +237 -0
  144. generic_ml_cache_core-0.2.0/tests/test_sqlite_execution_repository.py +236 -0
  145. generic_ml_cache_core-0.2.0/tests/test_token_usage.py +67 -0
  146. generic_ml_cache_core-0.2.0/tests/test_usage.py +200 -0
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ *.egg-info/
6
+ .coverage
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ generic-ml-cache
2
+ Copyright 2026 Daniel Slobozian
3
+
4
+ This product includes software developed by Daniel Slobozian.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7
+ this software except in compliance with the License. You may obtain a copy of
8
+ the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: generic-ml-cache-core
3
+ Version: 0.2.0
4
+ Summary: Hexagonal core library for generic-ml-cache: domain, use cases, ports, and the default outbound adapters (SQLite repo, blob store, local clients, API). Stateless; inject the data source. Zero runtime deps.
5
+ Project-URL: Homepage, https://github.com/danielslobozian/generic-ml-cache
6
+ Project-URL: Repository, https://github.com/danielslobozian/generic-ml-cache
7
+ Project-URL: Issues, https://github.com/danielslobozian/generic-ml-cache/issues
8
+ Project-URL: Changelog, https://github.com/danielslobozian/generic-ml-cache/blob/main/CHANGELOG.md
9
+ Author: Daniel Slobozian
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: ai,cache,hexagonal,library,llm,ports-and-adapters,replay
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Software Development :: Libraries
25
+ Requires-Python: >=3.9
26
+ Provides-Extra: dev
27
+ Requires-Dist: coverage>=7; extra == 'dev'
28
+ Requires-Dist: pytest-cov; extra == 'dev'
29
+ Requires-Dist: pytest>=7; extra == 'dev'
30
+ Requires-Dist: ruff>=0.15; extra == 'dev'
31
+ Requires-Dist: vulture>=2; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # generic-ml-cache-core
35
+
36
+ #### The hexagonal engine behind gmlcache — embeddable, stateless, dependency-free
37
+
38
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-2563eb?style=flat-square)](https://github.com/danielslobozian/generic-ml-cache/blob/main/LICENSE)
39
+ [![Status: Alpha](https://img.shields.io/badge/Status-Alpha-d97706?style=flat-square)](https://github.com/danielslobozian/generic-ml-cache/blob/main/docs/ROADMAP.md)
40
+
41
+ The reusable **engine** behind
42
+ [`gmlcache`](https://github.com/danielslobozian/generic-ml-cache/tree/main/packages/cli):
43
+ record a real ML client (or API) call once, replay it by its content key. It contains
44
+ the domain model, the use cases, the port contracts, **and the default outbound
45
+ adapters** (SQLite execution repository, filesystem blob store, the
46
+ claude/codex/cursor client runner, the API client, metrics, clock, fingerprinting) —
47
+ plus the `build_use_cases` composition factory.
48
+
49
+ Pure Python, **zero runtime dependencies**, and **stateless**: it bakes in *structure*
50
+ (table names, blob naming, schema) but no *location* — you inject the data source.
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pip install generic-ml-cache-core
56
+ ```
57
+
58
+ ## Embed it
59
+
60
+ Hand the library a data source and it wires the engine for you:
61
+
62
+ ```python
63
+ from generic_ml_cache_core import build_use_cases
64
+ from generic_ml_cache_core.application.port.inbound.run_managed_local_execution_command import (
65
+ RunManagedLocalExecutionCommand,
66
+ )
67
+
68
+ wired = build_use_cases(store_root="/path/you/choose") # you provide the data source
69
+ command = RunManagedLocalExecutionCommand(
70
+ client="claude", model="sonnet", effort="", context="", prompt="…",
71
+ )
72
+ execution = wired.run_managed.execute(command) # records on a miss, replays on a hit
73
+ ```
74
+
75
+ You reuse the shipped adapters by injecting a data source — you never reimplement them
76
+ (the **Spring Batch** model: the framework ships the writers, you provide the
77
+ connection). Need a different store? Construct the use cases yourself against the
78
+ ports and pass your own adapter.
79
+
80
+ ## What's inside
81
+
82
+ - **Domain model** — executions, polymorphic call identities, artifacts, usage.
83
+ - **Use cases** — managed-local / passthrough / API runs, and probe (check).
84
+ - **Ports** (`application/port/...`) — client runner, blob store, execution repository,
85
+ metrics, clock, fingerprint, API client.
86
+ - **Default adapters** (`adapter/out/...`) + the `build_use_cases` composition factory.
87
+ - **`generic_ml_cache_core.testing.InMemoryExecutionRepository`** — a dependency-free
88
+ reference adapter to test your code against the ports.
89
+
90
+ Inbound drivers —
91
+ [`gmlcache`](https://github.com/danielslobozian/generic-ml-cache/tree/main/packages/cli)
92
+ today, a daemon later — map their surface (a terminal, a REST API) onto these public
93
+ APIs; the core itself has no UI and reads no config file.
94
+
95
+ ## Links
96
+
97
+ - **Repository & docs:** <https://github.com/danielslobozian/generic-ml-cache>
98
+ - **Changelog** (both packages, versioned in lockstep): [`CHANGELOG.md`](https://github.com/danielslobozian/generic-ml-cache/blob/main/CHANGELOG.md)
99
+ - **Security policy:** [`SECURITY.md`](https://github.com/danielslobozian/generic-ml-cache/blob/main/SECURITY.md)
100
+
101
+ ## License
102
+
103
+ Apache-2.0 — see [`LICENSE`](https://github.com/danielslobozian/generic-ml-cache/blob/main/LICENSE)
104
+ and [`NOTICE`](https://github.com/danielslobozian/generic-ml-cache/blob/main/NOTICE).
@@ -0,0 +1,71 @@
1
+ # generic-ml-cache-core
2
+
3
+ #### The hexagonal engine behind gmlcache — embeddable, stateless, dependency-free
4
+
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-2563eb?style=flat-square)](https://github.com/danielslobozian/generic-ml-cache/blob/main/LICENSE)
6
+ [![Status: Alpha](https://img.shields.io/badge/Status-Alpha-d97706?style=flat-square)](https://github.com/danielslobozian/generic-ml-cache/blob/main/docs/ROADMAP.md)
7
+
8
+ The reusable **engine** behind
9
+ [`gmlcache`](https://github.com/danielslobozian/generic-ml-cache/tree/main/packages/cli):
10
+ record a real ML client (or API) call once, replay it by its content key. It contains
11
+ the domain model, the use cases, the port contracts, **and the default outbound
12
+ adapters** (SQLite execution repository, filesystem blob store, the
13
+ claude/codex/cursor client runner, the API client, metrics, clock, fingerprinting) —
14
+ plus the `build_use_cases` composition factory.
15
+
16
+ Pure Python, **zero runtime dependencies**, and **stateless**: it bakes in *structure*
17
+ (table names, blob naming, schema) but no *location* — you inject the data source.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install generic-ml-cache-core
23
+ ```
24
+
25
+ ## Embed it
26
+
27
+ Hand the library a data source and it wires the engine for you:
28
+
29
+ ```python
30
+ from generic_ml_cache_core import build_use_cases
31
+ from generic_ml_cache_core.application.port.inbound.run_managed_local_execution_command import (
32
+ RunManagedLocalExecutionCommand,
33
+ )
34
+
35
+ wired = build_use_cases(store_root="/path/you/choose") # you provide the data source
36
+ command = RunManagedLocalExecutionCommand(
37
+ client="claude", model="sonnet", effort="", context="", prompt="…",
38
+ )
39
+ execution = wired.run_managed.execute(command) # records on a miss, replays on a hit
40
+ ```
41
+
42
+ You reuse the shipped adapters by injecting a data source — you never reimplement them
43
+ (the **Spring Batch** model: the framework ships the writers, you provide the
44
+ connection). Need a different store? Construct the use cases yourself against the
45
+ ports and pass your own adapter.
46
+
47
+ ## What's inside
48
+
49
+ - **Domain model** — executions, polymorphic call identities, artifacts, usage.
50
+ - **Use cases** — managed-local / passthrough / API runs, and probe (check).
51
+ - **Ports** (`application/port/...`) — client runner, blob store, execution repository,
52
+ metrics, clock, fingerprint, API client.
53
+ - **Default adapters** (`adapter/out/...`) + the `build_use_cases` composition factory.
54
+ - **`generic_ml_cache_core.testing.InMemoryExecutionRepository`** — a dependency-free
55
+ reference adapter to test your code against the ports.
56
+
57
+ Inbound drivers —
58
+ [`gmlcache`](https://github.com/danielslobozian/generic-ml-cache/tree/main/packages/cli)
59
+ today, a daemon later — map their surface (a terminal, a REST API) onto these public
60
+ APIs; the core itself has no UI and reads no config file.
61
+
62
+ ## Links
63
+
64
+ - **Repository & docs:** <https://github.com/danielslobozian/generic-ml-cache>
65
+ - **Changelog** (both packages, versioned in lockstep): [`CHANGELOG.md`](https://github.com/danielslobozian/generic-ml-cache/blob/main/CHANGELOG.md)
66
+ - **Security policy:** [`SECURITY.md`](https://github.com/danielslobozian/generic-ml-cache/blob/main/SECURITY.md)
67
+
68
+ ## License
69
+
70
+ Apache-2.0 — see [`LICENSE`](https://github.com/danielslobozian/generic-ml-cache/blob/main/LICENSE)
71
+ and [`NOTICE`](https://github.com/danielslobozian/generic-ml-cache/blob/main/NOTICE).
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.18"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "generic-ml-cache-core"
7
+ version = "0.2.0"
8
+ description = "Hexagonal core library for generic-ml-cache: domain, use cases, ports, and the default outbound adapters (SQLite repo, blob store, local clients, API). Stateless; inject the data source. Zero runtime deps."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ authors = [{ name = "Daniel Slobozian" }]
14
+ keywords = ["cache", "llm", "ai", "hexagonal", "ports-and-adapters", "library", "replay"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Software Development :: Libraries",
27
+ ]
28
+ dependencies = []
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/danielslobozian/generic-ml-cache"
32
+ Repository = "https://github.com/danielslobozian/generic-ml-cache"
33
+ Issues = "https://github.com/danielslobozian/generic-ml-cache/issues"
34
+ Changelog = "https://github.com/danielslobozian/generic-ml-cache/blob/main/CHANGELOG.md"
35
+
36
+ [project.optional-dependencies]
37
+ dev = ["pytest>=7", "pytest-cov", "coverage>=7", "vulture>=2", "ruff>=0.15"]
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/generic_ml_cache_core"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ addopts = "-ra"
45
+
46
+ [tool.ruff]
47
+ line-length = 100
48
+ target-version = "py39"
@@ -0,0 +1,64 @@
1
+ # SPDX-FileCopyrightText: 2026 Daniel Slobozian
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """generic-ml-cache-core: the hexagonal core library.
4
+
5
+ Record a real ML client (or API) call once, replay it forever by its content key.
6
+
7
+ This is a stateless library: it holds the domain model, the use cases, the port
8
+ contracts, AND the default outbound adapters (SQLite execution repository,
9
+ filesystem blob store, local client runner, API client, metrics, clock,
10
+ fingerprint). It bakes in *structure* (table names, blob naming, schema) but no
11
+ *location* -- the data source (store path) and configuration are injected by the
12
+ caller. Wire it with :func:`build_use_cases`, or construct the adapters and use
13
+ cases directly. The CLI / a daemon / an embedding app are inbound drivers that
14
+ supply the data source and map their surface onto this library.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from importlib.metadata import PackageNotFoundError
20
+ from importlib.metadata import version as _pkg_version
21
+
22
+ try:
23
+ __version__ = _pkg_version("generic-ml-cache-core")
24
+ except PackageNotFoundError: # running from an uninstalled source tree
25
+ __version__ = "0+unknown"
26
+
27
+ from generic_ml_cache_core.adapter.inbound.composition import ( # noqa: E402 # fmt: skip
28
+ WiredUseCases,
29
+ build_use_cases,
30
+ )
31
+ from generic_ml_cache_core.adapter.out.client import ( # noqa: E402 # fmt: skip
32
+ ClientAdapter,
33
+ get_adapter,
34
+ register,
35
+ )
36
+ from generic_ml_cache_core.common.checksum import ( # noqa: E402 # fmt: skip
37
+ checksum_input_data,
38
+ file_content_fingerprint,
39
+ text_checksum,
40
+ )
41
+ from generic_ml_cache_core.common.errors import ( # noqa: E402 # fmt: skip
42
+ CacheError,
43
+ CacheMiss,
44
+ ClientNotFound,
45
+ RunInterrupted,
46
+ UnknownClient,
47
+ )
48
+
49
+ __all__ = [
50
+ "__version__",
51
+ "build_use_cases",
52
+ "WiredUseCases",
53
+ "register",
54
+ "get_adapter",
55
+ "ClientAdapter",
56
+ "checksum_input_data",
57
+ "text_checksum",
58
+ "file_content_fingerprint",
59
+ "CacheError",
60
+ "CacheMiss",
61
+ "ClientNotFound",
62
+ "RunInterrupted",
63
+ "UnknownClient",
64
+ ]
@@ -0,0 +1 @@
1
+ """Hexagonal layer package."""
@@ -0,0 +1 @@
1
+ """Hexagonal layer package."""
@@ -0,0 +1,96 @@
1
+ # SPDX-FileCopyrightText: 2026 Daniel Slobozian
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """The composition root: build the real adapters and wire the use cases.
4
+
5
+ This is the *only* place that names every concrete adapter. It reads where to
6
+ store things, constructs the outbound adapters, and hands them to the use-case
7
+ services through their constructors. A driving adapter (the CLI) asks for the
8
+ wired use cases and depends only on the inbound ports.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+ from typing import Callable, Optional
16
+
17
+ from generic_ml_cache_core.adapter.out.api.stub_api_client_adapter import StubApiClientAdapter
18
+ from generic_ml_cache_core.adapter.out.client.local_client_runner import LocalClientRunner
19
+ from generic_ml_cache_core.adapter.out.client.passthrough_client_runner import (
20
+ PassthroughClientRunner,
21
+ )
22
+ from generic_ml_cache_core.adapter.out.clock.system_clock import SystemClock
23
+ from generic_ml_cache_core.adapter.out.fingerprint.filesystem_file_fingerprint import (
24
+ FilesystemFileFingerprint,
25
+ )
26
+ from generic_ml_cache_core.adapter.out.metrics.access_registry import AccessRegistry
27
+ from generic_ml_cache_core.adapter.out.metrics.journal_metrics import JournalMetrics
28
+ from generic_ml_cache_core.adapter.out.persistence.sqlite_execution_repository import (
29
+ SqliteExecutionRepository,
30
+ )
31
+ from generic_ml_cache_core.adapter.out.storage.filesystem_blob_store import FilesystemBlobStore
32
+ from generic_ml_cache_core.application.usecase.probe_service import ProbeService
33
+ from generic_ml_cache_core.application.usecase.run_api_execution_service import (
34
+ RunApiExecutionService,
35
+ )
36
+ from generic_ml_cache_core.application.usecase.run_managed_local_execution_service import (
37
+ RunManagedLocalExecutionService,
38
+ )
39
+ from generic_ml_cache_core.application.usecase.run_passthrough_execution_service import (
40
+ RunPassthroughExecutionService,
41
+ )
42
+
43
+ _BLOBS_DIRNAME = "blobs"
44
+ _EXECUTIONS_DB = "executions.sqlite3"
45
+
46
+ #: given a client name, the executable override to use, or None for the default.
47
+ ExecutableOverride = Callable[[str], Optional[str]]
48
+
49
+
50
+ @dataclass(frozen=True)
51
+ class WiredUseCases:
52
+ """The use cases a driving adapter needs, plus the stores the read-only CLI
53
+ views (inspect/stats/list) query directly."""
54
+
55
+ run_managed: RunManagedLocalExecutionService
56
+ run_passthrough: RunPassthroughExecutionService
57
+ run_api: RunApiExecutionService
58
+ probe: ProbeService
59
+ blob_store: FilesystemBlobStore
60
+ repository: SqliteExecutionRepository
61
+ metrics: JournalMetrics
62
+
63
+
64
+ def build_use_cases(
65
+ store_root: Path,
66
+ executable_override: Optional[ExecutableOverride] = None,
67
+ timeout: Optional[float] = None,
68
+ ) -> WiredUseCases:
69
+ """Construct the outbound adapters under ``store_root`` and wire the services.
70
+
71
+ Layout: ``store_root/blobs/`` for output bytes, ``store_root/executions.sqlite3``
72
+ for the structured records, and the access-event registry beside them.
73
+ """
74
+ store_root = Path(store_root)
75
+ clock = SystemClock()
76
+ blob_store = FilesystemBlobStore(store_root / _BLOBS_DIRNAME)
77
+ repository = SqliteExecutionRepository(store_root / _EXECUTIONS_DB, clock)
78
+ metrics = JournalMetrics(AccessRegistry(store_root))
79
+ file_fingerprint = FilesystemFileFingerprint()
80
+ local_runner = LocalClientRunner(executable_override, timeout)
81
+ passthrough_runner = PassthroughClientRunner(executable_override, timeout)
82
+ api_client = StubApiClientAdapter()
83
+
84
+ return WiredUseCases(
85
+ run_managed=RunManagedLocalExecutionService(
86
+ file_fingerprint, local_runner, blob_store, repository, metrics
87
+ ),
88
+ run_passthrough=RunPassthroughExecutionService(
89
+ passthrough_runner, blob_store, repository, metrics
90
+ ),
91
+ run_api=RunApiExecutionService(api_client, blob_store, repository, metrics),
92
+ probe=ProbeService(file_fingerprint, repository),
93
+ blob_store=blob_store,
94
+ repository=repository,
95
+ metrics=metrics,
96
+ )
@@ -0,0 +1 @@
1
+ """Hexagonal layer package."""
@@ -0,0 +1 @@
1
+ """Hexagonal layer package."""
@@ -0,0 +1,30 @@
1
+ # SPDX-FileCopyrightText: 2026 Daniel Slobozian
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """StubApiClientAdapter: a deterministic, offline stand-in for a provider API."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import List
8
+
9
+ from generic_ml_cache_core.application.domain.model.run.client_run_result import ClientRunResult
10
+ from generic_ml_cache_core.application.domain.model.run.message import Message
11
+ from generic_ml_cache_core.application.domain.model.usage.token_usage import TokenUsage
12
+ from generic_ml_cache_core.application.port.out.api_client_port import ApiClientPort
13
+
14
+
15
+ class StubApiClientAdapter(ApiClientPort):
16
+ """A deterministic stand-in for a real provider API.
17
+
18
+ It runs everywhere — including CI, where no provider is reachable — by
19
+ synthesising a reply from the inputs: stdout echoes the last message, and the
20
+ token usage is a deterministic function of the message sizes. Same inputs ->
21
+ same result, so it behaves correctly under caching. Swap in a real adapter
22
+ when one exists; the port contract is identical.
23
+ """
24
+
25
+ def run(self, provider: str, model: str, messages: List[Message]) -> ClientRunResult:
26
+ last_content = messages[-1].content if messages else ""
27
+ reply = f"[stub:{provider}:{model}] {last_content}"
28
+ input_tokens = sum(len(message.content) for message in messages)
29
+ token_usage = TokenUsage(input_tokens=input_tokens, output_tokens=len(reply))
30
+ return ClientRunResult(exit_code=0, stdout=reply, token_usage=token_usage)