-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage.py
More file actions
70 lines (59 loc) · 1.94 KB
/
Copy pathusage.py
File metadata and controls
70 lines (59 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""CLI utility to check Voyage AI token usage."""
import argparse
import sys
from pathlib import Path
from token_tracker import get_tracker
def main():
parser = argparse.ArgumentParser(description="Check Voyage AI token usage")
parser.add_argument(
"--reset",
action="store_true",
help="Reset all usage counters (use with caution!)"
)
parser.add_argument(
"--json",
action="store_true",
help="Output as JSON"
)
parser.add_argument(
"--embedding-limit",
type=int,
default=200_000_000,
help="Embedding token limit (default: 200M)"
)
parser.add_argument(
"--rerank-limit",
type=int,
default=200_000_000,
help="Rerank token limit (default: 200M)"
)
args = parser.parse_args()
tracker = get_tracker(
storage_path=Path.home() / "Projects/shared-data/usage/voyage_usage.json",
embedding_limit=args.embedding_limit,
rerank_limit=args.rerank_limit
)
if args.reset:
confirm = input("⚠️ Are you sure you want to reset all usage counters? (yes/no): ")
if confirm.lower() == "yes":
tracker.reset_usage(confirm=True)
print("✅ Usage counters reset.")
else:
print("❌ Reset cancelled.")
return
if args.json:
import json
print(json.dumps(tracker.get_status(), indent=2))
else:
tracker.print_status()
# Print warnings if approaching limits
status = tracker.get_status()
if status['embedding']['percent_used'] > 90:
print("⚠️ WARNING: Approaching embedding token limit!")
if status['rerank']['percent_used'] > 90:
print("⚠️ WARNING: Approaching rerank token limit!")
if status['embedding']['exhausted'] or status['rerank']['exhausted']:
sys.exit(1)
if __name__ == "__main__":
main()