feat(core): 添加 LLMResponse frozen dataclass

含 content/thinking/ttft_ms/max_inter_token_ms/call_id 等 11 个字段。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-06 22:33:48 -04:00
parent 9340c5e0f8
commit 70320d7cfa
2 changed files with 74 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
"""core/types.py 单元测试。"""
from __future__ import annotations
import pytest
from core.types import LLMResponse
class TestLLMResponse:
@pytest.fixture()
def sample_response(self) -> LLMResponse:
return LLMResponse(
content="回答内容",
thinking="思考过程",
model="deepseek-v4-pro",
provider="deepseek",
prompt_tokens=100,
completion_tokens=50,
latency_ms=1200,
ttft_ms=350.0,
max_inter_token_ms=45.0,
cache_hit=False,
call_id="test-uuid-001",
)
def test_frozen_prevents_mutation(self, sample_response: LLMResponse) -> None:
with pytest.raises(AttributeError):
sample_response.content = "篡改"
def test_all_fields_accessible(self, sample_response: LLMResponse) -> None:
assert sample_response.content == "回答内容"
assert sample_response.thinking == "思考过程"
assert sample_response.model == "deepseek-v4-pro"
assert sample_response.provider == "deepseek"
assert sample_response.prompt_tokens == 100
assert sample_response.completion_tokens == 50
assert sample_response.latency_ms == 1200
assert sample_response.ttft_ms == 350.0
assert sample_response.max_inter_token_ms == 45.0
assert sample_response.cache_hit is False
assert sample_response.call_id == "test-uuid-001"
def test_cache_hit_response_has_none_ttft(self) -> None:
resp = LLMResponse(
content="cached", thinking="", model="m", provider="p",
prompt_tokens=0, completion_tokens=0, latency_ms=1,
ttft_ms=None, max_inter_token_ms=None, cache_hit=True, call_id="c",
)
assert resp.ttft_ms is None
assert resp.max_inter_token_ms is None
assert resp.cache_hit is True