Return ``messages`` with every ``cache_control`` key removed. Only list-of-blocks contents (see :func:`_cached_text`) can carry the marker; plain-string contents pass through untouched. The input is not mutated.
(messages: list[dict])
| 306 | |
| 307 | |
| 308 | def _strip_cache_control(messages: list[dict]) -> list[dict]: |
| 309 | """Return ``messages`` with every ``cache_control`` key removed. |
| 310 | |
| 311 | Only list-of-blocks contents (see :func:`_cached_text`) can carry the |
| 312 | marker; plain-string contents pass through untouched. The input is not |
| 313 | mutated. |
| 314 | """ |
| 315 | cleaned: list[dict] = [] |
| 316 | for msg in messages: |
| 317 | content = msg.get("content") |
| 318 | if isinstance(content, list): |
| 319 | blocks = [ |
| 320 | {k: v for k, v in block.items() if k != "cache_control"} |
| 321 | if isinstance(block, dict) |
| 322 | else block |
| 323 | for block in content |
| 324 | ] |
| 325 | msg = {**msg, "content": blocks} |
| 326 | cleaned.append(msg) |
| 327 | return cleaned |
| 328 | |
| 329 | |
| 330 | def _prepare_messages(model: str, messages: list[dict]) -> list[dict]: |