一个用于测试 OpenAI 兼容接口模型上下文窗口大小的 Python 脚本。
脚本文件:probe_context_window.py
- 先按常见上下文档位探测(2K / 4K / 8K / 16K / ...)
- 自动做二分逼近,估算可用上下文上限
- 输出建议的安全
prompt budget(方便你做会话压缩) - 支持交互式输入:
Base URL -> API Key -> Model
- Python 3.9+
- 可访问目标 OpenAI 兼容 API
python3 probe_context_window.py按提示输入:
- Base URL(例如
https://your-host:port) - API Key
- Model 名称
python3 probe_context_window.py \
--no-interactive \
--base-url https://your-host:port \
--api-key 'sk-xxx' \
--model your-model-name \
--json--max-output-tokens 1:降低探测成本--safe-margin 256:给生产请求留安全余量--binary-steps 20:二分最多迭代次数--checkpoints 2048,4096,8192,16384:自定义预探测档位
推荐:context-window-prober
备选:
llm-context-probermodel-context-tester