fix: keep type-check delta stable after cache update

This commit is contained in:
Maximilian Rink 2026-10-12 20:20:39 +02:00
parent 4c344d2992
commit 0d25ab4096
3 changed files with 14 additions and 14 deletions

View file

@ -211,7 +211,7 @@ class OpenRouterImageEditConfig(BaseImageEditConfig):
if img is None:
continue
mime_type = ImageEditRequestUtils.get_image_content_type(img)
image_bytes = self._read_image_bytes(img)
image_bytes = self._read_image_bytes(cast(FileTypes, img))
b64_data = base64.b64encode(image_bytes).decode("utf-8")
content_parts.append(
{
@ -372,13 +372,13 @@ class OpenRouterImageEditConfig(BaseImageEditConfig):
input_image_tokens = prompt_tokens_details.get("image_tokens", 0)
model_response.usage = ImageUsage(
input_tokens=prompt_tokens,
input_tokens=int(prompt_tokens),
input_tokens_details=ImageUsageInputTokensDetails(
image_tokens=input_image_tokens,
text_tokens=prompt_tokens - input_image_tokens,
image_tokens=int(input_image_tokens),
text_tokens=int(prompt_tokens - input_image_tokens),
),
output_tokens=image_tokens,
total_tokens=total_tokens,
output_tokens=int(image_tokens),
total_tokens=int(total_tokens),
)
cost: Final = usage_data.get("cost")

View file

@ -254,7 +254,7 @@ class AWSEventStreamDecoder:
)
return GChunk(
text=_text,
text=_text or "",
index=_index,
is_finished=is_finished,
finish_reason=finish_reason,

View file

@ -1,4 +1,4 @@
from collections.abc import Sequence
from collections.abc import Mapping, Sequence
from typing import (
Final,
Literal,
@ -417,7 +417,7 @@ class ContextCachingEndpoints(VertexBase):
"Content-Type": "application/json",
}
if isinstance(token, dict):
headers.update(token)
headers.update(cast(Mapping[str, str], token))
elif token is not None:
headers["Authorization"] = f"Bearer {token}"
if extra_headers is not None:
@ -471,7 +471,7 @@ class ContextCachingEndpoints(VertexBase):
cached_content_request_body: Final = transform_openai_messages_to_gemini_context_caching(
model=model,
messages=cached_messages,
cache_key=generated_cache_key,
cache_key=generated_cache_key or "",
custom_llm_provider=custom_llm_provider,
vertex_project=vertex_project,
vertex_location=vertex_location,
@ -496,7 +496,7 @@ class ContextCachingEndpoints(VertexBase):
response: Final = client.post(
url=url,
headers=headers,
json=cached_content_request_body,
json=cast(dict[str, object], cached_content_request_body),
)
response.raise_for_status()
except httpx.HTTPStatusError as err:
@ -597,7 +597,7 @@ class ContextCachingEndpoints(VertexBase):
"Content-Type": "application/json",
}
if isinstance(token, dict):
headers.update(token)
headers.update(cast(Mapping[str, str], token))
elif token is not None:
headers["Authorization"] = f"Bearer {token}"
if extra_headers is not None:
@ -648,7 +648,7 @@ class ContextCachingEndpoints(VertexBase):
cached_content_request_body: Final = transform_openai_messages_to_gemini_context_caching(
model=model,
messages=cached_messages,
cache_key=generated_cache_key,
cache_key=generated_cache_key or "",
custom_llm_provider=custom_llm_provider,
vertex_project=vertex_project,
vertex_location=vertex_location,
@ -673,7 +673,7 @@ class ContextCachingEndpoints(VertexBase):
response: Final = await client.post(
url=url,
headers=headers,
json=cached_content_request_body,
json=cast(dict[str, object], cached_content_request_body),
)
response.raise_for_status()
except httpx.HTTPStatusError as err: