| 2316 | |
| 2317 | |
| 2318 | def _reuse_anthropic_source_body( |
| 2319 | *, |
| 2320 | source_body: dict[str, Any], |
| 2321 | upstream_body: dict[str, Any], |
| 2322 | ) -> dict[str, Any]: |
| 2323 | transport_body = json.loads(json.dumps(source_body)) |
| 2324 | for key in ("model", "max_tokens", "stream", "temperature", "top_p"): |
| 2325 | if key in upstream_body: |
| 2326 | transport_body[key] = json.loads(json.dumps(upstream_body[key])) |
| 2327 | stop_value = upstream_body.get("stop") |
| 2328 | if isinstance(stop_value, list): |
| 2329 | transport_body["stop_sequences"] = list(stop_value) |
| 2330 | elif isinstance(stop_value, str) and stop_value.strip(): |
| 2331 | transport_body["stop_sequences"] = [stop_value] |
| 2332 | return transport_body |
| 2333 | |
| 2334 | |
| 2335 | def _transport_name(native_anthropic_transport: bool) -> str: |