mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(cli): 统一 CLI handler pending usage 的 api_format 来源
CLI stream/sync mixin 中创建 pending usage 记录时,api_format 取值 来源不一致(部分用 FORMAT_ID,部分用 allowed_api_formats[0])。 新增 primary_api_format 属性并统一使用,确保 pending 记录的格式 与实际客户端请求格式一致。
This commit is contained in:
@@ -49,6 +49,7 @@ class CliHandlerProtocol(Protocol):
|
||||
user_agent: str
|
||||
start_time: float
|
||||
allowed_api_formats: list[str]
|
||||
primary_api_format: str
|
||||
redis: Redis # type: ignore[type-arg]
|
||||
telemetry: MessageTelemetry
|
||||
perf_metrics: dict[str, Any] | None
|
||||
|
||||
@@ -99,13 +99,14 @@ class CliStreamMixin:
|
||||
# 使用子类实现的方法提取 model(不同 API 格式的 model 位置不同)
|
||||
# 注意:使用 original_request_body,因为整流只修改 messages,不影响 model 字段
|
||||
model = self.extract_model_from_request(original_request_body, path_params)
|
||||
client_api_format = self.primary_api_format
|
||||
|
||||
# 提前创建 pending 记录,让前端可以立即看到"处理中"
|
||||
self._create_pending_usage(
|
||||
model=model,
|
||||
is_stream=True,
|
||||
request_type="chat",
|
||||
api_format=self.FORMAT_ID,
|
||||
api_format=client_api_format,
|
||||
request_headers=original_headers,
|
||||
request_body=original_request_body,
|
||||
)
|
||||
@@ -113,7 +114,7 @@ class CliStreamMixin:
|
||||
# 创建流上下文
|
||||
ctx = StreamContext(
|
||||
model=model,
|
||||
api_format=self.allowed_api_formats[0],
|
||||
api_format=client_api_format,
|
||||
api_family=self.api_family,
|
||||
endpoint_kind=self.endpoint_kind,
|
||||
request_id=self.request_id,
|
||||
|
||||
@@ -78,7 +78,7 @@ class CliSyncMixin:
|
||||
|
||||
# 使用子类实现的方法提取 model(不同 API 格式的 model 位置不同)
|
||||
model = self.extract_model_from_request(original_request_body, path_params)
|
||||
api_format = self.allowed_api_formats[0]
|
||||
api_format = self.primary_api_format
|
||||
sync_start_time = time.time()
|
||||
|
||||
# 提前创建 pending 记录,让前端可以立即看到"处理中"
|
||||
@@ -86,7 +86,7 @@ class CliSyncMixin:
|
||||
model=model,
|
||||
is_stream=False,
|
||||
request_type="chat",
|
||||
api_format=self.FORMAT_ID,
|
||||
api_format=api_format,
|
||||
request_headers=original_headers,
|
||||
request_body=original_request_body,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user