(input_options: FinalRequestOptions)
| 38 | |
| 39 | |
| 40 | def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions: |
| 41 | options = model_copy(input_options, deep=True) |
| 42 | |
| 43 | if is_dict(options.json_data): |
| 44 | options.json_data.setdefault("anthropic_version", DEFAULT_VERSION) |
| 45 | |
| 46 | if is_given(options.headers): |
| 47 | betas = options.headers.get("anthropic-beta") |
| 48 | if betas: |
| 49 | options.json_data.setdefault("anthropic_beta", betas.split(",")) |
| 50 | |
| 51 | if options.url in {"/v1/complete", "/v1/messages", "/v1/messages?beta=true"} and options.method == "post": |
| 52 | if not is_dict(options.json_data): |
| 53 | raise RuntimeError("Expected dictionary json_data for post /completions endpoint") |
| 54 | |
| 55 | model = options.json_data.pop("model", None) |
| 56 | model = urllib.parse.quote(str(model), safe=":") |
| 57 | stream = options.json_data.pop("stream", False) |
| 58 | if stream: |
| 59 | options.url = f"/model/{model}/invoke-with-response-stream" |
| 60 | else: |
| 61 | options.url = f"/model/{model}/invoke" |
| 62 | |
| 63 | if options.url.startswith("/v1/messages/batches"): |
| 64 | raise AnthropicError("The Batch API is not supported in Bedrock yet") |
| 65 | |
| 66 | if options.url == "/v1/messages/count_tokens": |
| 67 | raise AnthropicError("Token counting is not supported in Bedrock yet") |
| 68 | |
| 69 | return options |
| 70 | |
| 71 | |
| 72 | def _infer_region() -> str: |
no test coverage detected