module PromptBudgetCheck
Overview
Estimate the token size of prompts from a CSV and compare each with a budget. The estimate is characters divided by a rough ratio that you set. Real tokenizers differ, so treat every number as an estimate.
Defined in:
prompt_budget_check.crConstant Summary
-
DEFAULT_CHARS_PER_TOKEN =
4.0 -
DEFAULT_LIMIT =
1000 -
DEFAULT_WARN_AT =
80.0 -
REQUIRED =
["prompt_id", "text"] of ::String -
USAGE =
"usage: prompt-budget-check prompts.csv [--chars-per-token 4] [--limit 1000] [--warn-at 80]\nCSV columns: prompt_id, text. The ratio, limit and warn share are set by you; the token count is an estimate. More: https://www.onegtmlab.dev/glossary/prompt-engineering" -
VERSION =
"1.0.0"
Class Method Summary
-
.analyze(text : String, settings : Settings = Settings.new) : Report
Parse the CSV text and build the report.
-
.cli(args : Array(String), stdout : IO, stderr : IO) : Int32
Command line entry.
-
.estimate_tokens(characters : Int32, chars_per_token : Float64) : Int64
ceil(characters / chars_per_token), guarding against float noise.
- .num(v : Float64) : String
-
.parse_csv(text : String) : Array(Array(String))
Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark.
- .render(report : Report) : String
- .status_for(tokens : Int64, settings : Settings) : String
Class Method Detail
Parse the CSV text and build the report. Raises ArgumentError on bad input. Row numbers count the header as row 1.
Command line entry. Returns the exit code: 0 ok, 1 bad input or file, 2 usage.
ceil(characters / chars_per_token), guarding against float noise.
Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark. Returns rows of raw cell strings.