Allow developer to choose to whether stop response.create when generate_reply timeout
Feature Type
I cannot use LiveKit without it
Feature Description
According to https://deepwiki.com/search/after-failed-to-generate-a-rep_2136620f-4226-4394-96f6-b0867e3fd25b?mode=deep, the timeout of generate_reply does not trigger response.cancel to stop response.create and thus openai request pipeline triggered by generate_reply still keep running even though internal generate_reply timed out happened.
We want it can allow developer to choose to whether to stop response.create when generate_reply timeout due to following 3 reasons:
-
Our use case want openai request pipeline triggered by
generate_replycompletely stop when internalgenerate_replytime out happened. -
According to https://deepwiki.com/search/after-failed-to-generate-a-rep_2745306e-349a-44c8-9b7a-3bbdc43d37ce?mode=fast, when
generate_replytimes out locally, the OpenAI server may still be processing the original request, and a subsequent generate_reply call can trigger the "OpenAI Realtime API returned an error: RealtimeError(message='Conversation already has an active response in progress:" error. The image below show the details -
We don't need the audio playback for
response.createof the timeoutedgenerate_reply. It is costly and wasteful that openai server is still processing it (input token and output token cost money)
Workarounds / Alternatives
No response
Additional Context
To force to trigger "failed to generate a reply: generate_reply timed out.", please following the steps below:
- Reduce the default timeout of the corresponding source code from 10 to 0.01 in
livekit/plugins/openai/realtime/realtime_model.py - Use openai realtime model with openai.realtime.RealtimeModel(
model="gpt-realtime",
voice="marin",
turn_detection=ServerVad(
type="server_vad"
prefix_padding_ms=300,
silence_duration_ms=500,
threshold=0.5,
create_response=False,
interrupt_response=False,
),
temperature=0.6,
input_audio_noise_reduction=NOT_GIVEN
),
input_audio_transcription=AudioTranscription(language=lang, model="whisper-1"),
max_session_duration=55 * 60,
) - Implement
await agent_session.generate_reply()