mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
refactor(cli): 提取 _build_upstream_request 统一流式/非流式的上游请求构建逻辑
将 cli_stream_mixin 和 cli_sync_mixin 中重复的上游请求构建代码 (provider behavior / stream policy / envelope / auth / RequestBuilder / URL 构建) 提取到 cli_request_mixin._build_upstream_request,返回 CliUpstreamRequestResult dataclass。
This commit is contained in:
@@ -6,7 +6,8 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
import src.api.handlers.base.cli_stream_mixin as mixmod
|
||||
import src.api.handlers.base.cli_request_mixin as request_mixmod
|
||||
from src.api.handlers.base.cli_request_mixin import CliRequestMixin
|
||||
from src.api.handlers.base.cli_stream_mixin import CliStreamMixin
|
||||
from src.api.handlers.base.stream_context import StreamContext
|
||||
|
||||
@@ -33,7 +34,7 @@ class _CaptureBuilder:
|
||||
raise _StopBuild()
|
||||
|
||||
|
||||
class _DummyCliStreamHandler(CliStreamMixin):
|
||||
class _DummyCliStreamHandler(CliRequestMixin, CliStreamMixin):
|
||||
FORMAT_ID = "openai:cli"
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -79,9 +80,9 @@ async def test_execute_stream_request_does_not_mutate_original_request_body(
|
||||
async def _fake_get_provider_auth(endpoint: Any, key: Any) -> _DummyAuthInfo:
|
||||
return _DummyAuthInfo()
|
||||
|
||||
monkeypatch.setattr(mixmod, "get_provider_auth", _fake_get_provider_auth)
|
||||
monkeypatch.setattr(request_mixmod, "get_provider_auth", _fake_get_provider_auth)
|
||||
monkeypatch.setattr(
|
||||
mixmod,
|
||||
request_mixmod,
|
||||
"get_provider_behavior",
|
||||
lambda **kwargs: SimpleNamespace(
|
||||
envelope=None,
|
||||
@@ -89,15 +90,19 @@ async def test_execute_stream_request_does_not_mutate_original_request_body(
|
||||
cross_format_variant=None,
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(mixmod, "get_upstream_stream_policy", lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(request_mixmod, "get_upstream_stream_policy", lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(
|
||||
mixmod,
|
||||
request_mixmod,
|
||||
"resolve_upstream_is_stream",
|
||||
lambda *, client_is_stream, policy: client_is_stream,
|
||||
)
|
||||
monkeypatch.setattr(mixmod, "enforce_stream_mode_for_upstream", lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr(
|
||||
mixmod,
|
||||
request_mixmod,
|
||||
"enforce_stream_mode_for_upstream",
|
||||
lambda *args, **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
request_mixmod,
|
||||
"maybe_patch_request_with_prompt_cache_key",
|
||||
lambda request_body, **kwargs: request_body,
|
||||
)
|
||||
@@ -107,7 +112,12 @@ async def test_execute_stream_request_does_not_mutate_original_request_body(
|
||||
ctx.client_api_format = "openai:cli"
|
||||
|
||||
provider = SimpleNamespace(name="provider", id="provider-1", provider_type="", proxy=None)
|
||||
endpoint = SimpleNamespace(id="endpoint-1", api_format="openai:cli", base_url="https://x")
|
||||
endpoint = SimpleNamespace(
|
||||
id="endpoint-1",
|
||||
api_format="openai:cli",
|
||||
base_url="https://x",
|
||||
custom_path=None,
|
||||
)
|
||||
key = SimpleNamespace(id="key-1", proxy=None)
|
||||
candidate = SimpleNamespace(
|
||||
mapping_matched_model=None, needs_conversion=False, output_limit=None
|
||||
|
||||
Reference in New Issue
Block a user