ebaml 0.2.4__tar.gz → 0.2.5__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.
- {ebaml-0.2.4 → ebaml-0.2.5}/PKG-INFO +3 -3
- {ebaml-0.2.4 → ebaml-0.2.5}/README.md +2 -2
- {ebaml-0.2.4 → ebaml-0.2.5}/pyproject.toml +1 -1
- {ebaml-0.2.4 → ebaml-0.2.5}/pyproject.toml.orig +1 -1
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/graphs/ebm_graph.py +4 -3
- ebaml-0.2.5/src/ebaml/graphs/token_budget.py +84 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/descriptors.py +4 -3
- {ebaml-0.2.4 → ebaml-0.2.5}/LICENSE +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/.baml-generator-output-root +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/.baml-generator-output.json +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/.gitignore +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_baml_sources.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_function_registry.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_inlinedbaml.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_invocation_types.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_invocation_types.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/_typemap.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/clients/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/clients/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/content/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/content/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/errors/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/errors/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/events/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/events/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/mcp/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/mcp/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/stream/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/stream/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/tools/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/tools/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/wire/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/ai/wire/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/crypto/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/crypto/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/csv/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/csv/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/env/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/env/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/errors/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/errors/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/fs/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/fs/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/future/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/future/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/glob/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/glob/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/hash/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/hash/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/host/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/host/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/http/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/http/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/io/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/io/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/iter/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/iter/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/json/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/json/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/media/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/media/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/net/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/net/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/ops/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/ops/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/panics/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/panics/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/random/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/random/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/regex/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/regex/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/sap/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/sap/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/spawn/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/spawn/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/sys/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/sys/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/time/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/time/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/toml/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/toml/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/ws/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/ws/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/yaml/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/baml/yaml/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/experimental/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/experimental/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/py.typed +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/class_/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/class_/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/enum/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/enum/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/errors/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/errors/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/function/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/function/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/interface/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/reflect/interface/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/anthropic/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/anthropic/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/anthropic/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/anthropic/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/assert_/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/assert_/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/aws/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/aws/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/aws/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/aws/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/claude_code/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/claude_code/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/claude_code/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/claude_code/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/google/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/google/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/google/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/google/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/internal/decisions/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/openai/internal/decisions/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/testing/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/testing/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/trace/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/trace/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/typesafeai/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/typesafeai/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/typesafeai/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/typesafeai/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/vercel/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/vercel/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/vercel/internal/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/baml_sdk/vendor/vercel/internal/__init__.pyi +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/benchmark.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/core/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/core/custom_types.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/core/exceptions.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/graphs/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/graphs/graph_text.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/graphs/model_kinds.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/graphs/terms.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/options.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/provider_errors.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/retry.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/llm/sdk_setup.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/local/__init__.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/local/fact_text.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/local/facts.py +0 -0
- {ebaml-0.2.4 → ebaml-0.2.5}/src/ebaml/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ebaml
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: BAML for Explainable Boosting Machines: talk to your EBM.
|
|
5
5
|
Keywords: baml,llm,explainable-ai,explainable-boosting-machine,interpretml
|
|
6
6
|
Author: Johnny Godoy
|
|
@@ -281,8 +281,8 @@ them too.
|
|
|
281
281
|
- **Token budget:** there is no tokenizer before a call, so the check uses a rough estimate (about 3 characters per
|
|
282
282
|
token). Going a little over `max_tokens` only warns. Going more than `overbudget_percent` (default 50) over makes
|
|
283
283
|
`to_text` simplify the graph, or raise if it cannot. The provider's own error is the real limit. The functions in
|
|
284
|
-
`ebaml.llm.descriptors` pass the
|
|
285
|
-
`check_budget`, for example `
|
|
284
|
+
`ebaml.llm.descriptors` pass the check. A direct call of `EBMGraph.to_text` checks nothing, unless you pass
|
|
285
|
+
`check_budget`, for example `ebaml.graphs.token_budget.check_token_budget`. That check needs no LLM and no key.
|
|
286
286
|
|
|
287
287
|
<!-- --8<-- [end:behaviour] -->
|
|
288
288
|
## Notebook
|
|
@@ -253,8 +253,8 @@ them too.
|
|
|
253
253
|
- **Token budget:** there is no tokenizer before a call, so the check uses a rough estimate (about 3 characters per
|
|
254
254
|
token). Going a little over `max_tokens` only warns. Going more than `overbudget_percent` (default 50) over makes
|
|
255
255
|
`to_text` simplify the graph, or raise if it cannot. The provider's own error is the real limit. The functions in
|
|
256
|
-
`ebaml.llm.descriptors` pass the
|
|
257
|
-
`check_budget`, for example `
|
|
256
|
+
`ebaml.llm.descriptors` pass the check. A direct call of `EBMGraph.to_text` checks nothing, unless you pass
|
|
257
|
+
`check_budget`, for example `ebaml.graphs.token_budget.check_token_budget`. That check needs no LLM and no key.
|
|
258
258
|
|
|
259
259
|
<!-- --8<-- [end:behaviour] -->
|
|
260
260
|
## Notebook
|
|
@@ -79,7 +79,7 @@ class TokenBudget(Protocol):
|
|
|
79
79
|
class BudgetCheck(Protocol):
|
|
80
80
|
"""A function that estimates the tokens of a text and compares them with a budget.
|
|
81
81
|
|
|
82
|
-
``
|
|
82
|
+
``ebaml.graphs.token_budget.check_token_budget`` is such a function.
|
|
83
83
|
"""
|
|
84
84
|
|
|
85
85
|
def __call__(self, *, text: str, max_tokens: int, overbudget_percent: int) -> TokenBudget:
|
|
@@ -639,8 +639,9 @@ class EBMGraph:
|
|
|
639
639
|
The LLM provider's own error remains the real limit.
|
|
640
640
|
check_budget: BudgetCheck, optional
|
|
641
641
|
Estimates the tokens of a text and compares them with ``max_tokens`` and ``overbudget_percent``, for
|
|
642
|
-
example ``
|
|
643
|
-
once, at the first simplification level, and ``max_tokens`` and ``overbudget_percent``
|
|
642
|
+
example ``ebaml.graphs.token_budget.check_token_budget``. If not provided, the text is not checked: the
|
|
643
|
+
function writes it once, at the first simplification level, and ``max_tokens`` and ``overbudget_percent``
|
|
644
|
+
have no effect.
|
|
644
645
|
|
|
645
646
|
Returns
|
|
646
647
|
-------
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""The token budget of a text: an estimate of its tokens, compared with a limit.
|
|
2
|
+
|
|
3
|
+
No tokenizer runs before the LLM call, so the estimate is about 3 characters per token. The provider error stays the
|
|
4
|
+
real limit. ``estimate_tokens`` and ``check_token_budget`` in ``baml_src/talk_to_ebm.baml`` use the same rule, and a
|
|
5
|
+
test keeps the two sides equal. This module needs no ``baml_sdk``, so code that calls no LLM can check a budget too.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Literal
|
|
9
|
+
|
|
10
|
+
import attrs
|
|
11
|
+
|
|
12
|
+
_CHARS_PER_TOKEN = 3
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@attrs.frozen
|
|
16
|
+
class BudgetStatus:
|
|
17
|
+
"""The estimated tokens of a text, and how they compare with the budget.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
estimated_tokens: int
|
|
22
|
+
The estimated number of tokens of the text.
|
|
23
|
+
status: Literal["ok", "warn", "over"]
|
|
24
|
+
``"ok"`` within ``max_tokens``, ``"warn"`` above it, and ``"over"`` beyond ``overbudget_percent`` above it.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
estimated_tokens: int
|
|
29
|
+
status: Literal["ok", "warn", "over"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def estimate_tokens(text: str) -> int:
|
|
33
|
+
"""Estimate the tokens of a text at 3 characters per token, rounded up.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
text: str
|
|
38
|
+
The text.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
int
|
|
43
|
+
The estimated number of tokens.
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
>>> estimate_tokens("abcd")
|
|
48
|
+
2
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
return -(-len(text) // _CHARS_PER_TOKEN)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def check_token_budget(*, text: str, max_tokens: int, overbudget_percent: int) -> BudgetStatus:
|
|
55
|
+
"""Compare the estimated tokens of a text with a budget and with the tolerance above it.
|
|
56
|
+
|
|
57
|
+
The function is a ``BudgetCheck``, so ``EBMGraph.to_text`` accepts it as ``check_budget``.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
text: str
|
|
62
|
+
The text.
|
|
63
|
+
max_tokens: int
|
|
64
|
+
The budget.
|
|
65
|
+
overbudget_percent: int
|
|
66
|
+
How far above ``max_tokens``, in percent, the estimate may go before the status is ``"over"``.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
BudgetStatus
|
|
71
|
+
The estimate and the status.
|
|
72
|
+
|
|
73
|
+
Examples
|
|
74
|
+
--------
|
|
75
|
+
>>> check_token_budget(text="a" * 300, max_tokens=80, overbudget_percent=50)
|
|
76
|
+
BudgetStatus(estimated_tokens=100, status='warn')
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
estimated = estimate_tokens(text)
|
|
80
|
+
if estimated > max_tokens * (100 + overbudget_percent) // 100:
|
|
81
|
+
return BudgetStatus(estimated, "over")
|
|
82
|
+
if estimated > max_tokens:
|
|
83
|
+
return BudgetStatus(estimated, "warn")
|
|
84
|
+
return BudgetStatus(estimated, "ok")
|
|
@@ -17,6 +17,7 @@ from ebaml.core.custom_types import Audience, ExplainableBoostingModel, FeatureV
|
|
|
17
17
|
from ebaml.core.exceptions import InvalidOptionError
|
|
18
18
|
from ebaml.graphs.ebm_graph import EBMGraph
|
|
19
19
|
from ebaml.graphs.terms import main_effect_features, main_term
|
|
20
|
+
from ebaml.graphs.token_budget import check_token_budget, estimate_tokens
|
|
20
21
|
from ebaml.llm.options import GraphOptions, ModelOptions, PromptOptions
|
|
21
22
|
from ebaml.llm.provider_errors import provider_errors
|
|
22
23
|
from ebaml.llm.retry import call_with_shrinking_graph
|
|
@@ -152,7 +153,7 @@ def _model_spec(model: ModelOptions | str | None) -> baml_sdk.ModelSpec | None:
|
|
|
152
153
|
|
|
153
154
|
|
|
154
155
|
def _graph_text(ebm: ExplainableBoostingModel, feature_index: int, options: GraphOptions) -> str:
|
|
155
|
-
"""Convert an EBM graph to text, with the
|
|
156
|
+
"""Convert an EBM graph to text, with the token budget check.
|
|
156
157
|
|
|
157
158
|
Parameters
|
|
158
159
|
----------
|
|
@@ -185,7 +186,7 @@ def _graph_text(ebm: ExplainableBoostingModel, feature_index: int, options: Grap
|
|
|
185
186
|
confidence_level=options.confidence_level,
|
|
186
187
|
max_tokens=options.max_tokens,
|
|
187
188
|
overbudget_percent=options.overbudget_percent,
|
|
188
|
-
check_budget=
|
|
189
|
+
check_budget=check_token_budget,
|
|
189
190
|
)
|
|
190
191
|
|
|
191
192
|
|
|
@@ -293,7 +294,7 @@ def _describe_graph_counted( # ruff: ignore[too-many-arguments, too-many-positi
|
|
|
293
294
|
graph,
|
|
294
295
|
error_type=BamlError,
|
|
295
296
|
is_truncated=_is_truncated,
|
|
296
|
-
estimate_tokens=
|
|
297
|
+
estimate_tokens=estimate_tokens,
|
|
297
298
|
rebuild=lambda budget: _graph_text(
|
|
298
299
|
ebm,
|
|
299
300
|
feature_index,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|