Skip to content

Fix seed field not bridged in SpeechRequest OpenAI conversion#262

Merged
juliendenize merged 2 commits into
mistralai:mainfrom
winklemad:fix-speech-request-seed
Jul 15, 2026
Merged

Fix seed field not bridged in SpeechRequest OpenAI conversion#262
juliendenize merged 2 commits into
mistralai:mainfrom
winklemad:fix-speech-request-seed

Conversation

@winklemad

Copy link
Copy Markdown
Contributor

No linked issue — found by reading the code.

The bug

SpeechRequest uses the field name random_seed, while the OpenAI request format uses seed. Neither converter bridges the two:

  • to_openai() returns the raw model_dump, so it emits random_seed (a mistral-common-internal name) instead of seed.
  • from_openai() keeps only keys that are model fields, so an OpenAI request's seed is never mapped to random_seed and is silently dropped:
from mistral_common.protocol.speech.request import SpeechRequest

SpeechRequest.from_openai({"input": "hi", "voice": "female", "seed": 123}).random_seed
# None   -> the seed provided in the OpenAI request is lost

SpeechRequest(input="hi", voice="female", random_seed=123).to_openai()["seed"]
# KeyError: 'seed'   -> the key is emitted as "random_seed" instead

Smoking gun

The sibling TranscriptionRequest already bridges the two names in both directions:

# TranscriptionRequest.to_openai
openai_request["seed"] = openai_request.pop("random_seed")
# TranscriptionRequest.from_openai
seed = openai_request.get("seed")
...
converted_dict["random_seed"] = seed

SpeechRequest does neither, so it is inconsistent with its sibling.

Fix

Translate random_seedseed in both SpeechRequest.to_openai and SpeechRequest.from_openai, mirroring TranscriptionRequest. A seed now survives the round trip and an OpenAI-style request with seed is honored.

Testing

Added test_convert_speech_request_seed, asserting to_openai() emits seed (not random_seed) and from_openai({"seed": ...}) sets random_seed. It fails before the change (KeyError: 'seed') and passes after; the full tests/test_converters.py suite passes (104 passed). ruff check / ruff format --check are clean.

winklemad and others added 2 commits July 12, 2026 09:39
`SpeechRequest.to_openai` emitted the mistral-common field name `random_seed`
instead of OpenAI's `seed`, and `SpeechRequest.from_openai` only copied keys that
are model fields, so an OpenAI request's `seed` was silently dropped (`random_seed`
stayed `None`). The sibling `TranscriptionRequest` already bridges the two names in
both directions.

Translate `random_seed` <-> `seed` in both converters so a seed survives the round
trip and an OpenAI-style request with `seed` is honored.

@juliendenize juliendenize left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, made a minor update and will merge :)

@juliendenize
juliendenize merged commit 46609ce into mistralai:main Jul 15, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants