sriti-core 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 (51) hide show
  1. sriti_core-0.1.0/LICENSE +179 -0
  2. sriti_core-0.1.0/PKG-INFO +421 -0
  3. sriti_core-0.1.0/README.md +205 -0
  4. sriti_core-0.1.0/pyproject.toml +56 -0
  5. sriti_core-0.1.0/setup.cfg +4 -0
  6. sriti_core-0.1.0/sriti/__init__.py +0 -0
  7. sriti_core-0.1.0/sriti/app.py +93 -0
  8. sriti_core-0.1.0/sriti/client.py +60 -0
  9. sriti_core-0.1.0/sriti/core/__init__.py +0 -0
  10. sriti_core-0.1.0/sriti/core/cache/__init__.py +0 -0
  11. sriti_core-0.1.0/sriti/core/cache/embedding_cache.py +92 -0
  12. sriti_core-0.1.0/sriti/core/cache/encryption.py +50 -0
  13. sriti_core-0.1.0/sriti/core/cache/semantic_cache.py +392 -0
  14. sriti_core-0.1.0/sriti/core/cascade/__init__.py +0 -0
  15. sriti_core-0.1.0/sriti/core/cascade/aggregation.py +363 -0
  16. sriti_core-0.1.0/sriti/core/cascade/case_memory.py +265 -0
  17. sriti_core-0.1.0/sriti/core/cascade/classifier.py +290 -0
  18. sriti_core-0.1.0/sriti/core/cascade/complexity.py +156 -0
  19. sriti_core-0.1.0/sriti/core/cascade/constants.py +47 -0
  20. sriti_core-0.1.0/sriti/core/cascade/engine.py +1234 -0
  21. sriti_core-0.1.0/sriti/core/cascade/expert_bank.py +221 -0
  22. sriti_core-0.1.0/sriti/core/cascade/multimodal.py +188 -0
  23. sriti_core-0.1.0/sriti/core/cascade/policy.py +387 -0
  24. sriti_core-0.1.0/sriti/core/cascade/provider_health.py +244 -0
  25. sriti_core-0.1.0/sriti/core/cascade/reliability.py +499 -0
  26. sriti_core-0.1.0/sriti/core/cascade/reliability_store.py +93 -0
  27. sriti_core-0.1.0/sriti/core/catalog/__init__.py +0 -0
  28. sriti_core-0.1.0/sriti/core/catalog/registry.py +218 -0
  29. sriti_core-0.1.0/sriti/core/compression/__init__.py +0 -0
  30. sriti_core-0.1.0/sriti/core/compression/llmlingua.py +441 -0
  31. sriti_core-0.1.0/sriti/core/compression/quality_gate.py +47 -0
  32. sriti_core-0.1.0/sriti/core/execution/__init__.py +0 -0
  33. sriti_core-0.1.0/sriti/core/execution/litellm_client.py +345 -0
  34. sriti_core-0.1.0/sriti/core/execution/retry.py +71 -0
  35. sriti_core-0.1.0/sriti/core/execution/streaming.py +160 -0
  36. sriti_core-0.1.0/sriti/core/local_vector_store.py +132 -0
  37. sriti_core-0.1.0/sriti/core/schemas.py +149 -0
  38. sriti_core-0.1.0/sriti/core/service.py +211 -0
  39. sriti_core-0.1.0/sriti/core/settings.py +51 -0
  40. sriti_core-0.1.0/sriti/core/telemetry.py +53 -0
  41. sriti_core-0.1.0/sriti_core.egg-info/PKG-INFO +421 -0
  42. sriti_core-0.1.0/sriti_core.egg-info/SOURCES.txt +49 -0
  43. sriti_core-0.1.0/sriti_core.egg-info/dependency_links.txt +1 -0
  44. sriti_core-0.1.0/sriti_core.egg-info/requires.txt +19 -0
  45. sriti_core-0.1.0/sriti_core.egg-info/top_level.txt +1 -0
  46. sriti_core-0.1.0/tests/test_case_memory_pure_functions.py +40 -0
  47. sriti_core-0.1.0/tests/test_classifier.py +19 -0
  48. sriti_core-0.1.0/tests/test_client.py +22 -0
  49. sriti_core-0.1.0/tests/test_engine_cascade.py +506 -0
  50. sriti_core-0.1.0/tests/test_local_vector_store.py +70 -0
  51. sriti_core-0.1.0/tests/test_reliability_store.py +58 -0
