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 -3
View File
@@ -90,6 +90,7 @@ async def _complete(
reasoning_effort=None,
first_token_event=None,
content_event=None,
response_mode="text",
):
return await transport.complete(
messages=[{"role": "user", "content": "hi"}],
@@ -100,6 +101,7 @@ async def _complete(
reasoning_effort=reasoning_effort,
first_token_event=first_token_event,
content_event=content_event,
response_mode="text",
)
@@ -161,6 +163,8 @@ class TestSsePureFunctions:
assert _sse_data_payload("data: [DONE]") == "[DONE]"
async def test_iter_deltas_yields_and_flags_done(self):
from polygateway.transports._openai_completion import ChatCompletionAccumulator, ChatDelta
async def lines():
for raw in [
_chunk(content="he"),
@@ -173,16 +177,28 @@ class TestSsePureFunctions:
yield line
sink = {}
out = [d async for d in _iter_sse_deltas(lines(), sink)]
assert out == [(True, "he"), (False, "think")]
out = [
d
async for d in _iter_sse_deltas(
lines(), sink, ChatCompletionAccumulator(response_mode="text")
)
]
assert out == [ChatDelta("he", "", True), ChatDelta("", "think", True)]
assert sink["done"] is True and sink["usage"] == _USAGE
async def test_malformed_frame_raises_transient(self):
from polygateway.transports._openai_completion import ChatCompletionAccumulator
async def lines():
yield "data: {not-json"
with pytest.raises(TransientError, match="malformed"):
_ = [d async for d in _iter_sse_deltas(lines(), {})]
_ = [
d
async for d in _iter_sse_deltas(
lines(), {}, ChatCompletionAccumulator(response_mode="text")
)
]
class TestStreamHappyPath: