fix: changes after review

This commit is contained in:
Yamac Ay 2026-09-25 10:03:50 +02:00
parent 77b24862ba
commit a23f13a645
No known key found for this signature in database
GPG key ID: D113B438819CA628
2 changed files with 5 additions and 5 deletions

View file

@ -15,7 +15,7 @@ from pydantic import (
class CacheControl(BaseModel):
type: Literal["ephemeral"]
ttl: str | None = None
ttl: Literal["5m", "1h"] | None = None
@model_serializer(mode="wrap")
def _serialize(

View file

@ -73,18 +73,18 @@ def _fold_message_cache_control(
breakpoint for the whole block. In all other cases (empty list, None,
unrecognized type) the marker is silently dropped.
"""
cc = message.get("cache_control")
if cc is None:
cache_control = message.get("cache_control")
if cache_control is None:
return message
base = {k: v for k, v in message.items() if k != "cache_control"}
content = message.get("content")
if isinstance(content, str):
base["content"] = [{"type": "text", "text": content, "cache_control": cc}]
base["content"] = [{"type": "text", "text": content, "cache_control": cache_control}]
return base
if isinstance(content, list) and content and isinstance(content[-1], dict):
base["content"] = [
*content[:-1],
{**content[-1], "cache_control": cc},
{**content[-1], "cache_control": cache_control},
]
return base
return base