sno-llmix 2.0.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.
- sno_llmix-2.0.0/LICENSE +176 -0
- sno_llmix-2.0.0/PKG-INFO +305 -0
- sno_llmix-2.0.0/README.md +281 -0
- sno_llmix-2.0.0/pyproject.toml +47 -0
- sno_llmix-2.0.0/python/llmix/__init__.py +224 -0
- sno_llmix-2.0.0/python/llmix/adaptive_semaphore.py +167 -0
- sno_llmix-2.0.0/python/llmix/batch.py +620 -0
- sno_llmix-2.0.0/python/llmix/config.py +136 -0
- sno_llmix-2.0.0/python/llmix/config_registry.py +526 -0
- sno_llmix-2.0.0/python/llmix/dispatchers/__init__.py +517 -0
- sno_llmix-2.0.0/python/llmix/env.py +119 -0
- sno_llmix-2.0.0/python/llmix/http2.py +126 -0
- sno_llmix-2.0.0/python/llmix/key_pool.py +117 -0
- sno_llmix-2.0.0/python/llmix/lazy_import.py +108 -0
- sno_llmix-2.0.0/python/llmix/mda_loader.py +584 -0
- sno_llmix-2.0.0/python/llmix/model_capabilities.py +172 -0
- sno_llmix-2.0.0/python/llmix/pipeline.py +523 -0
- sno_llmix-2.0.0/python/llmix/pricing.json +69 -0
- sno_llmix-2.0.0/python/llmix/pricing.py +184 -0
- sno_llmix-2.0.0/python/llmix/provider_kwargs.py +228 -0
- sno_llmix-2.0.0/python/llmix/provider_urls.py +47 -0
- sno_llmix-2.0.0/python/llmix/providers/__init__.py +80 -0
- sno_llmix-2.0.0/python/llmix/providers/_config.py +61 -0
- sno_llmix-2.0.0/python/llmix/providers/anthropic_client.py +405 -0
- sno_llmix-2.0.0/python/llmix/providers/base.py +141 -0
- sno_llmix-2.0.0/python/llmix/providers/client_factory.py +94 -0
- sno_llmix-2.0.0/python/llmix/providers/deepinfra_client.py +280 -0
- sno_llmix-2.0.0/python/llmix/providers/gemini_async_client.py +345 -0
- sno_llmix-2.0.0/python/llmix/providers/gemini_common.py +375 -0
- sno_llmix-2.0.0/python/llmix/providers/novita_client.py +263 -0
- sno_llmix-2.0.0/python/llmix/providers/onprem_gpu_client.py +335 -0
- sno_llmix-2.0.0/python/llmix/providers/openai_async_client.py +458 -0
- sno_llmix-2.0.0/python/llmix/providers/openai_common.py +382 -0
- sno_llmix-2.0.0/python/llmix/providers/openrouter_client.py +313 -0
- sno_llmix-2.0.0/python/llmix/providers/together_client.py +233 -0
- sno_llmix-2.0.0/python/llmix/py.typed +0 -0
- sno_llmix-2.0.0/python/llmix/resilience.py +548 -0
- sno_llmix-2.0.0/python/llmix/response_cache.py +449 -0
- sno_llmix-2.0.0/python/llmix/telemetry.py +57 -0
- sno_llmix-2.0.0/python/llmix/thinking.py +69 -0
- sno_llmix-2.0.0/python/llmix/types.py +753 -0
- sno_llmix-2.0.0/python/sno_llmix.egg-info/PKG-INFO +305 -0
- sno_llmix-2.0.0/python/sno_llmix.egg-info/SOURCES.txt +45 -0
- sno_llmix-2.0.0/python/sno_llmix.egg-info/dependency_links.txt +1 -0
- sno_llmix-2.0.0/python/sno_llmix.egg-info/requires.txt +17 -0
- sno_llmix-2.0.0/python/sno_llmix.egg-info/top_level.txt +1 -0
- sno_llmix-2.0.0/setup.cfg +4 -0
sno_llmix-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
|
|
95
|
+
Derivative 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 such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
sno_llmix-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sno-llmix
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Cross-runtime LLM orchestration for Python, TypeScript, and Rust with L2 caching, retries, key rotation, and config-driven runtime control
|
|
5
|
+
Requires-Python: >=3.14
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: openai>=2.0.0
|
|
9
|
+
Requires-Dist: anthropic>=0.40.0
|
|
10
|
+
Requires-Dist: google-genai<3,>=1.18.0
|
|
11
|
+
Requires-Dist: httpx[http2]<0.29,>=0.28.1
|
|
12
|
+
Requires-Dist: cachetools<8,>=5.5.0
|
|
13
|
+
Requires-Dist: pydantic<3,>=2
|
|
14
|
+
Requires-Dist: snoai-mda-config<2,>=1.0.0
|
|
15
|
+
Requires-Dist: json-repair<1,>=0.58.0
|
|
16
|
+
Requires-Dist: openrouter>=0.9.1
|
|
17
|
+
Provides-Extra: redis
|
|
18
|
+
Requires-Dist: redis<8,>=6.4.0; extra == "redis"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pyright>=1.1.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# LLMix
|
|
26
|
+
|
|
27
|
+
[](https://www.npmjs.com/package/@snoai/llmix)
|
|
28
|
+
[](https://pypi.org/project/sno-llmix/)
|
|
29
|
+
[](https://www.python.org/downloads/)
|
|
30
|
+
[](https://www.typescriptlang.org/)
|
|
31
|
+
[](https://www.rust-lang.org/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
|
|
34
|
+
> **Config-driven harness around your LLM SDK.**
|
|
35
|
+
> Swap models by editing MDA presets. Keep the SDK you already use.
|
|
36
|
+
|
|
37
|
+
LLMix sits **above** your existing LLM client — `openai`, `anthropic`, AI SDK, LiteLLM, anything with a callable signature — and wraps it with the production primitives you'd otherwise rebuild from scratch: an MDA-driven config layer, a two-tier response cache, a circuit breaker, key-pool rotation, and singleflight deduplication.
|
|
38
|
+
|
|
39
|
+
Provider, model, and parameters can live in a `.mda` preset. Edit the preset, publish or reload config, and get a different model at runtime. **No redeploy.**
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## At a Glance
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
**Works with:** AI SDK v6 · `openai` (Py/JS) · `anthropic` · `google-genai` · LiteLLM · any async callable that returns your model's response.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Three Things It Does
|
|
52
|
+
|
|
53
|
+
**Config-driven model swap.** Provider, model, and params are *data*, not code. Drop in a new MDA preset, the next call can route to a different provider. Built for agent harnesses that reshape behavior via config, not redeploys.
|
|
54
|
+
|
|
55
|
+
**Production resilience, no extra code.** Two-tier cache (L1 memory + L2 Redis), circuit breaker, key-pool rotation with auto-eviction of dead keys, single flight dedup, adaptive concurrency, retries that honor `Retry-After`. Composable with whatever SDK you already ship.
|
|
56
|
+
|
|
57
|
+
**Runtime parity.** Python, TypeScript, and Rust share byte-identical cache keys and retry semantics. Config authoring now uses MDA Source Mode across all three runtimes. (`llmix-rs` is currently beta — see [`rust/llmix-rs/README.md`](rust/llmix-rs/README.md).)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
### Python
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install sno-llmix
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from llmix import (
|
|
71
|
+
CallInput, CallPipeline, KeyPool, PipelineConfig,
|
|
72
|
+
TwoTierCache, openai_dispatch,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
pipeline = CallPipeline(PipelineConfig(
|
|
76
|
+
dispatch=openai_dispatch(),
|
|
77
|
+
response_cache=TwoTierCache("memory"),
|
|
78
|
+
))
|
|
79
|
+
pipeline.set_key_pool("openai", KeyPool(["sk-..."]))
|
|
80
|
+
|
|
81
|
+
response = await pipeline.call(CallInput(
|
|
82
|
+
config={
|
|
83
|
+
"provider": "openai",
|
|
84
|
+
"model": "gpt-4.1-mini",
|
|
85
|
+
"common": {"temperature": 0.7, "max_output_tokens": 1024},
|
|
86
|
+
"caching": {"strategy": "memory"},
|
|
87
|
+
},
|
|
88
|
+
messages=[{"role": "user", "content": "Summarize this article..."}],
|
|
89
|
+
))
|
|
90
|
+
|
|
91
|
+
print(response.content, response.cache_hit)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### TypeScript
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { CallPipeline, KeyPool, TwoTierCache, openaiDispatch } from "@snoai/llmix";
|
|
98
|
+
|
|
99
|
+
const pipeline = new CallPipeline({
|
|
100
|
+
dispatch: openaiDispatch(),
|
|
101
|
+
responseCache: new TwoTierCache("memory"),
|
|
102
|
+
});
|
|
103
|
+
pipeline.setKeyPool("openai", new KeyPool(["sk-..."]));
|
|
104
|
+
|
|
105
|
+
const response = await pipeline.call({
|
|
106
|
+
config: {
|
|
107
|
+
provider: "openai",
|
|
108
|
+
model: "gpt-4.1-mini",
|
|
109
|
+
common: { temperature: 0.2, maxOutputTokens: 2048 },
|
|
110
|
+
caching: { strategy: "memory" },
|
|
111
|
+
},
|
|
112
|
+
messages: [{ role: "user", content: "Extract entities from this text." }],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
console.log(response.content, response.usage);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Rust
|
|
119
|
+
|
|
120
|
+
```rust
|
|
121
|
+
use llmix_rs::{
|
|
122
|
+
CallInput, CallPipeline, DispatchContext, KeyPool, LlmUsage,
|
|
123
|
+
PipelineConfig, ProviderResult,
|
|
124
|
+
};
|
|
125
|
+
use serde_json::json;
|
|
126
|
+
|
|
127
|
+
#[tokio::main(flavor = "current_thread")]
|
|
128
|
+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
129
|
+
let pipeline = CallPipeline::new(PipelineConfig::new(|ctx: DispatchContext| async move {
|
|
130
|
+
Ok(ProviderResult {
|
|
131
|
+
content: format!("echo: {}", ctx.messages.last().and_then(|m| m.get("content")).and_then(|v| v.as_str()).unwrap_or("")),
|
|
132
|
+
model: ctx.model,
|
|
133
|
+
usage: LlmUsage { input_tokens: 1, output_tokens: 2, total_tokens: 3 },
|
|
134
|
+
headers: None,
|
|
135
|
+
tool_calls: None,
|
|
136
|
+
})
|
|
137
|
+
}))?;
|
|
138
|
+
pipeline.set_key_pool("openai", KeyPool::new(vec!["sk-...".into()])?);
|
|
139
|
+
|
|
140
|
+
let response = pipeline.call(CallInput {
|
|
141
|
+
config: json!({"provider": "openai", "model": "gpt-4o-mini"}),
|
|
142
|
+
messages: vec![json!({"role": "user", "content": "Extract entities."})],
|
|
143
|
+
singleflight_key: None,
|
|
144
|
+
}).await;
|
|
145
|
+
|
|
146
|
+
println!("{}", response.content);
|
|
147
|
+
pipeline.close().await;
|
|
148
|
+
Ok(())
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### MDA Presets
|
|
153
|
+
|
|
154
|
+

|
|
155
|
+
|
|
156
|
+
```mda
|
|
157
|
+
---
|
|
158
|
+
name: extraction
|
|
159
|
+
description: Entity extraction preset.
|
|
160
|
+
metadata:
|
|
161
|
+
snoai-llmix:
|
|
162
|
+
common:
|
|
163
|
+
provider: openai
|
|
164
|
+
model: gpt-4.1-mini
|
|
165
|
+
maxOutputTokens: 2048
|
|
166
|
+
temperature: 0.2
|
|
167
|
+
caching:
|
|
168
|
+
strategy: redis-or-memory
|
|
169
|
+
providerOptions:
|
|
170
|
+
openai:
|
|
171
|
+
reasoningEffort: medium
|
|
172
|
+
---
|
|
173
|
+
# extraction
|
|
174
|
+
|
|
175
|
+
Runtime settings plus human-readable operating notes live together.
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Inside Every Call
|
|
181
|
+
|
|
182
|
+

|
|
183
|
+
|
|
184
|
+
| Concern | What LLMix does |
|
|
185
|
+
|---------------------|------------------------------------------------------------------------------------|
|
|
186
|
+
| **Cache** | L1 memory + optional Redis L2; cross-language byte-identical keys |
|
|
187
|
+
| **Concurrency** | AIMD adaptive semaphore with rate-limit feedback |
|
|
188
|
+
| **Dedup** | Singleflight collapses identical concurrent calls into one upstream request |
|
|
189
|
+
| **Failures** | Retry with jittered exponential backoff; `Retry-After` honored |
|
|
190
|
+
| **Provider health** | Circuit breaker scoped to `(provider, endpoint)` |
|
|
191
|
+
| **API keys** | Round-robin pools; dead-key eviction on `401/403`; fast rotation on `429` |
|
|
192
|
+
| **Request shaping** | Provider-specific kwargs transforms and capability filtering |
|
|
193
|
+
| **Output** | Optional `<think>` token extraction; normalized response objects |
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Tested Against Real Providers
|
|
198
|
+
|
|
199
|
+
Every dispatcher below has a real-HTTP integration suite under `tests/integration/` — no mocks, no recorded fixtures.
|
|
200
|
+
|
|
201
|
+
| Provider | Dispatcher | Primary model under test |
|
|
202
|
+
|-------------|---------------------------------------------|----------------------------------|
|
|
203
|
+
| OpenAI | `openai_dispatch` / `openaiDispatch` | `gpt-4o-mini`, `o4-mini` |
|
|
204
|
+
| Anthropic | `anthropic_dispatch` / `anthropicDispatch` | `claude-haiku-4-5-20251001` |
|
|
205
|
+
| Gemini | `gemini_dispatch` / `geminiDispatch` | `gemini-2.5-flash` |
|
|
206
|
+
| OpenRouter | `openrouter_dispatch` / `openrouterDispatch`| `deepseek/deepseek-v4-flash` |
|
|
207
|
+
| DeepInfra | `deepinfra_dispatch` / `deepinfraDispatch` | `Qwen/Qwen3-32B` |
|
|
208
|
+
| Novita | `novita_dispatch` / `novitaDispatch` | `qwen/qwen3.5-27b` |
|
|
209
|
+
| Together | `together_dispatch` / `togetherDispatch` | `Qwen/Qwen2.5-7B-Instruct-Turbo` |
|
|
210
|
+
| Sno GPU | `sno_gpu_dispatch` / `snoGpuDispatch` | `qwen3.6-27b-extract` |
|
|
211
|
+
|
|
212
|
+
OpenRouter, DeepInfra, Novita, and Together are OpenAI-compatible — their dispatchers reuse the OpenAI client / `@ai-sdk/openai` with a provider-specific `base_url`. TypeScript dispatchers use AI SDK v6 where the provider supports it.
|
|
213
|
+
|
|
214
|
+
Cross-cutting suites (`test_e2e_cache.py`, `_concurrency`, `_parity`, `_redis`, `_resilience`, `_security`, `_thinking`) exercise the pipeline itself across every provider.
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Production Config: the Registry
|
|
219
|
+
|
|
220
|
+
Services that need atomic config updates use the **LLMix Config Registry** — a publishing layer that turns editable `.mda` presets into immutable, content-addressed snapshots.
|
|
221
|
+
|
|
222
|
+
```text
|
|
223
|
+
config/llm/
|
|
224
|
+
authoring/ ← editable .mda presets
|
|
225
|
+
snapshots/<rev>/ ← immutable, content-addressed
|
|
226
|
+
current.json ← the only live switch
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Runtime services open the manager once at startup; reads come from resolved JSON snapshot files, not mutable authoring MDA.
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from llmix import ConfigRegistryManager, ConfigRegistryPublisher, resolve_config_dir
|
|
233
|
+
|
|
234
|
+
root = resolve_config_dir().config_dir
|
|
235
|
+
ConfigRegistryPublisher(root).publish()
|
|
236
|
+
|
|
237
|
+
manager = ConfigRegistryManager.open(root)
|
|
238
|
+
config = manager.get_preset("search", "summary")
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { ConfigRegistryManager, ConfigRegistryPublisher, resolveConfigDir } from "@snoai/llmix";
|
|
243
|
+
|
|
244
|
+
const { configDir } = resolveConfigDir();
|
|
245
|
+
await new ConfigRegistryPublisher(configDir).publish();
|
|
246
|
+
|
|
247
|
+
const manager = await ConfigRegistryManager.open(configDir);
|
|
248
|
+
const config = await manager.getPreset("search", "summary");
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Managers expose the active revision and reload-health metadata so service code can surface which revision is live.
|
|
252
|
+
|
|
253
|
+
TypeScript authoring tools can use `loadMdaConfig` / `loadMdaConfigPreset`; Python authoring tools can use `load_mda_config` / `load_mda_config_preset`; Rust authoring tools can use `load_config` / `load_config_preset`, which now hard-require `.mda` files. None of these direct loaders are the production hot path.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## What This Is *Not*
|
|
258
|
+
|
|
259
|
+
- **Not a streaming library.** Streaming is your SDK's job. LLMix handles calls, not chunks.
|
|
260
|
+
- **Not a provider replacement.** It wraps your client, it doesn't replace it.
|
|
261
|
+
- **Not a cross-provider router** in the LiteLLM sense. One call, one provider — the one your config names.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Environment Variables
|
|
266
|
+
|
|
267
|
+
| Variable | Purpose |
|
|
268
|
+
|-----------------------------------|------------------------------------------------------|
|
|
269
|
+
| `OPENAI_API_KEY` / `OPENAI_KEYS` | Single key or comma-separated OpenAI key pool |
|
|
270
|
+
| `ANTHROPIC_API_KEY` | Anthropic auth |
|
|
271
|
+
| `GEMINI_API_KEY` | Google / Gemini auth |
|
|
272
|
+
| `OPENROUTER_API_KEY` | OpenRouter auth |
|
|
273
|
+
| `SNO_LLM_API_KEY` | Sno GPU auth |
|
|
274
|
+
| `GPU_BASE_URL` | Sno GPU base URL |
|
|
275
|
+
| `REDIS_URL` | Redis L2 cache |
|
|
276
|
+
| `LLMIX_STATE_DIR` | Lock files, batch metadata, kill switch state |
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# TypeScript
|
|
284
|
+
bun install && bun test
|
|
285
|
+
bunx tsc -p tsconfig.check.json
|
|
286
|
+
|
|
287
|
+
# Python
|
|
288
|
+
uv sync && uv run pytest tests/python/
|
|
289
|
+
uv run pyright
|
|
290
|
+
|
|
291
|
+
# Rust
|
|
292
|
+
cargo test --manifest-path rust/llmix-rs/Cargo.toml
|
|
293
|
+
cargo clippy --manifest-path rust/llmix-rs/Cargo.toml -- -D warnings
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
[Apache-2.0](LICENSE)
|
|
301
|
+
|
|
302
|
+
## Related
|
|
303
|
+
|
|
304
|
+
- [AI SDK](https://ai-sdk.dev/)
|
|
305
|
+
- [Promptix](https://github.com/sno-ai/promptix)
|