|
30 | 30 | differ across runs. We therefore strip volatile fields from the request |
31 | 31 | body before matching. See ``_match_llm_body`` below. |
32 | 32 | """ |
| 33 | + |
33 | 34 | from __future__ import annotations |
34 | 35 |
|
35 | 36 | import logging |
36 | 37 | import os |
37 | 38 | import re |
| 39 | +from collections.abc import Iterator |
38 | 40 | from contextlib import contextmanager |
39 | | -from typing import Iterator, Optional |
40 | 41 |
|
41 | 42 | logger = logging.getLogger(__name__) |
42 | 43 |
|
|
60 | 61 | re.compile(rb'"id"\s*:\s*"call_[A-Za-z0-9]+"'), # OpenAI tool-call IDs |
61 | 62 | re.compile(rb'"tool_call_id"\s*:\s*"call_[A-Za-z0-9]+"'), |
62 | 63 | # UUIDs that occasionally appear in tool returns (annotation IDs etc.) |
63 | | - re.compile( |
64 | | - rb"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b" |
65 | | - ), |
| 64 | + re.compile(rb"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b"), |
66 | 65 | ] |
67 | 66 |
|
68 | 67 |
|
@@ -135,7 +134,7 @@ def _match_llm_body(r1, r2) -> None: |
135 | 134 |
|
136 | 135 |
|
137 | 136 | @contextmanager |
138 | | -def maybe_vcr_cassette() -> Iterator[Optional[object]]: |
| 137 | +def maybe_vcr_cassette() -> Iterator[object | None]: |
139 | 138 | """ |
140 | 139 | Yield either an active VCR cassette context (when env says so) or |
141 | 140 | None (the no-op path used in production). |
@@ -210,9 +209,7 @@ def maybe_vcr_cassette() -> Iterator[Optional[object]]: |
210 | 209 | def _ignore_request(request) -> bool: |
211 | 210 | return request.host not in _LLM_HOSTS |
212 | 211 |
|
213 | | - my_vcr.before_record_request = ( |
214 | | - lambda req: req if not _ignore_request(req) else None |
215 | | - ) |
| 212 | + my_vcr.before_record_request = lambda req: req if not _ignore_request(req) else None |
216 | 213 | # ``record_mode=none`` (replay) plus our ignore filter means: for |
217 | 214 | # non-LLM hosts the request passes through to the real network; for |
218 | 215 | # LLM hosts a missing cassette entry raises |
|
0 commit comments