Skip to content

Commit d907784

Browse files
committed
fix: include API key in rotation status identity
1 parent e60d46a commit d907784

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

desktop_qt_ui/ui/main_page/env_management.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,14 @@ def _build_test_status_endpoint(
758758
_base_field, slot_index = _split_slot_field(field)
759759
base_url = (api_base or _get_api_address_example(test_target)).rstrip("/")
760760
model_name = (model or "").strip()
761-
status_key = make_endpoint_status_key(feature, provider, slot_index, base_url, model_name)
761+
status_key = make_endpoint_status_key(
762+
feature,
763+
provider,
764+
slot_index,
765+
base_url,
766+
model_name,
767+
api_key=api_key,
768+
)
762769
return APIEndpoint(
763770
feature=feature,
764771
provider=provider,

doc/CHANGELOG_v3.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
### 修复异常文本误判导致 API 密钥被误拉黑的问题
1616
- 修复了当 AI 渲染失败抛出通用 `RuntimeError` 异常时,其文本描述中包含 "HTTP 404" 的排查细节信息会被轮询系统(`api_key_rotation.py`)的正则表达式抓取,误判定为发生了真实的 HTTP 404 永久网络错误,从而导致该 API Key 被错误的拉黑屏蔽。现在系统在提取状态码时会自动过滤并跳过 `RuntimeError``ValueError` 等内置异常类型的正则匹配,避免发生误拉黑。
17+
- API 通道状态现在会区分不同 API Key,更换 Key 后不会继续继承旧 Key 的本地冷却或不可用状态。
1718

1819
### 修复渲染报错被错误归类为“模型不支持多模态”的问题
1920
- 修复了当 AI 渲染发生其他错误(例如 API 404 响应细节描述)而抛出异常时,由于异常消息中带有 `"vision"``"image_url"` 关键字,导致客户端 UI 界面(`app_logic.py`)将其误判并显示为“模型不支持多模态输入”引导信息的 Bug。现已增加豁免判定,排除由渲染器(Renderer)抛出的此类异常误匹配。

manga_translator/api_key_rotation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import hashlib
45
import re
56
import threading
67
import time
@@ -134,8 +135,15 @@ def make_endpoint_status_key(
134135
slot: int,
135136
base_url: str,
136137
model_name: str,
138+
api_key: str | None = None,
137139
) -> str:
138-
return f"{feature}:{provider}:{slot}:{base_url}:{model_name}"
140+
api_key_text = str(api_key or "").strip()
141+
api_key_fingerprint = (
142+
hashlib.sha256(api_key_text.encode("utf-8")).hexdigest()[:12]
143+
if api_key_text
144+
else "no-key"
145+
)
146+
return f"{feature}:{provider}:{slot}:{base_url}:{model_name}:{api_key_fingerprint}"
139147

140148

141149
def _now() -> float:

manga_translator/runtime_api_resolver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ def _build_endpoint(
5757
if not str(resolved_api_key or "").strip():
5858
return None
5959
base_url = (base_url or "").rstrip("/")
60-
status_key = make_endpoint_status_key(feature, provider, index, base_url, model_name)
60+
status_key = make_endpoint_status_key(
61+
feature,
62+
provider,
63+
index,
64+
base_url,
65+
model_name,
66+
api_key=resolved_api_key,
67+
)
6168
return APIEndpoint(
6269
feature=feature,
6370
provider=provider,

0 commit comments

Comments
 (0)