@@ -0,0 +1,179 @@
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 made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combined work of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the
121
+ Contribution, either on its own or together with this Work.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions consistent with this License.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ Copyright 2024 Sudev Mukherjee, Purusoth Mahendran, Clint Solomon
168
+
169
+ Licensed under the Apache License, Version 2.0 (the "License");
170
+ you may not use this file except in compliance with the License.
171
+ You may obtain a copy of the License at
172
+
173
+ http://www.apache.org/licenses/LICENSE-2.0
174
+
175
+ Unless required by applicable law or agreed to in writing, software
176
+ distributed under the License is distributed on an "AS IS" BASIS,
177
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
178
+ implied. See the License for the specific language governing
179
+ permissions and limitations under the License.
@@ -0,0 +1,421 @@
1
+ Metadata-Version: 2.1
2
+ Name: sriti-core
3
+ Version: 0.1.0
4
+ Summary: Adaptive LLM cascade engine with semantic caching and reliability tracking
5
+ Author: Sudev Mukherjee, Purusoth Mahendran, Clint Solomon
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship made available under
41
+ the License, as indicated by a copyright notice that is included in
42
+ or attached to the work (an example is provided in the Appendix below).
43
+
44
+ "Derivative Works" shall mean any work, whether in Source or Object
45
+ form, that is based on (or derived from) the Work and for which the
46
+ editorial revisions, annotations, elaborations, or other modifications
47
+ represent, as a whole, an original work of authorship. For the purposes
48
+ of this License, Derivative Works shall not include works that remain
49
+ separable from, or merely link (or bind by name) to the interfaces of,
50
+ the Work and Derivative Works thereof.
51
+
52
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
53
+ in the Work by the copyright owner or by an individual or Legal Entity
54
+ authorized to submit on behalf of the copyright owner. For the purposes
55
+ of this definition, "submitted" means any form of electronic, verbal,
56
+ or written communication sent to the Licensor or its representatives,
57
+ including but not limited to communication on electronic mailing lists,
58
+ source code control systems, and issue tracking systems that are managed
59
+ by, or on behalf of, the Licensor for the purpose of discussing and
60
+ improving the Work, but excluding communication that is conspicuously
61
+ marked or designated in writing by the copyright owner as "Not a
62
+ Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
65
+ whom a Contribution has been received by the Licensor and included
66
+ within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by the combined work of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a cross-claim
85
+ or counterclaim in a lawsuit) alleging that the Work or any
86
+ Contribution embodied within the Work constitutes direct or contributory
87
+ patent infringement, then any patent licenses granted to You under
88
+ this License for that Work shall terminate as of the date such
89
+ litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or Derivative
97
+ Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, You must include a readable copy of the
110
+ attribution notices contained within such NOTICE file, in
111
+ at least one of the following places: within a NOTICE text
112
+ file distributed as part of the Derivative Works; within
113
+ the Source form or documentation, if provided along with the
114
+ Derivative Works; or, within a display generated by the
115
+ Derivative Works, if and wherever such third-party notices
116
+ normally appear. The contents of the NOTICE file are for
117
+ informational purposes only and do not modify the License.
118
+ You may add Your own attribution notices within Derivative
119
+ Works that You distribute, alongside or in addition to the
120
+ NOTICE text from the Work, provided that such additional
121
+ attribution notices cannot be construed as modifying the License.
122
+
123
+ You may add Your own license statement for Your modifications and
124
+ may provide additional grant of rights to use, copy, modify, merge,
125
+ publish, distribute, sublicense, and/or sell copies of the
126
+ Contribution, either on its own or together with this Work.
127
+
128
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
129
+ any Contribution intentionally submitted for inclusion in the Work
130
+ by You to the Licensor shall be under the terms and conditions of
131
+ this License, without any additional terms or conditions.
132
+ Notwithstanding the above, nothing herein shall supersede or modify
133
+ the terms of any separate license agreement you may have executed
134
+ with Licensor regarding such Contributions.
135
+
136
+ 6. Trademarks. This License does not grant permission to use the trade
137
+ names, trademarks, service marks, or product names of the Licensor,
138
+ except as required for reasonable and customary use in describing the
139
+ origin of the Work and reproducing the content of the NOTICE file.
140
+
141
+ 7. Disclaimer of Warranty. Unless required by applicable law or
142
+ agreed to in writing, Licensor provides the Work (and each
143
+ Contributor provides its Contributions) on an "AS IS" BASIS,
144
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
145
+ implied, including, without limitation, any warranties or conditions
146
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
147
+ PARTICULAR PURPOSE. You are solely responsible for determining the
148
+ appropriateness of using or reproducing the Work and assume any
149
+ risks associated with Your exercise of permissions under this License.
150
+
151
+ 8. Limitation of Liability. In no event and under no legal theory,
152
+ whether in tort (including negligence), contract, or otherwise,
153
+ unless required by applicable law (such as deliberate and grossly
154
+ negligent acts) or agreed to in writing, shall any Contributor be
155
+ liable to You for damages, including any direct, indirect, special,
156
+ incidental, or exemplary damages of any character arising as a
157
+ result of this License or out of the use or inability to use the
158
+ Work (including but not limited to damages for loss of goodwill,
159
+ work stoppage, computer failure or malfunction, or all other
160
+ commercial damages or losses), even if such Contributor has been
161
+ advised of the possibility of such damages.
162
+
163
+ 9. Accepting Warranty or Additional Liability. While redistributing
164
+ the Work or Derivative Works thereof, You may choose to offer,
165
+ and charge a fee for, acceptance of support, warranty, indemnity,
166
+ or other liability obligations and/or rights consistent with this
167
+ License. However, in accepting such obligations, You may offer only
168
+ conditions consistent with this License.
169
+
170
+ END OF TERMS AND CONDITIONS
171
+
172
+ Copyright 2024 Sudev Mukherjee, Purusoth Mahendran, Clint Solomon
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
183
+ implied. See the License for the specific language governing
184
+ permissions and limitations under the License.
185
+
186
+ Project-URL: Homepage, https://github.com/sriti-ai/sriti-core
187
+ Project-URL: Issues, https://github.com/sriti-ai/sriti-core/issues
188
+ Classifier: Development Status :: 4 - Beta
189
+ Classifier: Intended Audience :: Developers
190
+ Classifier: License :: OSI Approved :: Apache Software License
191
+ Classifier: Programming Language :: Python :: 3
192
+ Classifier: Programming Language :: Python :: 3.11
193
+ Classifier: Programming Language :: Python :: 3.12
194
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
195
+ Requires-Python: >=3.11
196
+ Description-Content-Type: text/markdown
197
+ License-File: LICENSE
198
+ Requires-Dist: fastapi>=0.115.0
199
+ Requires-Dist: uvicorn[standard]>=0.30.0
200
+ Requires-Dist: httpx>=0.27.2
201
+ Requires-Dist: pydantic<3.0,>=2.0
202
+ Requires-Dist: pydantic-settings>=2.5.2
203
+ Requires-Dist: python-dotenv>=1.0.1
204
+ Requires-Dist: litellm<1.88,>=1.83.7
205
+ Requires-Dist: redis<6,>=5.0.8
206
+ Requires-Dist: pyyaml>=6.0.2
207
+ Requires-Dist: numpy<2,>=1.26.0
208
+ Requires-Dist: fastembed>=0.3.0
209
+ Requires-Dist: llmlingua>=0.2.0
210
+ Requires-Dist: torch>=2.8.0
211
+ Requires-Dist: transformers>=4.53.0
212
+ Requires-Dist: cryptography>=42.0.0
213
+ Provides-Extra: dev
214
+ Requires-Dist: pytest>=8.0; extra == "dev"
215
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
216
+
217
+ <p align="center">
218
+ <img src="./assets/logo.png" alt="Sriti Core Logo" width="220" />
219
+ </p>
220
+
221
+ <h1 align="center">Sriti Core</h1>
222
+
223
+ <p align="center">
224
+ <strong>Intelligent, Reliability-Aware Model Routing & Cascade Engine for LLMs</strong>
225
+ </p>
226
+
227
+ <p align="center">
228
+ <a href="#key-features">Key Features</a> •
229
+ <a href="#architecture">Architecture</a> •
230
+ <a href="#quickstart">Quickstart</a> •
231
+ <a href="#how-it-works">How It Works</a> •
232
+ <a href="#configuration">Configuration</a> •
233
+ <a href="#api-reference">API Reference</a> •
234
+ <a href="#testing">Testing</a> •
235
+ <a href="#license">License</a>
236
+ </p>
237
+
238
+ ---
239
+
240
+ ## Overview
241
+
242
+ **Sriti Core** is an open-source, ultra-efficient intelligent routing proxy and cascading engine for Large Language Models.
243
+
244
+ Instead of routing every single request to expensive frontier models (like Claude 3.5 Sonnet or GPT-4o), Sriti dynamically categorizes the request, checks an encrypted semantic cache, and cascades through a hierarchy of models:
245
+ 1. **Tier 3 (Local / Fast):** Free, local models running on edge devices or on-prem hardware via Ollama (e.g., Qwen 2.5, Llama 3.2, MiniCPM).
246
+ 2. **Tier 2 (Balanced Cloud):** High-throughput, cost-effective inference providers (e.g., Groq, Fireworks, DeepInfra).
247
+ 3. **Tier 1 (Frontier):** Capable reasoning models invoked only when task complexity warrants it, or when lower tiers fail verification or latency SLOs.
248
+
249
+ Sriti continuously learns model reliability, evaluates output quality gates, and guarantees strict latency SLOs while dramatically slashing cloud API bills.
250
+
251
+ ---
252
+
253
+ ## Key Features
254
+
255
+ - 🎯 **In-Process Task Classifier:** Zero-shot task classification using fast ONNX runtime (`fastembed` BAAI/bge-small-en-v1.5) mapping prompts across categories (e.g., Code, Extraction, Summarization, QA, Math, Reasoning).
256
+ - ⚡ **Semantically Aware Caching:** Vector similarity caching backed by Redis/Valkey with task-dependent cosine thresholds. Uncacheable tasks (e.g., non-deterministic reasoning, math) bypass the cache automatically.
257
+ - 🔒 **Encrypted Cache at Rest:** Optional AES-GCM (256-bit) authenticated encryption for cached prompt and completion payloads.
258
+ - 🗜️ **In-Process Prompt Compression:** LLMLingua-2 integration to compress lengthy contexts before sending them over the wire, with an adaptive quality gate to ensure semantic integrity.
259
+ - 📊 **Dynamic Cascade with Quality Gates:** Evaluates lower-tier completions using structural validation (e.g. JSON validation) or semantic quality scoring. If a tier's response fails, it automatically escalates to the next tier.
260
+ - 📈 **Online Reliability Profile Learner:** Real-time Exponential Moving Average (EMA) tracking of per-model latency, success rate, and error states without needing external analytical databases.
261
+ - 🧠 **Case-Based Memory (KNN Routing):** Remembers past routing decisions and dynamically adjusts candidate selection bias based on historical outcome rewards.
262
+ - 🛡️ **Lightweight & Self-Contained:** Uses a native NumPy cosine similarity vector store requiring no proprietary Redis modules (no RediSearch or RedisJSON needed). Works seamlessly on vanilla Redis or Valkey.
263
+ - 🔌 **Unified LLM Execution:** Powered by LiteLLM to seamlessly talk to 100+ LLM providers and local inference runtimes.
264
+
265
+ ---
266
+
267
+ ## Architecture
268
+
269
+ ```text
270
+ User / Application Request
271
+
272
+
273
+ ┌──────────────────────────────────┐
274
+ │ 1. Fast ONNX Classifier │ ──> Task Category & Embeddings
275
+ └──────────────────────────────────┘
276
+
277
+
278
+ ┌──────────────────────────────────┐
279
+ │ 2. Semantic Cache (Valkey) │ ──[Hit]──> Return Cached Response
280
+ └──────────────────────────────────┘
281
+ │ [Miss]
282
+
283
+ ┌──────────────────────────────────┐
284
+ │ 3. Model Cascading Engine │
285
+ │ │
286
+ │ ┌────────────────────────────┐ │
287
+ │ │ Tier 3: Local Edge Models │ │ ──[Success]──> Accept & Learn
288
+ │ └────────────────────────────┘ │
289
+ │ │ [Fail/Timeout] │
290
+ │ ┌────────────────────────────┐ │
291
+ │ │ Tier 2: Cost-Effective LLM │ │ ──[Success]──> Accept & Learn
292
+ │ └────────────────────────────┘ │
293
+ │ │ [Fail/Timeout] │
294
+ │ ┌────────────────────────────┐ │
295
+ │ │ Tier 1: Frontier Models │ │ ──[Guaranteed Execution]
296
+ │ └────────────────────────────┘ │
297
+ └──────────────────────────────────┘
298
+
299
+
300
+ ┌──────────────────────────────────┐
301
+ │ 4. Update Reliability & Cache │
302
+ └──────────────────────────────────┘
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Quickstart
308
+
309
+ ### 1. Installation
310
+
311
+ Python 3.11+ is required.
312
+
313
+ **Via pip (recommended):**
314
+ ```bash
315
+ pip install sriti-core
316
+ ```
317
+
318
+ **From source:**
319
+ ```bash
320
+ git clone https://github.com/sriti-ai/sriti-core.git
321
+ cd sriti-core
322
+ pip install -e ".[dev]"
323
+ ```
324
+
325
+ ### 2. Configure Environment
326
+
327
+ Create a `.env` file with your credentials and configuration:
328
+
329
+ ```env
330
+ SRITI_REDIS_URL=redis://localhost:6379/0
331
+ # Optional: Provider API keys (only configure what you use)
332
+ ANTHROPIC_API_KEY=sk-ant-...
333
+ OPENAI_API_KEY=sk-...
334
+ GROQ_API_KEY=gsk_...
335
+ # Optional: AES-256 GCM key for cache encryption (base64-encoded 32 bytes)
336
+ # CACHE_ENCRYPTION_KEY=...
337
+ ```
338
+
339
+ ### 3. Start the Sriti Server
340
+
341
+ ```bash
342
+ uvicorn sriti.app:app --host 0.0.0.0 --port 8100
343
+ ```
344
+
345
+ ### 4. Send a Request via HTTP
346
+
347
+ ```bash
348
+ curl -X POST http://localhost:8100/complete \
349
+ -H "Content-Type: application/json" \
350
+ -d '{
351
+ "prompt": "Extract invoice items and total amount from this ledger snippet...",
352
+ "minimum_tier": "tier_3",
353
+ "cacheable": true,
354
+ "requires_json": true
355
+ }'
356
+ ```
357
+
358
+ ### 5. Python Client SDK
359
+
360
+ You can also use the bundled async Python client:
361
+
362
+ ```python
363
+ import asyncio
364
+ from sriti.client import SritiModelClient
365
+
366
+ async def main():
367
+ client = SritiModelClient(base_url="http://localhost:8100")
368
+ response = await client.complete(
369
+ prompt="Explain the difference between a mutual fund and an ETF in two sentences.",
370
+ minimum_tier="tier_3",
371
+ cacheable=True
372
+ )
373
+ print(f"Response: {response.text}")
374
+ print(f"Tier Used: {response.tier_used}")
375
+ print(f"Latency: {response.latency_ms}ms")
376
+ print(f"Cost: ${response.cost_usd}")
377
+
378
+ asyncio.run(main())
379
+ ```
380
+
381
+ ---
382
+
383
+ ## How It Works
384
+
385
+ ### 1. Task Classification
386
+ Prompts are embedded using `fastembed` and compared against predefined semantic task anchors (or an optional lightweight classification head). The classifier runs completely locally in under 10ms.
387
+
388
+ ### 2. Multi-Tier Semantic Cache
389
+ - Tasks have configurable similarity thresholds in `policy.yaml`. For example, conversational questions allow a similarity threshold of `0.75`, while structured data extraction requires `0.92`.
390
+ - Vectors and encrypted payloads are stored in Valkey/Redis.
391
+
392
+ ### 3. Reliability-Driven Cascading
393
+ - For each tier, active candidates in `models.yaml` are evaluated based on their Pareto score: a composite metric factoring in latency, cost, and historical success probability.
394
+ - If a lower tier experiences an API error, context window exhaustion, or fails a verification check (e.g. invalid JSON syntax), Sriti escalates seamlessly to the next tier.
395
+
396
+ ---
397
+
398
+ ## Configuration
399
+
400
+ Sriti's configuration is managed through two clean YAML files in `sriti/config/`:
401
+
402
+ - **`models.yaml`**: Defines model providers, context windows, cost per token, and tier mappings (`default_tier: 1 | 2 | 3`).
403
+ - **`policy.yaml`**: Defines cache TTLs, per-task similarity thresholds, latency SLOs, and quality gate cutoffs.
404
+
405
+ ---
406
+
407
+ ## Testing
408
+
409
+ Run unit and cascade integration tests using pytest:
410
+
411
+ ```bash
412
+ pytest
413
+ ```
414
+
415
+ All 39 unit tests run without requiring live LLM API keys or a running Redis instance (mocked in-memory).
416
+
417
+ ---
418
+
419
+ ## License
420
+
421
+ This project is licensed under the Apache License 2.0.