mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""Responses 续链匹配与失效判定。"""
|
|
|
|
from domain.models import LlmResponseChain, LlmRuntimeConfig
|
|
from application.chat_service import _usable_chain_id
|
|
from infrastructure.llm.factory import _is_chain_invalid_error
|
|
|
|
|
|
def test_usable_chain_id_matches():
|
|
llm = LlmRuntimeConfig(
|
|
base_url="https://api.openai.com/v1",
|
|
api_key="k",
|
|
model="gpt-4o-mini",
|
|
provider_id=3,
|
|
api_style="responses",
|
|
)
|
|
chain = LlmResponseChain(
|
|
provider_id=3, model="gpt-4o-mini", previous_response_id="resp_abc"
|
|
)
|
|
assert _usable_chain_id(chain, llm, True) == "resp_abc"
|
|
|
|
|
|
def test_usable_chain_id_clears_on_model_switch():
|
|
llm = LlmRuntimeConfig(
|
|
base_url="https://api.openai.com/v1",
|
|
api_key="k",
|
|
model="gpt-4o",
|
|
provider_id=3,
|
|
api_style="responses",
|
|
)
|
|
chain = LlmResponseChain(
|
|
provider_id=3, model="gpt-4o-mini", previous_response_id="resp_abc"
|
|
)
|
|
assert _usable_chain_id(chain, llm, True) is None
|
|
|
|
|
|
def test_usable_chain_id_requires_responses():
|
|
llm = LlmRuntimeConfig(
|
|
base_url="https://api.deepseek.com/v1",
|
|
api_key="k",
|
|
model="deepseek-chat",
|
|
provider_id=1,
|
|
api_style="completions",
|
|
)
|
|
chain = LlmResponseChain(
|
|
provider_id=1, model="deepseek-chat", previous_response_id="resp_x"
|
|
)
|
|
assert _usable_chain_id(chain, llm, False) is None
|
|
|
|
|
|
def test_is_chain_invalid_error():
|
|
assert _is_chain_invalid_error(Exception("Invalid previous_response_id: resp_x"))
|
|
assert not _is_chain_invalid_error(Exception("rate limit exceeded"))
|