refactor(speech): freeze httpx response header dicts (LIT002)

This commit is contained in:
mateo-berri 2026-08-31 21:12:53 -07:00
parent be84f0d7e5
commit c1b5cacf1f
2 changed files with 5 additions and 2 deletions

View file

@ -174,7 +174,9 @@ class SpeechToCompletionBridgeTransformationHandler:
if self._is_gemini_tts_model(model)
else (decoded_audio, "audio/mpeg")
)
response: Final = httpx.Response(status_code=200, content=content, headers={"Content-Type": content_type})
response: Final = httpx.Response(
status_code=200, content=content, headers=MappingProxyType({"Content-Type": content_type})
)
binary_response: Final = HttpxBinaryResponseContent(response)
binary_response.set_response_cost(_completion_response_cost(model_response))
return binary_response

View file

@ -7,6 +7,7 @@ Reference: https://cloud.google.com/text-to-speech/docs/reference/rest/v1/text/s
import base64
from collections.abc import Coroutine
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Final, Union
import httpx
@ -464,7 +465,7 @@ class VertexAITextToSpeechConfig(BaseTextToSpeechConfig, VertexBase):
media_type: Final = speech_media_type_from_audio_bytes(binary_data)
response: Final = httpx.Response(
status_code=200,
headers={} if media_type is None else {"content-type": media_type},
headers=None if media_type is None else MappingProxyType({"content-type": media_type}),
content=binary_data,
)