vetch 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.
- vetch-0.1.0/.gitignore +91 -0
- vetch-0.1.0/CHANGELOG.md +54 -0
- vetch-0.1.0/LICENSE +190 -0
- vetch-0.1.0/NOTICE +31 -0
- vetch-0.1.0/PKG-INFO +257 -0
- vetch-0.1.0/README.md +212 -0
- vetch-0.1.0/SECURITY.md +60 -0
- vetch-0.1.0/pyproject.toml +96 -0
- vetch-0.1.0/src/vetch/METHODOLOGY.md +124 -0
- vetch-0.1.0/src/vetch/__init__.py +142 -0
- vetch-0.1.0/src/vetch/advisory.py +87 -0
- vetch-0.1.0/src/vetch/calculation.py +381 -0
- vetch-0.1.0/src/vetch/calibrate.py +191 -0
- vetch-0.1.0/src/vetch/ci.py +63 -0
- vetch-0.1.0/src/vetch/cli.py +807 -0
- vetch-0.1.0/src/vetch/compat.py +168 -0
- vetch-0.1.0/src/vetch/config.py +69 -0
- vetch-0.1.0/src/vetch/context.py +149 -0
- vetch-0.1.0/src/vetch/emitter.py +197 -0
- vetch-0.1.0/src/vetch/exceptions.py +91 -0
- vetch-0.1.0/src/vetch/otel.py +59 -0
- vetch-0.1.0/src/vetch/providers/__init__.py +14 -0
- vetch-0.1.0/src/vetch/providers/anthropic.py +352 -0
- vetch-0.1.0/src/vetch/providers/openai.py +472 -0
- vetch-0.1.0/src/vetch/providers/vertexai.py +434 -0
- vetch-0.1.0/src/vetch/proxy.py +220 -0
- vetch-0.1.0/src/vetch/py.typed +0 -0
- vetch-0.1.0/src/vetch/registry/PROVENANCE.md +41 -0
- vetch-0.1.0/src/vetch/registry/aliases.json +20 -0
- vetch-0.1.0/src/vetch/registry/energy.json +62 -0
- vetch-0.1.0/src/vetch/registry/pricing.json +42 -0
- vetch-0.1.0/src/vetch/schema.py +196 -0
- vetch-0.1.0/src/vetch/sensing/__init__.py +28 -0
- vetch-0.1.0/src/vetch/sensing/cache.py +377 -0
- vetch-0.1.0/src/vetch/sensing/global_averages.json +60 -0
- vetch-0.1.0/src/vetch/sensing/grid.py +319 -0
- vetch-0.1.0/src/vetch/sensing/memory_cache.py +165 -0
- vetch-0.1.0/src/vetch/stats.py +71 -0
- vetch-0.1.0/src/vetch/storage.py +269 -0
- vetch-0.1.0/src/vetch/wrapper.py +614 -0
- vetch-0.1.0/tests/__init__.py +1 -0
- vetch-0.1.0/tests/conftest.py +30 -0
- vetch-0.1.0/tests/test_advisory.py +146 -0
- vetch-0.1.0/tests/test_advisory_new.py +32 -0
- vetch-0.1.0/tests/test_anthropic.py +284 -0
- vetch-0.1.0/tests/test_calculation.py +198 -0
- vetch-0.1.0/tests/test_calibrate.py +293 -0
- vetch-0.1.0/tests/test_chaos.py +526 -0
- vetch-0.1.0/tests/test_chaos_storage.py +88 -0
- vetch-0.1.0/tests/test_ci.py +178 -0
- vetch-0.1.0/tests/test_cli.py +182 -0
- vetch-0.1.0/tests/test_compat.py +162 -0
- vetch-0.1.0/tests/test_compat_deep.py +78 -0
- vetch-0.1.0/tests/test_config.py +136 -0
- vetch-0.1.0/tests/test_config_new.py +48 -0
- vetch-0.1.0/tests/test_context.py +141 -0
- vetch-0.1.0/tests/test_emitter.py +169 -0
- vetch-0.1.0/tests/test_emitter_deep.py +95 -0
- vetch-0.1.0/tests/test_exceptions.py +164 -0
- vetch-0.1.0/tests/test_file_locking.py +328 -0
- vetch-0.1.0/tests/test_grid_deep.py +67 -0
- vetch-0.1.0/tests/test_grid_failure.py +314 -0
- vetch-0.1.0/tests/test_integration.py +220 -0
- vetch-0.1.0/tests/test_memory_cache.py +246 -0
- vetch-0.1.0/tests/test_multiprocess_cache.py +84 -0
- vetch-0.1.0/tests/test_nested_context.py +50 -0
- vetch-0.1.0/tests/test_openai.py +319 -0
- vetch-0.1.0/tests/test_otel.py +162 -0
- vetch-0.1.0/tests/test_patch_chain.py +237 -0
- vetch-0.1.0/tests/test_patch_failure.py +212 -0
- vetch-0.1.0/tests/test_proxy.py +263 -0
- vetch-0.1.0/tests/test_proxy_deep.py +140 -0
- vetch-0.1.0/tests/test_region_inference.py +118 -0
- vetch-0.1.0/tests/test_schema.py +188 -0
- vetch-0.1.0/tests/test_serverless_mode.py +51 -0
- vetch-0.1.0/tests/test_stats.py +119 -0
- vetch-0.1.0/tests/test_storage.py +216 -0
- vetch-0.1.0/tests/test_storage_new.py +46 -0
- vetch-0.1.0/tests/test_stream_completion.py +224 -0
- vetch-0.1.0/tests/test_streaming_memory.py +184 -0
- vetch-0.1.0/tests/test_vertexai.py +273 -0
- vetch-0.1.0/tests/test_wrapper.py +145 -0
vetch-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
*.manifest
|
|
31
|
+
*.spec
|
|
32
|
+
|
|
33
|
+
# Installer logs
|
|
34
|
+
pip-log.txt
|
|
35
|
+
pip-delete-this-directory.txt
|
|
36
|
+
|
|
37
|
+
# Unit test / coverage reports
|
|
38
|
+
htmlcov/
|
|
39
|
+
.tox/
|
|
40
|
+
.nox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
*.py,cover
|
|
48
|
+
.hypothesis/
|
|
49
|
+
.pytest_cache/
|
|
50
|
+
|
|
51
|
+
# Translations
|
|
52
|
+
*.mo
|
|
53
|
+
*.pot
|
|
54
|
+
|
|
55
|
+
# Environments
|
|
56
|
+
.env
|
|
57
|
+
.venv
|
|
58
|
+
env/
|
|
59
|
+
venv/
|
|
60
|
+
ENV/
|
|
61
|
+
env.bak/
|
|
62
|
+
venv.bak/
|
|
63
|
+
|
|
64
|
+
# IDEs
|
|
65
|
+
.idea/
|
|
66
|
+
.vscode/
|
|
67
|
+
*.swp
|
|
68
|
+
*.swo
|
|
69
|
+
*~
|
|
70
|
+
|
|
71
|
+
# macOS
|
|
72
|
+
.DS_Store
|
|
73
|
+
|
|
74
|
+
# mypy
|
|
75
|
+
.mypy_cache/
|
|
76
|
+
.dmypy.json
|
|
77
|
+
dmypy.json
|
|
78
|
+
|
|
79
|
+
# ruff
|
|
80
|
+
.ruff_cache/
|
|
81
|
+
|
|
82
|
+
# Jupyter
|
|
83
|
+
.ipynb_checkpoints/
|
|
84
|
+
|
|
85
|
+
# Local development
|
|
86
|
+
*.local
|
|
87
|
+
.envrc
|
|
88
|
+
|
|
89
|
+
# Vetch cache files (for testing)
|
|
90
|
+
vetch_grid_cache.json
|
|
91
|
+
vetch_grid_cache.json.tmp
|
vetch-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-02-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial **alpha** release of Vetch SDK
|
|
12
|
+
- Core context manager: `wrap()` for energy/carbon/cost tracking
|
|
13
|
+
- OpenAI provider wrapper (sync & streaming)
|
|
14
|
+
- Vertex AI provider wrapper (sync & streaming)
|
|
15
|
+
- Anthropic provider wrapper (sync & streaming)
|
|
16
|
+
- Multi-tier grid intensity cache (Memory + File with locking)
|
|
17
|
+
- Serverless mode (`VETCH_CACHE_MODE=memory-only`)
|
|
18
|
+
- Energy calculation engine with model registry
|
|
19
|
+
- Pricing registry for list cost estimation with `price_multiplier` support
|
|
20
|
+
- CLI tool: `estimate`, `compare`, `methodology`, `check`, `audit`, `report`
|
|
21
|
+
- Token estimation with tiktoken integration and language-aware fallback
|
|
22
|
+
- Session statistics: `get_session_stats()` for pattern detection
|
|
23
|
+
- Advisory engine: `generate_advisories()` for optimization recommendations
|
|
24
|
+
- OpenTelemetry span decoration (attach metrics to existing spans)
|
|
25
|
+
- SQLite local storage for historical analysis (experimental)
|
|
26
|
+
- GPU calibration module for Tier 0 measurements (experimental)
|
|
27
|
+
- CI summary mode for GitHub Actions
|
|
28
|
+
|
|
29
|
+
### Safety Features
|
|
30
|
+
- **Fail-open behavior**: LLM calls always proceed even when Vetch fails
|
|
31
|
+
- **Fail-loud diagnostics**: `vetch_warnings` field captures all issues
|
|
32
|
+
- **Kill switch**: `VETCH_DISABLED=true` completely disables Vetch
|
|
33
|
+
- **Privacy-first**: Zero access to prompt/completion content
|
|
34
|
+
|
|
35
|
+
### Alpha Limitations
|
|
36
|
+
- Timezone-based region inference has ~30% accuracy - use `VETCH_REGION` for production
|
|
37
|
+
- Experimental modules (`calibrate`, `storage`, `ci`) marked with `FutureWarning`
|
|
38
|
+
- Integration tests require live API credentials
|
|
39
|
+
- Energy estimates are Tier 3 (±10x uncertainty) for most models
|
|
40
|
+
|
|
41
|
+
### Environment Variables
|
|
42
|
+
| Variable | Purpose | Default |
|
|
43
|
+
|----------|---------|---------|
|
|
44
|
+
| `VETCH_REGION` | Grid region for carbon calculation | (inferred) |
|
|
45
|
+
| `VETCH_OUTPUT` | Output target: `stderr`, `none`, or file path | `stderr` |
|
|
46
|
+
| `VETCH_DEFAULT_PUE` | Power Usage Effectiveness multiplier | `1.1` |
|
|
47
|
+
| `VETCH_CACHE_MODE` | Set to `memory-only` for serverless | (file-based) |
|
|
48
|
+
| `VETCH_DISABLED` | Set to `true` to disable all tracking | `false` |
|
|
49
|
+
| `ELECTRICITY_MAPS_API_KEY` | API key for live grid data | (optional) |
|
|
50
|
+
|
|
51
|
+
### Dependencies
|
|
52
|
+
- **Runtime**: Zero dependencies (stdlib only)
|
|
53
|
+
- **Optional**: `openai>=1.0,<2.0`, `google-cloud-aiplatform>=1.0`, `tiktoken>=0.5.0`
|
|
54
|
+
- **Test**: `pytest>=7.0`, `hypothesis>=6.0`
|
vetch-0.1.0/LICENSE
ADDED
|
@@ -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 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 any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Prismatic Labs
|
|
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.
|
vetch-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Vetch SDK
|
|
2
|
+
Copyright 2026 Prismatic Labs
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Prismatic Labs.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
|
|
18
|
+
--------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
Third-Party Data Sources:
|
|
21
|
+
|
|
22
|
+
Electricity Maps (https://electricitymaps.com/)
|
|
23
|
+
- Real-time carbon intensity data for grid regions
|
|
24
|
+
- Used under their API terms of service
|
|
25
|
+
|
|
26
|
+
Model energy estimates derived from:
|
|
27
|
+
- Published academic research on LLM energy consumption
|
|
28
|
+
- Parameter count extrapolation using FLOP-to-Wh conversion
|
|
29
|
+
|
|
30
|
+
See src/vetch/METHODOLOGY.md for full methodology documentation.
|
|
31
|
+
See src/vetch/registry/PROVENANCE.md for data source citations.
|
vetch-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vetch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Energy-aware observability for LLM inference
|
|
5
|
+
Project-URL: Homepage, https://github.com/prismatic-labs/vetch
|
|
6
|
+
Project-URL: Documentation, https://github.com/prismatic-labs/vetch#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/prismatic-labs/vetch
|
|
8
|
+
Project-URL: Issues, https://github.com/prismatic-labs/vetch/issues
|
|
9
|
+
Author: Prismatic Labs
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: carbon,energy,llm,observability,openai,vertexai
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Provides-Extra: calibrate
|
|
27
|
+
Requires-Dist: nvidia-ml-py3; extra == 'calibrate'
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build; extra == 'dev'
|
|
30
|
+
Requires-Dist: mypy>=1.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: twine; extra == 'dev'
|
|
33
|
+
Provides-Extra: openai
|
|
34
|
+
Requires-Dist: openai<2.0,>=1.0; extra == 'openai'
|
|
35
|
+
Provides-Extra: test
|
|
36
|
+
Requires-Dist: hypothesis>=6.0; extra == 'test'
|
|
37
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'test'
|
|
38
|
+
Requires-Dist: pytest>=7.0; extra == 'test'
|
|
39
|
+
Requires-Dist: tiktoken>=0.5.0; extra == 'test'
|
|
40
|
+
Provides-Extra: tiktoken
|
|
41
|
+
Requires-Dist: tiktoken>=0.5.0; extra == 'tiktoken'
|
|
42
|
+
Provides-Extra: vertexai
|
|
43
|
+
Requires-Dist: google-cloud-aiplatform>=1.0; extra == 'vertexai'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# Vetch SDK
|
|
47
|
+
|
|
48
|
+
Energy-aware observability for LLM inference.
|
|
49
|
+
|
|
50
|
+
Vetch is a Python SDK that wraps LLM API calls to log energy consumption, cost, and carbon per inference using live grid data. It never reads prompt or completion content—only metadata from the response usage.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **Fail-Open**: LLM calls always proceed even if Vetch fails.
|
|
55
|
+
- **Privacy-First**: No prompt or completion data is ever read or buffered.
|
|
56
|
+
- **Multi-tier Caching**: Memory and file-based caching for grid intensity data.
|
|
57
|
+
- **Observability-Transparent**: Works seamlessly with Datadog, OpenTelemetry, and Sentry.
|
|
58
|
+
- **Low Overhead**: Under 5ms overhead for sync calls; zero TTFT latency for streaming.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install vetch
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from vetch import wrap
|
|
70
|
+
from openai import OpenAI
|
|
71
|
+
|
|
72
|
+
client = OpenAI()
|
|
73
|
+
|
|
74
|
+
with wrap(region="us-east-1", tags={"team": "ml", "env": "prod"}) as ctx:
|
|
75
|
+
response = client.chat.completions.create(
|
|
76
|
+
model="gpt-4o",
|
|
77
|
+
messages=[{"role": "user", "content": "Hello world"}]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Access inference metadata
|
|
81
|
+
print(f"Energy: {ctx.event['estimated_energy_wh']} Wh")
|
|
82
|
+
print(f"Carbon: {ctx.event['estimated_carbon_g']} gCO2e")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## CLI Usage
|
|
86
|
+
|
|
87
|
+
Estimate energy/carbon for a model without running code:
|
|
88
|
+
```bash
|
|
89
|
+
vetch estimate --model gpt-4o --input-tokens 1000 --output-tokens 500 --region us-east-1
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Compare multiple models:
|
|
93
|
+
```bash
|
|
94
|
+
vetch compare --models gpt-4o,claude-3-opus,gemini-1.5-pro --tokens 1000
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Analyze your token usage patterns:
|
|
98
|
+
```bash
|
|
99
|
+
vetch audit
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Check your environment:
|
|
103
|
+
```bash
|
|
104
|
+
vetch check
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Token Waste Audit
|
|
108
|
+
|
|
109
|
+
Vetch tracks token usage patterns across your session and provides actionable recommendations:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from vetch import wrap, get_session_stats, generate_advisories
|
|
113
|
+
|
|
114
|
+
# Make multiple LLM calls
|
|
115
|
+
for _ in range(10):
|
|
116
|
+
with wrap() as ctx:
|
|
117
|
+
response = client.chat.completions.create(...)
|
|
118
|
+
|
|
119
|
+
# Analyze patterns
|
|
120
|
+
stats = get_session_stats()
|
|
121
|
+
advisories = generate_advisories(stats)
|
|
122
|
+
|
|
123
|
+
for a in advisories:
|
|
124
|
+
print(f"[{a.level.value}] {a.title}")
|
|
125
|
+
print(f" {a.description}")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**What it detects:**
|
|
129
|
+
- **Static system prompts**: Repeated input token counts suggest cacheable prompts
|
|
130
|
+
- **High input:output ratios**: Large inputs producing small outputs
|
|
131
|
+
- **Expensive model usage**: Opportunities to use smaller, cheaper models
|
|
132
|
+
|
|
133
|
+
## GPU Calibration (Local Inference)
|
|
134
|
+
|
|
135
|
+
For local inference (Ollama, vLLM, llama.cpp), calibrate energy measurements using actual GPU power draw:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from vetch.calibrate import calibrate_model, format_calibration_result
|
|
139
|
+
|
|
140
|
+
def my_inference():
|
|
141
|
+
# Run your inference workload
|
|
142
|
+
# Return (input_tokens, output_tokens)
|
|
143
|
+
response = ollama.generate(model="llama3.1:8b", prompt="Hello world")
|
|
144
|
+
return 100, 50 # Your actual token counts
|
|
145
|
+
|
|
146
|
+
result = calibrate_model("ollama", "llama3.1:8b", workload=my_inference)
|
|
147
|
+
print(format_calibration_result(result))
|
|
148
|
+
|
|
149
|
+
# Use calibrated values for accurate tracking
|
|
150
|
+
with wrap(energy_override=result.to_override()) as ctx:
|
|
151
|
+
response = ollama.generate(...)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Check calibration status:
|
|
155
|
+
```bash
|
|
156
|
+
vetch calibrate --status
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Requirements:** NVIDIA GPU with `pynvml` (`pip install nvidia-ml-py3`)
|
|
160
|
+
|
|
161
|
+
## Historical Analysis & Reporting
|
|
162
|
+
|
|
163
|
+
Vetch can persist events to SQLite for historical FinOps analysis:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from vetch import configure_storage, query_usage, wrap
|
|
167
|
+
from datetime import datetime, timedelta
|
|
168
|
+
|
|
169
|
+
# Enable persistent storage
|
|
170
|
+
configure_storage() # Uses ~/.vetch/usage.db
|
|
171
|
+
|
|
172
|
+
# Your LLM calls are now tracked
|
|
173
|
+
with wrap(tags={"team": "ml", "feature": "chat"}) as ctx:
|
|
174
|
+
response = client.chat.completions.create(...)
|
|
175
|
+
|
|
176
|
+
# Query historical usage
|
|
177
|
+
summary = query_usage(
|
|
178
|
+
start=datetime.now() - timedelta(days=7),
|
|
179
|
+
tags={"team": "ml"}
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
print(f"Total cost: ${summary.total_cost_usd:.2f}")
|
|
183
|
+
print(f"Total energy: {summary.total_energy_wh:.2f} Wh")
|
|
184
|
+
print(f"Requests: {summary.total_requests}")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Generate reports from CLI:
|
|
188
|
+
```bash
|
|
189
|
+
# Weekly report
|
|
190
|
+
vetch report --days 7
|
|
191
|
+
|
|
192
|
+
# Filter by team
|
|
193
|
+
vetch report --tags team=ml
|
|
194
|
+
|
|
195
|
+
# Show top consumers
|
|
196
|
+
vetch report --top --top-by team --days 30
|
|
197
|
+
|
|
198
|
+
# JSON output for dashboards
|
|
199
|
+
vetch report --format json
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Energy Tiers
|
|
203
|
+
|
|
204
|
+
Vetch uses a tiered system for energy estimate confidence:
|
|
205
|
+
|
|
206
|
+
| Tier | Name | Uncertainty | Source |
|
|
207
|
+
|------|------|-------------|--------|
|
|
208
|
+
| 0 | **Measured** | ±10-20% | Direct GPU measurement (pynvml) |
|
|
209
|
+
| 1 | **Vendor-Published** | ±20-50% | Official provider data |
|
|
210
|
+
| 2 | **Validated** | ±50-100% | Crowdsourced aggregates |
|
|
211
|
+
| 3 | **Estimated** | ±10x | Parameter-based calculation |
|
|
212
|
+
|
|
213
|
+
Run `vetch methodology` to see full methodology documentation.
|
|
214
|
+
|
|
215
|
+
## Environment Variables
|
|
216
|
+
|
|
217
|
+
| Variable | Description |
|
|
218
|
+
|----------|-------------|
|
|
219
|
+
| `VETCH_DISABLED` | Set to `true` to completely disable Vetch (emergency kill switch) |
|
|
220
|
+
| `VETCH_REGION` | Default grid region (e.g., `us-east-1`, `eu-west-1`) |
|
|
221
|
+
| `VETCH_OUTPUT` | Output target: `stderr` (default), `none`, or file path |
|
|
222
|
+
| `ELECTRICITY_MAPS_API_KEY` | API key for live grid carbon intensity data |
|
|
223
|
+
| `VETCH_CACHE_MODE` | Set to `memory-only` for serverless/Lambda environments |
|
|
224
|
+
|
|
225
|
+
## Alpha Limitations
|
|
226
|
+
|
|
227
|
+
This is an alpha release. Please be aware of:
|
|
228
|
+
|
|
229
|
+
1. **Energy estimates are uncertain**: Most models use Tier 3 estimates (±10x uncertainty). See `vetch methodology` for details.
|
|
230
|
+
|
|
231
|
+
2. **Region inference is approximate**: Without explicit `VETCH_REGION`, timezone-based inference is ~30% accurate. Set the region explicitly for accurate carbon calculations.
|
|
232
|
+
|
|
233
|
+
3. **Experimental modules**: `vetch.calibrate`, `vetch.storage`, and `vetch.ci` emit `FutureWarning` and may change in future versions.
|
|
234
|
+
|
|
235
|
+
4. **Provider support**: Currently supports OpenAI, Anthropic, and Vertex AI. Other providers coming soon.
|
|
236
|
+
|
|
237
|
+
## Troubleshooting
|
|
238
|
+
|
|
239
|
+
**Vetch is blocking my LLM calls:**
|
|
240
|
+
```bash
|
|
241
|
+
export VETCH_DISABLED=true # Emergency kill switch
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Too much output:**
|
|
245
|
+
```bash
|
|
246
|
+
export VETCH_OUTPUT=none # Silence all output
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Need to debug:**
|
|
250
|
+
```python
|
|
251
|
+
import logging
|
|
252
|
+
logging.getLogger("vetch").setLevel(logging.DEBUG)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
Apache License 2.0. See `LICENSE` and `NOTICE` for details.
|