feat: 新增命令行 API 客户端,修复发布配置改写的反斜杠 bug

scripts/api_client.py:完整走一遍 upload -> 轮询 i2t -> 打印识别文本与抽取字段。
只用标准库(不依赖 requests),可直接拷到别的机器上跑;支持多图、
--min-confidence(服务端过滤)、--json、--health。参数校验放在探活之前,
参数写错时不会因为连不上服务而报出误导性错误。

scripts/prepare_release_config.py:re.sub 的**替换串**里反斜杠是转义序列,
写 Windows 路径(model_dir=D:\...)必然抛 "bad escape \c"。改用函数式替换。

.gitignore 补 *.zip:打包产物压出来有数 GB,别误提交。

README:补命令行客户端用法、发布包共用项目 models 目录的做法。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
zimoyin
2026-10-14 11:59:39 +08:00
parent 5ab4bef80e
commit 0a299dec18
5 changed files with 278 additions and 13 deletions
+3 -1
View File
@@ -17,7 +17,9 @@ from pathlib import Path
def apply_override(text: str, key: str, value: str) -> str:
pattern = re.compile(rf"^{re.escape(key)}:.*$", re.MULTILINE)
if pattern.search(text):
return pattern.sub(f"{key}: {value}", text, count=1)
# 必须用函数式替换:re.sub 会把替换串里的反斜杠当转义序列,
# Windows 路径(D:\code\...)会直接抛 "bad escape \c"。
return pattern.sub(lambda _match: f"{key}: {value}", text, count=1)
# 源文件里没有这一项(例如被注释掉了),追加到末尾。
return text.rstrip("\n") + f"\n{key}: {value}\n"