tryaii-dre 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 (60) hide show
  1. tryaii_dre-0.2.0/.gitignore +62 -0
  2. tryaii_dre-0.2.0/LICENSE +190 -0
  3. tryaii_dre-0.2.0/PKG-INFO +186 -0
  4. tryaii_dre-0.2.0/README.md +138 -0
  5. tryaii_dre-0.2.0/examples/advanced_routing.py +90 -0
  6. tryaii_dre-0.2.0/examples/custom_benchmarks.py +63 -0
  7. tryaii_dre-0.2.0/examples/openai_embeddings.py +18 -0
  8. tryaii_dre-0.2.0/examples/openrouter_integration.py +46 -0
  9. tryaii_dre-0.2.0/examples/quickstart.py +45 -0
  10. tryaii_dre-0.2.0/examples/try_it.py +108 -0
  11. tryaii_dre-0.2.0/pyproject.toml +87 -0
  12. tryaii_dre-0.2.0/tests/__init__.py +0 -0
  13. tryaii_dre-0.2.0/tests/test_budget.py +48 -0
  14. tryaii_dre-0.2.0/tests/test_centroids/__init__.py +0 -0
  15. tryaii_dre-0.2.0/tests/test_centroids/test_generator.py +88 -0
  16. tryaii_dre-0.2.0/tests/test_classifiers/__init__.py +0 -0
  17. tryaii_dre-0.2.0/tests/test_classifiers/test_embedding.py +120 -0
  18. tryaii_dre-0.2.0/tests/test_integrations/__init__.py +0 -0
  19. tryaii_dre-0.2.0/tests/test_integrations/test_openrouter.py +32 -0
  20. tryaii_dre-0.2.0/tests/test_parity.py +106 -0
  21. tryaii_dre-0.2.0/tests/test_registry/__init__.py +0 -0
  22. tryaii_dre-0.2.0/tests/test_registry/test_models.py +130 -0
  23. tryaii_dre-0.2.0/tests/test_router.py +171 -0
  24. tryaii_dre-0.2.0/tests/test_scoring/__init__.py +0 -0
  25. tryaii_dre-0.2.0/tests/test_scoring/test_benchmarks.py +83 -0
  26. tryaii_dre-0.2.0/tests/test_scoring/test_engine.py +146 -0
  27. tryaii_dre-0.2.0/tryaii_dre/__init__.py +61 -0
  28. tryaii_dre-0.2.0/tryaii_dre/async_client.py +487 -0
  29. tryaii_dre-0.2.0/tryaii_dre/benchmarks/__init__.py +4 -0
  30. tryaii_dre-0.2.0/tryaii_dre/benchmarks/registry.py +193 -0
  31. tryaii_dre-0.2.0/tryaii_dre/benchmarks/standard.py +105 -0
  32. tryaii_dre-0.2.0/tryaii_dre/budget.py +460 -0
  33. tryaii_dre-0.2.0/tryaii_dre/centroids/__init__.py +4 -0
  34. tryaii_dre-0.2.0/tryaii_dre/centroids/data/centroids_all-MiniLM-L6-v2.json +1 -0
  35. tryaii_dre-0.2.0/tryaii_dre/centroids/data/training_queries.json +246 -0
  36. tryaii_dre-0.2.0/tryaii_dre/centroids/generator.py +214 -0
  37. tryaii_dre-0.2.0/tryaii_dre/centroids/loader.py +214 -0
  38. tryaii_dre-0.2.0/tryaii_dre/classifiers/__init__.py +8 -0
  39. tryaii_dre-0.2.0/tryaii_dre/classifiers/base.py +77 -0
  40. tryaii_dre-0.2.0/tryaii_dre/classifiers/embedding.py +197 -0
  41. tryaii_dre-0.2.0/tryaii_dre/cli/__init__.py +0 -0
  42. tryaii_dre-0.2.0/tryaii_dre/cli/banner.py +162 -0
  43. tryaii_dre-0.2.0/tryaii_dre/cli/main.py +763 -0
  44. tryaii_dre-0.2.0/tryaii_dre/client.py +206 -0
  45. tryaii_dre-0.2.0/tryaii_dre/config.py +105 -0
  46. tryaii_dre-0.2.0/tryaii_dre/embeddings/__init__.py +9 -0
  47. tryaii_dre-0.2.0/tryaii_dre/embeddings/base.py +54 -0
  48. tryaii_dre-0.2.0/tryaii_dre/embeddings/local.py +83 -0
  49. tryaii_dre-0.2.0/tryaii_dre/embeddings/openai_provider.py +83 -0
  50. tryaii_dre-0.2.0/tryaii_dre/integrations/__init__.py +3 -0
  51. tryaii_dre-0.2.0/tryaii_dre/integrations/openrouter.py +436 -0
  52. tryaii_dre-0.2.0/tryaii_dre/registry/__init__.py +3 -0
  53. tryaii_dre-0.2.0/tryaii_dre/registry/models.py +252 -0
  54. tryaii_dre-0.2.0/tryaii_dre/registry/presets/__init__.py +0 -0
  55. tryaii_dre-0.2.0/tryaii_dre/registry/presets/default_models.json +932 -0
  56. tryaii_dre-0.2.0/tryaii_dre/router.py +283 -0
  57. tryaii_dre-0.2.0/tryaii_dre/scoring/__init__.py +11 -0
  58. tryaii_dre-0.2.0/tryaii_dre/scoring/benchmarks.py +82 -0
  59. tryaii_dre-0.2.0/tryaii_dre/scoring/engine.py +284 -0
  60. tryaii_dre-0.2.0/tryaii_dre/scoring/priorities.py +93 -0
