mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
fix(providers): 修复 Key 表单状态同步与 streaming 候选状态码处理
前端: - KeyAllowedModelsEditDialog 同时监听 open 和 apiKey 变化,避免切换 key 时状态未刷新 - KeyFormDialog 新增 api_formats 过滤与默认值逻辑,可用格式变化时自动同步表单 - ProviderDetailDrawer 合并 provider 和 endpoint 的 api_formats 传递给 Key 表单, 数据刷新后同步 currentEndpoint 和 editingKey 引用 后端: - mark_candidate_streaming 移除 status_code 参数,streaming 阶段不再提前写入状态码 - 简化 active_requests 中 streaming 请求的完成判断,不再依赖 status_code 条件
This commit is contained in:
@@ -114,7 +114,6 @@ class RequestCandidateService:
|
||||
def mark_candidate_streaming(
|
||||
db: Session,
|
||||
candidate_id: str,
|
||||
status_code: int = 200,
|
||||
concurrent_requests: int | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
@@ -123,18 +122,19 @@ class RequestCandidateService:
|
||||
用于流式请求:连接建立成功后,流开始传输时调用。
|
||||
此时请求尚未完成,需要等流传输完毕后再调用 mark_candidate_success。
|
||||
|
||||
注意:streaming 阶段不设置 status_code,最终状态码由
|
||||
mark_candidate_success / mark_candidate_failed 在流结束时写入。
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
candidate_id: 候选ID
|
||||
status_code: HTTP 状态码(通常是 200)
|
||||
concurrent_requests: 并发请求数
|
||||
"""
|
||||
candidate = db.query(RequestCandidate).filter(RequestCandidate.id == candidate_id).first()
|
||||
if candidate:
|
||||
candidate.status = "streaming"
|
||||
candidate.status_code = status_code
|
||||
candidate.concurrent_requests = concurrent_requests
|
||||
# streaming 状态不设置 finished_at,因为请求还在进行中
|
||||
# streaming 状态不设置 finished_at 和 status_code,因为请求还在进行中
|
||||
db.commit()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -197,7 +197,6 @@ class RequestExecutor:
|
||||
RequestCandidateService.mark_candidate_streaming(
|
||||
db=self.db,
|
||||
candidate_id=candidate_id,
|
||||
status_code=200,
|
||||
concurrent_requests=key_rpm_count,
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -24,7 +24,7 @@ class UsageActiveRequestsMixin:
|
||||
|
||||
通过 RequestCandidate 表判断哪些请求实际已成功完成:
|
||||
1. status='success' 且 stream_completed=True(正常完成)
|
||||
2. status='streaming' 且 status_code=200(Provider 已返回成功,流因重启中断)
|
||||
2. status='streaming'(Provider 已返回成功响应头,流因重启中断)
|
||||
"""
|
||||
if not request_ids:
|
||||
return set()
|
||||
@@ -35,15 +35,13 @@ class UsageActiveRequestsMixin:
|
||||
db.query(
|
||||
RequestCandidate.request_id,
|
||||
RequestCandidate.status,
|
||||
RequestCandidate.status_code,
|
||||
RequestCandidate.extra_data,
|
||||
)
|
||||
.filter(
|
||||
RequestCandidate.request_id.in_(request_ids),
|
||||
or_(
|
||||
RequestCandidate.status == "success",
|
||||
(RequestCandidate.status == "streaming")
|
||||
& (RequestCandidate.status_code == 200),
|
||||
RequestCandidate.status == "streaming",
|
||||
),
|
||||
)
|
||||
.all()
|
||||
@@ -53,7 +51,7 @@ class UsageActiveRequestsMixin:
|
||||
extra_data = c.extra_data or {}
|
||||
if c.status == "success" and extra_data.get("stream_completed", False):
|
||||
completed.add(c.request_id)
|
||||
elif c.status == "streaming" and c.status_code == 200:
|
||||
elif c.status == "streaming":
|
||||
completed.add(c.request_id)
|
||||
return completed
|
||||
|
||||
@@ -111,7 +109,7 @@ class UsageActiveRequestsMixin:
|
||||
清理超时的 pending/streaming 请求
|
||||
|
||||
将超过指定时间仍处于 pending 或 streaming 状态的请求标记为 failed 或恢复为 completed。
|
||||
会检查 RequestCandidate 表,如果 Provider 已返回成功(status_code=200),
|
||||
会检查 RequestCandidate 表,如果 Provider 已返回成功响应(status=streaming 或 stream_completed),
|
||||
则恢复为 completed 而非标记为 failed,同时同步更新 candidate 状态。
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user