fix(types): type the provider_specific_fields source dict and beta row test helpers

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-10-27 20:25:06 +00:00
parent 7a7abe0d7f
commit f7e3a21fbc
2 changed files with 16 additions and 11 deletions

View file

@ -2920,7 +2920,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
def _build_provider_specific_fields(
self,
completion_response: dict,
completion_response: dict[str, object],
citations: Sequence[object] | None,
thinking_blocks: list[ChatCompletionThinkingBlock | ChatCompletionRedactedThinkingBlock] | None,
web_search_results: Sequence[object] | None,
@ -2951,17 +2951,15 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
if tool_results is not None:
provider_specific_fields["tool_results"] = tool_results
container: Final = completion_response.get("container")
container_fields: Final[dict[str, object] | None] = container if isinstance(container, dict) else None
if tool_results is not None and any(result.get("type") != "tool_search_tool_result" for result in tool_results):
container_id: Final = (
completion_response.get("container", {}).get("id")
if isinstance(completion_response.get("container"), dict)
else None
)
raw_container_id: Final = container_fields.get("id") if container_fields is not None else None
container_id: Final = raw_container_id if isinstance(raw_container_id, str) else None
code_by_id: Final = self._build_code_by_id_map(tool_calls)
code_interpreter_results = self._build_code_interpreter_results(tool_results, code_by_id, container_id)
provider_specific_fields["code_interpreter_results"] = code_interpreter_results
container: Final = completion_response.get("container")
if container is not None:
provider_specific_fields["container"] = container

View file

@ -33,9 +33,10 @@ def _bundled_config(monkeypatch: pytest.MonkeyPatch) -> None:
anthropic_beta_headers_manager._BETA_HEADERS_CONFIG = None
def _bundled_rows() -> dict:
def _bundled_rows() -> dict[str, dict[str, str | None]]:
with open(os.path.join(os.path.dirname(litellm.__file__), "anthropic_beta_headers_config.json")) as f:
return json.load(f)
rows: dict[str, dict[str, str | None]] = json.load(f)
return rows
@pytest.mark.parametrize(
@ -70,17 +71,23 @@ def test_resolve_beta_provider_picks_the_row_per_deployment(provider: str, api_b
def test_foundry_deployment_headers_follow_the_azure_ai_row() -> None:
headers: Final = {"anthropic-beta": f"{DIRECT_ONLY_BETA},thinking-binding-controls-2026-08-01"}
result: Final = update_headers_with_filtered_beta(headers=headers, provider="anthropic", api_base=FOUNDRY_API_BASE)
result: dict[str, str] = update_headers_with_filtered_beta(
headers=headers, provider="anthropic", api_base=FOUNDRY_API_BASE
)
assert result == {"anthropic-beta": "thinking-binding-controls-2026-08-01"}
def test_direct_deployment_headers_keep_every_anthropic_row_beta() -> None:
headers: Final = {"anthropic-beta": f"{DIRECT_ONLY_BETA},thinking-binding-controls-2026-08-01"}
result: Final = update_headers_with_filtered_beta(headers=headers, provider="anthropic", api_base=DIRECT_API_BASE)
result: dict[str, str] = update_headers_with_filtered_beta(
headers=headers, provider="anthropic", api_base=DIRECT_API_BASE
)
assert result == {"anthropic-beta": f"{DIRECT_ONLY_BETA},thinking-binding-controls-2026-08-01"}
def test_foundry_deployment_request_filters_header_and_body_betas_together() -> None:
headers: dict[str, str]
data: dict[str, object]
headers, data = update_request_with_filtered_beta(
headers={"anthropic-beta": DIRECT_ONLY_BETA},
request_data={"anthropic_beta": [DIRECT_ONLY_BETA, "thinking-binding-controls-2026-08-01"], "max_tokens": 8},