fix: stop advertising unsupported speech instructions

This commit is contained in:
waeckerlinfederowicz66-sketch 2026-09-14 12:18:00 +08:00
parent 2c9a01f776
commit 1fa8e5d024
2 changed files with 4 additions and 22 deletions

View file

@ -50,7 +50,7 @@ class FlowSpeechTextToSpeechConfig(BaseTextToSpeechConfig):
DEFAULT_VOICE = "Kore"
def get_supported_openai_params(self, model: str) -> list[str]: # mutable-ok: base provider interface returns list
return ["voice", "instructions"] # mutable-ok: base provider interface returns list
return ["voice"] # mutable-ok: base provider interface returns list
def map_openai_params(
self,
@ -60,17 +60,8 @@ class FlowSpeechTextToSpeechConfig(BaseTextToSpeechConfig):
drop_params: bool = False,
kwargs: dict[str, object] | None = None, # mutable-ok: base provider interface requires dict
) -> tuple[str | None, dict[str, object]]: # mutable-ok: base provider interface returns dict params
params: Final[dict[str, object]] = ( # mutable-ok: isolated request copy
dict(optional_params) if optional_params else {} # mutable-ok: isolated request copy
)
mapped_voice: Final = self._resolve_voice(voice)
instructions: Final = params.get("instructions")
mapped_params: Final[dict[str, object]] = ( # mutable-ok: base provider interface returns dict params
{"prompt": instructions} # mutable-ok: base provider interface returns dict params
if isinstance(instructions, str) and instructions.strip()
else {} # mutable-ok: base provider interface returns dict params
)
return mapped_voice, mapped_params
return mapped_voice, {} # mutable-ok: base provider interface returns dict params
def _resolve_voice(
self,
@ -124,19 +115,12 @@ class FlowSpeechTextToSpeechConfig(BaseTextToSpeechConfig):
litellm_params: dict[str, object], # mutable-ok: base provider interface requires dict
headers: dict[str, str], # mutable-ok: base provider interface requires dict
) -> TextToSpeechRequestData:
prompt: Final = optional_params.get("prompt")
prompt_data: Final[dict[str, str]] = ( # mutable-ok: JSON request body requires a dict
{"prompt": prompt} # mutable-ok: JSON request body requires a dict
if isinstance(prompt, str) and prompt.strip()
else {} # mutable-ok: JSON request body requires a dict
)
request_body: Final[dict[str, object]] = { # mutable-ok: JSON request body requires a dict
"text": input,
"originalText": input,
"speakers": [ # mutable-ok: FlowSpeech JSON schema requires a speakers array
{"voiceName": voice or self.DEFAULT_VOICE} # mutable-ok: FlowSpeech JSON schema requires an object
],
**prompt_data,
}
return TextToSpeechRequestData(
dict_body=request_body,

View file

@ -12,7 +12,7 @@ from litellm.llms.flowspeech.text_to_speech.transformation import (
)
def test_maps_voice_and_instructions_to_flowspeech_request():
def test_maps_voice_without_unsupported_instructions():
config = FlowSpeechTextToSpeechConfig()
voice, params = config.map_openai_params(
model="flowspeech-tts",
@ -33,8 +33,8 @@ def test_maps_voice_and_instructions_to_flowspeech_request():
"text": "Hello from FlowSpeech",
"originalText": "Hello from FlowSpeech",
"speakers": [{"voiceName": "Aoede"}],
"prompt": "Speak with calm confidence",
}
assert config.get_supported_openai_params("flowspeech-tts") == ["voice"]
def test_uses_default_voice_and_ignores_unsupported_openai_params():
@ -141,7 +141,6 @@ def test_speech_dispatches_to_flowspeech_handler():
"text": "Hello",
"originalText": "Hello",
"speakers": [{"voiceName": "Aoede"}],
"prompt": "Speak warmly",
}
return httpx.Response(
200,
@ -159,7 +158,6 @@ def test_speech_dispatches_to_flowspeech_handler():
model="flowspeech/flowspeech-tts",
input="Hello",
voice="Aoede",
instructions="Speak warmly",
api_key="test-key",
client=client,
)