@@ -0,0 +1,62 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ *.egg
10
+ .venv/
11
+ venv/
12
+ .mypy_cache/
13
+ .pytest_cache/
14
+ .ruff_cache/
15
+ htmlcov/
16
+ .coverage
17
+
18
+ # Node
19
+ node_modules/
20
+ dist/
21
+ *.tsbuildinfo
22
+ .eslintcache
23
+ .npm-cache/
24
+
25
+ # IDE
26
+ .vscode/
27
+ .idea/
28
+ *.swp
29
+ *.swo
30
+ *~
31
+
32
+ # OS
33
+ .DS_Store
34
+ Thumbs.db
35
+
36
+ # Environment
37
+ .env
38
+ .env.local
39
+ .env.*.local
40
+
41
+ # Logs
42
+ *.log
43
+
44
+ # Claude Code
45
+ .claude/
46
+
47
+ # Local-only docs
48
+ packages/python/CENTROIDS_AND_UPDATES.md
49
+
50
+ # Local-only dev workspace (eval runner, datasets, scratch scripts)
51
+ eval/
52
+
53
+ # Local benchmark snapshot cache (fetched from the tryaii-bench API)
54
+ cache/
55
+
56
+ # Derived routing data built from the snapshot (scripts/build_cache_shared.py)
57
+ cache-shared/
58
+
59
+ # Internal scratch / proposals
60
+ MIGRATION.md
61
+ docs/benchmarks-compare.html
62
+ Jira/
@@ -0,0 +1,190 @@
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 the 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 the 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 any 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
+ Copyright 2026 TryAII Team
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.4
2
+ Name: tryaii-dre
3
+ Version: 0.2.0
4
+ Summary: TryAii Diff Routing Engine -- Embedding-based AI model router. Understands your prompt semantically and routes to the best model based on benchmarks, cost, speed, and quality.
5
+ Project-URL: Homepage, https://github.com/tamirblu/Tryaii-RE
6
+ Project-URL: Documentation, https://github.com/tamirblu/Tryaii-RE#readme
7
+ Project-URL: Repository, https://github.com/tamirblu/Tryaii-RE
8
+ Project-URL: Issues, https://github.com/tamirblu/Tryaii-RE/issues
9
+ Author-email: TryAII Team <ceo@tryaii.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ai,benchmark,embeddings,llm,model-selection,openrouter,prompt-classification,routing
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: numpy>=1.24.0
26
+ Requires-Dist: pydantic>=2.0.0
27
+ Requires-Dist: python-dotenv>=1.0.0
28
+ Requires-Dist: sentence-transformers>=2.2.0
29
+ Provides-Extra: all
30
+ Requires-Dist: httpx>=0.25.0; extra == 'all'
31
+ Requires-Dist: openai>=1.0.0; extra == 'all'
32
+ Requires-Dist: redis>=5.0.0; extra == 'all'
33
+ Provides-Extra: dev
34
+ Requires-Dist: build>=1.2.0; extra == 'dev'
35
+ Requires-Dist: mypy>=1.5.0; extra == 'dev'
36
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
38
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
40
+ Requires-Dist: twine>=5.0.0; extra == 'dev'
41
+ Provides-Extra: openai
42
+ Requires-Dist: openai>=1.0.0; extra == 'openai'
43
+ Provides-Extra: openrouter
44
+ Requires-Dist: httpx>=0.25.0; extra == 'openrouter'
45
+ Provides-Extra: redis
46
+ Requires-Dist: redis>=5.0.0; extra == 'redis'
47
+ Description-Content-Type: text/markdown
48
+
49
+ # TryAii-DRE
50
+
51
+ **Embedding-based AI model router.** Understands your prompt semantically and routes to the best model based on benchmarks, cost, speed, and quality.
52
+
53
+ ```python
54
+ from tryaii_dre import DREClient, Router
55
+
56
+ router = Router()
57
+ result = router.route("Write a Python function to merge sorted arrays")
58
+
59
+ print(result.best_model) # "gpt-5.2"
60
+ print(result.best_reasoning) # "Quality: 0.94 on [HumanEval (93%), SWE-bench (87%)]"
61
+
62
+ client = DREClient(api_key="sk-or-...")
63
+ response = client.chat("Write a quicksort implementation")
64
+ print(response.content)
65
+ ```
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pip install tryaii-dre
71
+ ```
72
+
73
+ The base install includes local embeddings via `sentence-transformers` - no API keys needed.
74
+
75
+ Optional extras for provider integrations:
76
+
77
+ ```bash
78
+ pip install tryaii-dre[openrouter] # Route & call models via OpenRouter (adds httpx)
79
+ pip install tryaii-dre[openai] # Use OpenAI embeddings instead of local (adds openai)
80
+ pip install tryaii-dre[redis] # Redis client for planned distributed cache (not yet implemented)
81
+ pip install tryaii-dre[all] # All optional integrations
82
+ ```
83
+
84
+ ## Quick Start
85
+
86
+ ```python
87
+ from tryaii_dre import Router, Priorities
88
+
89
+ router = Router()
90
+
91
+ # Route with default balanced priorities
92
+ result = router.route("Explain quantum entanglement simply")
93
+ print(result.best_model)
94
+
95
+ # Quality-first (ignore cost)
96
+ result = router.route(
97
+ "Debug this memory leak in my Node.js app",
98
+ priorities=Priorities(quality=5, cost=1, speed=2),
99
+ )
100
+
101
+ # Budget mode
102
+ result = router.route(
103
+ "Summarize this email",
104
+ priorities=Priorities.budget(),
105
+ )
106
+ ```
107
+
108
+ ## CLI
109
+
110
+ Installing the package adds a `tryaii-dre` command (same surface as the Node SDK). It opens
111
+ with an animated blue→red banner, then runs your command. The banner prints to stderr and
112
+ auto-suppresses when output is piped, so `--json` stays clean.
113
+
114
+ ```bash
115
+ tryaii-dre route "Write a Python function to merge sorted arrays" --quality=5 --cost=1
116
+ tryaii-dre eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1
117
+ tryaii-dre models --provider anthropic # add --json for machine-readable output
118
+ tryaii-dre benchmarks --json
119
+ tryaii-dre setup # download the embedding model + warm centroids
120
+ ```
121
+
122
+ | Command | Key options |
123
+ |---------|-------------|
124
+ | `route "<prompt>"` | `--quality/--cost/--speed <1-5>` (default 3), `--top-k <n>` |
125
+ | `eval <input.json>` | `-o/--output <dir>`, `--max-price <usd>`, `--output-tokens <n>`, `--budget-mode strict\|fit-output` |
126
+ | `models` | `--provider <name>`, `--json` |
127
+ | `benchmarks` | `--json` |
128
+ | `setup` / `regenerate` | `--model <name>` |
129
+
130
+ Global flags: `--no-banner` (or `TRYAII_NO_BANNER=1`), `NO_COLOR=1`, `-v/--verbose`.
131
+
132
+ ### Eval over a dataset
133
+
134
+ ```bash
135
+ # Balanced run into a named folder
136
+ tryaii-dre eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1
137
+
138
+ # Budget-aware: --max-price is the total budget for the whole dataset
139
+ tryaii-dre eval prompts.json --output results/budget --max-price=0.10 --output-tokens=2000
140
+ tryaii-dre eval prompts.json --output results/budget-fit --max-price=0.10 --output-tokens=2000 --budget-mode=fit-output
141
+ ```
142
+
143
+ The input can be an array of strings or objects with `prompt`, optional `id`,
144
+ and optional `category`. In budgeted eval, quality/cost/speed priority flags
145
+ are ignored: price is the hard constraint, and the optimizer maximizes model
146
+ quality within that price. `--budget-mode=fit-output` lowers the fixed output
147
+ token estimate when the requested length cannot fit the total budget. The
148
+ command writes `results.jsonl`, `summary.json`, and `index.html`.
149
+
150
+ ## OpenRouter Integration
151
+
152
+ ```python
153
+ from tryaii_dre import Router
154
+ from tryaii_dre.integrations import OpenRouterIntegration
155
+
156
+ router = Router()
157
+ openrouter = OpenRouterIntegration(router, api_key="sk-or-...")
158
+
159
+ response = openrouter.chat("Write a quicksort implementation")
160
+ print(response.model_used) # Auto-selected best model
161
+ print(response.content) # Actual response
162
+ ```
163
+
164
+ ## OpenAI Embeddings
165
+
166
+ ```python
167
+ from tryaii_dre import Router
168
+ from tryaii_dre.embeddings import OpenAIEmbeddingProvider
169
+
170
+ router = Router(
171
+ embedding_provider=OpenAIEmbeddingProvider(),
172
+ )
173
+
174
+ result = router.route("Summarize this architecture decision")
175
+ print(result.best_model)
176
+ ```
177
+
178
+ Install the OpenAI client first:
179
+
180
+ ```bash
181
+ pip install tryaii-dre[openai]
182
+ ```
183
+
184
+ ## License
185
+
186
+ Apache 2.0
@@ -0,0 +1,138 @@
1
+ # TryAii-DRE
2
+
3
+ **Embedding-based AI model router.** Understands your prompt semantically and routes to the best model based on benchmarks, cost, speed, and quality.
4
+
5
+ ```python
6
+ from tryaii_dre import DREClient, Router
7
+
8
+ router = Router()
9
+ result = router.route("Write a Python function to merge sorted arrays")
10
+
11
+ print(result.best_model) # "gpt-5.2"
12
+ print(result.best_reasoning) # "Quality: 0.94 on [HumanEval (93%), SWE-bench (87%)]"
13
+
14
+ client = DREClient(api_key="sk-or-...")
15
+ response = client.chat("Write a quicksort implementation")
16
+ print(response.content)
17
+ ```
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ pip install tryaii-dre
23
+ ```
24
+
25
+ The base install includes local embeddings via `sentence-transformers` - no API keys needed.
26
+
27
+ Optional extras for provider integrations:
28
+
29
+ ```bash
30
+ pip install tryaii-dre[openrouter] # Route & call models via OpenRouter (adds httpx)
31
+ pip install tryaii-dre[openai] # Use OpenAI embeddings instead of local (adds openai)
32
+ pip install tryaii-dre[redis] # Redis client for planned distributed cache (not yet implemented)
33
+ pip install tryaii-dre[all] # All optional integrations
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ```python
39
+ from tryaii_dre import Router, Priorities
40
+
41
+ router = Router()
42
+
43
+ # Route with default balanced priorities
44
+ result = router.route("Explain quantum entanglement simply")
45
+ print(result.best_model)
46
+
47
+ # Quality-first (ignore cost)
48
+ result = router.route(
49
+ "Debug this memory leak in my Node.js app",
50
+ priorities=Priorities(quality=5, cost=1, speed=2),
51
+ )
52
+
53
+ # Budget mode
54
+ result = router.route(
55
+ "Summarize this email",
56
+ priorities=Priorities.budget(),
57
+ )
58
+ ```
59
+
60
+ ## CLI
61
+
62
+ Installing the package adds a `tryaii-dre` command (same surface as the Node SDK). It opens
63
+ with an animated blue→red banner, then runs your command. The banner prints to stderr and
64
+ auto-suppresses when output is piped, so `--json` stays clean.
65
+
66
+ ```bash
67
+ tryaii-dre route "Write a Python function to merge sorted arrays" --quality=5 --cost=1
68
+ tryaii-dre eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1
69
+ tryaii-dre models --provider anthropic # add --json for machine-readable output
70
+ tryaii-dre benchmarks --json
71
+ tryaii-dre setup # download the embedding model + warm centroids
72
+ ```
73
+
74
+ | Command | Key options |
75
+ |---------|-------------|
76
+ | `route "<prompt>"` | `--quality/--cost/--speed <1-5>` (default 3), `--top-k <n>` |
77
+ | `eval <input.json>` | `-o/--output <dir>`, `--max-price <usd>`, `--output-tokens <n>`, `--budget-mode strict\|fit-output` |
78
+ | `models` | `--provider <name>`, `--json` |
79
+ | `benchmarks` | `--json` |
80
+ | `setup` / `regenerate` | `--model <name>` |
81
+
82
+ Global flags: `--no-banner` (or `TRYAII_NO_BANNER=1`), `NO_COLOR=1`, `-v/--verbose`.
83
+
84
+ ### Eval over a dataset
85
+
86
+ ```bash
87
+ # Balanced run into a named folder
88
+ tryaii-dre eval prompts.json --output results/my-run --quality=5 --cost=1 --speed=1
89
+
90
+ # Budget-aware: --max-price is the total budget for the whole dataset
91
+ tryaii-dre eval prompts.json --output results/budget --max-price=0.10 --output-tokens=2000
92
+ tryaii-dre eval prompts.json --output results/budget-fit --max-price=0.10 --output-tokens=2000 --budget-mode=fit-output
93
+ ```
94
+
95
+ The input can be an array of strings or objects with `prompt`, optional `id`,
96
+ and optional `category`. In budgeted eval, quality/cost/speed priority flags
97
+ are ignored: price is the hard constraint, and the optimizer maximizes model
98
+ quality within that price. `--budget-mode=fit-output` lowers the fixed output
99
+ token estimate when the requested length cannot fit the total budget. The
100
+ command writes `results.jsonl`, `summary.json`, and `index.html`.
101
+
102
+ ## OpenRouter Integration
103
+
104
+ ```python
105
+ from tryaii_dre import Router
106
+ from tryaii_dre.integrations import OpenRouterIntegration
107
+
108
+ router = Router()
109
+ openrouter = OpenRouterIntegration(router, api_key="sk-or-...")
110
+
111
+ response = openrouter.chat("Write a quicksort implementation")
112
+ print(response.model_used) # Auto-selected best model
113
+ print(response.content) # Actual response
114
+ ```
115
+
116
+ ## OpenAI Embeddings
117
+
118
+ ```python
119
+ from tryaii_dre import Router
120
+ from tryaii_dre.embeddings import OpenAIEmbeddingProvider
121
+
122
+ router = Router(
123
+ embedding_provider=OpenAIEmbeddingProvider(),
124
+ )
125
+
126
+ result = router.route("Summarize this architecture decision")
127
+ print(result.best_model)
128
+ ```
129
+
130
+ Install the OpenAI client first:
131
+
132
+ ```bash
133
+ pip install tryaii-dre[openai]
134
+ ```
135
+
136
+ ## License
137
+
138
+ Apache 2.0
@@ -0,0 +1,90 @@
1
+ """
2
+ Advanced Routing -- Custom registries, filtering, and multi-step agents.
3
+
4
+ Shows how to build sophisticated routing logic on top of TryAii-DRE.
5
+ """
6
+
7
+ from tryaii_dre import TryaiiDreConfig, ModelRegistry, Priorities, Router
8
+
9
+ # ---- Custom model registry ----
10
+
11
+ registry = ModelRegistry() # Start empty
12
+
13
+ # Add only the models you want to route between
14
+ registry.add(
15
+ "gpt-4o-mini",
16
+ provider="OpenAI",
17
+ benchmarks={"HumanEval": 87.2, "MMLU": 70.0, "GSM8K": 87.0},
18
+ pricing=(0.00015, 0.0006),
19
+ latency="very fast",
20
+ capabilities=["fast-response", "cost-effective"],
21
+ )
22
+ registry.add(
23
+ "claude-sonnet-4-5-20250929",
24
+ provider="Anthropic",
25
+ benchmarks={"HumanEval": 93.0, "SWE-bench": 77.2, "MMLU": 89.1},
26
+ pricing=(0.003, 0.015),
27
+ latency="medium",
28
+ capabilities=["advanced-reasoning", "code-generation"],
29
+ )
30
+ registry.add(
31
+ "gemini-2.5-flash",
32
+ provider="Google",
33
+ benchmarks={"HumanEval": 78.0, "MMLU": 84.0, "GSM8K": 92.0},
34
+ pricing=(0.00015, 0.00035),
35
+ latency="fast",
36
+ capabilities=["fast-response", "multimodal"],
37
+ )
38
+
39
+ router = Router(registry=registry)
40
+
41
+
42
+ # ---- Multi-step agent routing ----
43
+ # Different steps of an agent pipeline need different model strengths
44
+
45
+ def route_agent_step(step_type: str, prompt: str) -> str:
46
+ """Route each agent step to the optimal model."""
47
+ strategies = {
48
+ "planning": Priorities(quality=5, cost=1, speed=1),
49
+ "code_generation": Priorities(quality=5, cost=2, speed=2),
50
+ "summarization": Priorities(quality=2, cost=5, speed=4),
51
+ "validation": Priorities(quality=4, cost=3, speed=3),
52
+ }
53
+
54
+ priorities = strategies.get(step_type, Priorities.balanced())
55
+ result = router.route(prompt, priorities=priorities)
56
+
57
+ print(f" [{step_type}] -> {result.best_model} (score: {result.best_score:.3f})")
58
+ return result.best_model
59
+
60
+
61
+ print("Agent pipeline routing:")
62
+ route_agent_step("planning", "Plan the architecture for a REST API")
63
+ route_agent_step("code_generation", "Write the authentication middleware")
64
+ route_agent_step("summarization", "Summarize the changes made in this PR")
65
+ route_agent_step("validation", "Check this code for security vulnerabilities")
66
+
67
+
68
+ # ---- Cost-constrained routing ----
69
+
70
+ print("\n\nCost-constrained routing (max $0.001/1k input):")
71
+ result = router.route(
72
+ "Write unit tests for this function",
73
+ filter_max_cost=0.001,
74
+ )
75
+ print(f" Best under $0.001: {result.best_model}")
76
+ for s in result.scores:
77
+ m = router.models.get_model(s.model_id)
78
+ cost = f"${m.pricing.input_per_1k:.5f}" if m and m.pricing else "?"
79
+ print(f" {s.model_id}: score={s.final_score:.3f}, input_cost={cost}")
80
+
81
+
82
+ # ---- Custom embedding model ----
83
+
84
+ print("\n\nUsing a different embedding model:")
85
+ config = TryaiiDreConfig(embedding_model="all-mpnet-base-v2")
86
+ custom_router = Router(config=config, registry=registry)
87
+
88
+ result = custom_router.route("Optimize this SQL query for performance")
89
+ print(f" Best model: {result.best_model}")
90
+ print(f" Classifier: {result.classification.classifier_used}")