feat: preserve governed OpenAI tool messages in 1.4.0

Add faithful single-choice chat results, tool stream activity, error-frame retries, and isolated protocol caching.

Reject empty cached completions with the same value predicate as transport, add regression coverage, and adopt Apache-2.0.
This commit is contained in:
2026-10-01 14:32:19 -04:00
parent 0e29deac1a
commit 9185eab8c9
42 changed files with 2227 additions and 78 deletions
+19
View File
@@ -172,3 +172,22 @@ class TestClientWithRealRedis:
second = await client.chat(_MSGS)
assert first.cache_hit is False and second.cache_hit is True
assert second.content == "hello"
async def test_real_completion_roundtrip(redis_cache, namespace):
"""真实 Redis 保存完整嵌套协议对象,命中仍为值类型。"""
from dataclasses import replace
from tests.unit.test_openai_completion import accumulate
completion = accumulate().finish()
mw = CacheMW(backend=redis_cache, model_fingerprint="m", default_namespace=namespace, ttl_s=60)
async def terminal(_):
return replace(_resp(), completion=completion)
request = ChatRequest(messages=_MSGS, response_mode="openai")
first = await mw(request, terminal)
second = await mw(request, terminal)
assert second.cache_hit and second.completion == first.completion
assert second.completion is not first.completion
@@ -86,6 +86,7 @@ class ScriptedTransport:
reasoning_effort,
first_token_event,
content_event,
response_mode,
):
self.calls.append(source.name)
if self.hang: