Spaces:
Runtime error
Runtime error
Delete chip-space/chip/cli.py
Browse files- chip-space/chip/cli.py +0 -54
chip-space/chip/cli.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
chip.cli — 命令行入口
|
| 3 |
-
|
| 4 |
-
安装后:
|
| 5 |
-
chip "请你帮我总结一下这段文字"
|
| 6 |
-
echo "..." | chip
|
| 7 |
-
chip --target qwen2.5 --layers L1 L2 --diff "..."
|
| 8 |
-
"""
|
| 9 |
-
from __future__ import annotations
|
| 10 |
-
import argparse, sys
|
| 11 |
-
|
| 12 |
-
from chip.compressor import Compressor
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def main():
|
| 16 |
-
ap = argparse.ArgumentParser(prog="chip",
|
| 17 |
-
description="CHIP — Chinese High-density Instruction Protocol compressor")
|
| 18 |
-
ap.add_argument("text", nargs="?",
|
| 19 |
-
help="prompt text (or read from stdin if omitted)")
|
| 20 |
-
ap.add_argument("--target", default="qwen2.5",
|
| 21 |
-
choices=["qwen2.5", "cl100k", "o200k", "deepseek_v3", "glm4"],
|
| 22 |
-
help="target tokenizer (decides protocol track)")
|
| 23 |
-
ap.add_argument("--layers", nargs="+", default=["L1", "L2", "L4"],
|
| 24 |
-
choices=["L1", "L2", "L3", "L4"],
|
| 25 |
-
help="L1=词法 L2=句法 L3=成语(需国产模型) L4=协议归一化")
|
| 26 |
-
ap.add_argument("--diff", action="store_true",
|
| 27 |
-
help="show original / compressed / rules side-by-side")
|
| 28 |
-
ap.add_argument("--rules", default=None,
|
| 29 |
-
help="custom rules.yaml path")
|
| 30 |
-
args = ap.parse_args()
|
| 31 |
-
|
| 32 |
-
if args.text:
|
| 33 |
-
text = args.text
|
| 34 |
-
else:
|
| 35 |
-
text = sys.stdin.read()
|
| 36 |
-
if not text.strip():
|
| 37 |
-
ap.print_help()
|
| 38 |
-
sys.exit(1)
|
| 39 |
-
|
| 40 |
-
kwargs = {}
|
| 41 |
-
if args.rules:
|
| 42 |
-
kwargs["rules_path"] = args.rules
|
| 43 |
-
compressor = Compressor(target=args.target, layers=args.layers, **kwargs)
|
| 44 |
-
result = compressor.compress(text)
|
| 45 |
-
|
| 46 |
-
if args.diff:
|
| 47 |
-
print(result.diff())
|
| 48 |
-
print(f"\n字符压缩率: {result.char_ratio:.2%} ({len(result.original)} → {len(result.compressed)})")
|
| 49 |
-
else:
|
| 50 |
-
print(result.compressed)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
if __name__ == "__main__":
|
| 54 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|