Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions crates/switchyard-translation/src/codecs/responses/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,9 @@ fn fnv1a_64(text: &str) -> u64 {
})
}

// Converts any upstream message ID into a Responses-looking response ID.
// Keep the response ID aligned with buffered responses and stored conversation history.
fn responses_id(state: &StreamTranslationState) -> String {
let Some(id) = target_message_id_or_source_message_id(state) else {
return "resp_switchyard".to_string();
};
if id.starts_with("resp_") {
id.to_string()
} else {
format!("resp_{id}")
}
target_message_id_or_source_message_id(state)
.unwrap_or("resp_switchyard")
.to_string()
}
16 changes: 16 additions & 0 deletions crates/switchyard-translation/tests/stream_translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,22 @@ fn openai_chat_to_responses_uses_served_model_without_losing_source_model() -> T
Ok(())
}

// Stored conversation history is keyed by the upstream ID, so clients must see it unchanged.
#[test]
fn openai_chat_to_responses_keeps_the_upstream_id() -> TestResult {
let mut state =
StreamTranslationState::new(WireFormat::OpenAiChat, WireFormat::OpenAiResponses);
let events = TranslationEngine::default().translate_event(
&mut state,
WireFormat::OpenAiChat,
WireFormat::OpenAiResponses,
&json!({"id": "chatcmpl-test", "choices": [{"index": 0, "delta": {"content": "hi"}}]}),
)?;

assert_eq!(events[0]["response"]["id"], "chatcmpl-test");
Ok(())
}

// Verifies OpenAI Chat finish emits a terminal chunk when the source closes without one.
#[test]
fn openai_chat_finish_synthesizes_terminal_chunk_after_incomplete_source() -> TestResult {
Expand Down
Loading