Files
karuo-ai/01_卡资(金)/金仓_存储备份/脚本/codex_responses_404_fix.sh
2026-07-19 00:21:46 +08:00

80 lines
2.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Codex App 404 on chatgpt.com/backend-api/codex/responses 一键修复
# 根因gpt-5.5 后端未开通 / gpt-5.4-mini 不支持 priority 档位 / 长会话重连失败
set -euo pipefail
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
CFG="$CODEX_HOME/config.toml"
STAMP="$(date +%Y%m%d%H%M%S)"
TARGET_MODEL="${1:-gpt-5.4}"
echo "== Codex 404 修复 =="
echo "目标模型: $TARGET_MODEL"
[[ -f "$CFG" ]] && cp "$CFG" "${CFG}.bak.${STAMP}"
python3 - "$CFG" "$TARGET_MODEL" <<'PY'
import re, sys
from pathlib import Path
cfg, model = Path(sys.argv[1]), sys.argv[2]
text = cfg.read_text(encoding="utf-8") if cfg.exists() else ""
# 去掉第三方 model_provider走 ChatGPT 官方登录)
out, skip = [], False
for line in text.splitlines():
s = line.strip()
if s.startswith("model_provider = "):
continue
if s.startswith("[model_providers."):
skip = True
continue
if skip:
if s.startswith("[") and not s.startswith("[model_providers."):
skip = False
out.append(line)
continue
out.append(line)
joined = "\n".join(out)
if joined and not joined.endswith("\n"):
joined += "\n"
# 固定稳定模型
if re.search(r"^model\s*=", joined, re.M):
joined = re.sub(r'^model\s*=.*$', f'model = "{model}"', joined, count=1, flags=re.M)
else:
joined = f'model = "{model}"\n' + joined
# gpt-5.4 支持 prioritymini 不支持
if model == "gpt-5.4-mini":
joined = re.sub(r"^service_tier\s*=.*\n", "", joined, flags=re.M)
elif not re.search(r"^service_tier\s*=", joined, re.M):
joined = joined.replace(
f'model = "{model}"\n',
f'model = "{model}"\nmodel_reasoning_effort = "medium"\nservice_tier = "priority"\n',
1,
)
cfg.write_text(joined, encoding="utf-8")
print(f"config.toml -> model={model}")
PY
# 刷新模型缓存(下次启动重拉)
if [[ -f "$CODEX_HOME/models_cache.json" ]]; then
cp "$CODEX_HOME/models_cache.json" "$CODEX_HOME/models_cache.json.bak.${STAMP}"
rm -f "$CODEX_HOME/models_cache.json"
echo "已清除 models_cache.jsonCodex 重启后自动重建)"
fi
# 结束卡住的 codex exec
pkill -f "codex exec" 2>/dev/null || true
echo ""
echo "请在 Codex App 内手动确认:"
echo " 1. 模型选择器改为 GPT-5.4(勿用 GPT-5.5"
echo " 2. 关闭 Fast/Priority 若仍 404可改 config 去掉 service_tier"
echo " 3. 「房产的市场调研」发「继续」;仍失败则新建对话续跑"
echo ""
echo "修复完成。建议 Cmd+Q 退出 Codex 后重新打开。"