mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-03 16:07:46 +08:00
忽略 OpenAI Responses keepalive 事件
This commit is contained in:
@@ -1556,6 +1556,7 @@ impl OpenAIResponsesProviderState {
|
||||
});
|
||||
self.finished = true;
|
||||
}
|
||||
"keepalive" => {}
|
||||
event_type if openai_responses_stream_event_is_known_noop(event_type) => {
|
||||
self.ensure_started(report_context, &mut out);
|
||||
}
|
||||
|
||||
@@ -715,6 +715,107 @@ mod tests {
|
||||
assert!(!sse.contains("HelloHello"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_openai_responses_keepalive_events_for_chat_clients() {
|
||||
let report_context = report_context("openai:responses", "openai:chat");
|
||||
let mut matrix = StreamingStandardFormatMatrix::default();
|
||||
let mut output = Vec::new();
|
||||
|
||||
let keepalive = matrix
|
||||
.transform_line(
|
||||
&report_context,
|
||||
data_line(json!({
|
||||
"type": "keepalive",
|
||||
"sequence_number": 1,
|
||||
})),
|
||||
)
|
||||
.expect("keepalive should be ignored");
|
||||
assert!(keepalive.is_empty());
|
||||
|
||||
for line in [
|
||||
data_line(json!({
|
||||
"type": "response.output_text.delta",
|
||||
"response_id": "resp_keepalive_123",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"delta": "pong",
|
||||
})),
|
||||
data_line(json!({
|
||||
"type": "response.completed",
|
||||
"response": {
|
||||
"id": "resp_keepalive_123",
|
||||
"object": "response",
|
||||
"model": "gpt-5.4",
|
||||
"status": "completed",
|
||||
"output": [],
|
||||
},
|
||||
})),
|
||||
] {
|
||||
output.extend(
|
||||
matrix
|
||||
.transform_line(&report_context, line)
|
||||
.expect("keepalive and text should convert"),
|
||||
);
|
||||
}
|
||||
|
||||
let sse = String::from_utf8(output).expect("sse should be utf8");
|
||||
assert!(!sse.contains("Unsupported provider stream event"), "{sse}");
|
||||
assert!(!sse.contains("unsupported_stream_event"), "{sse}");
|
||||
assert!(sse.contains("pong"), "{sse}");
|
||||
assert!(sse.contains("chat.completion.chunk"), "{sse}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_openai_responses_keepalive_events_for_responses_clients() {
|
||||
let mut report_context = report_context("openai:chat", "openai:responses");
|
||||
report_context["provider_stream_event_api_format"] = json!("openai:responses");
|
||||
let mut matrix = StreamingStandardFormatMatrix::default();
|
||||
let mut output = Vec::new();
|
||||
|
||||
let keepalive = matrix
|
||||
.transform_line(
|
||||
&report_context,
|
||||
data_line(json!({
|
||||
"type": "keepalive",
|
||||
"sequence_number": 1,
|
||||
})),
|
||||
)
|
||||
.expect("keepalive should be ignored");
|
||||
assert!(keepalive.is_empty());
|
||||
|
||||
for line in [
|
||||
data_line(json!({
|
||||
"type": "response.output_text.delta",
|
||||
"response_id": "resp_keepalive_456",
|
||||
"output_index": 0,
|
||||
"content_index": 0,
|
||||
"delta": "pong",
|
||||
})),
|
||||
data_line(json!({
|
||||
"type": "response.completed",
|
||||
"response": {
|
||||
"id": "resp_keepalive_456",
|
||||
"object": "response",
|
||||
"model": "gpt-5.4",
|
||||
"status": "completed",
|
||||
"output": [],
|
||||
},
|
||||
})),
|
||||
] {
|
||||
output.extend(
|
||||
matrix
|
||||
.transform_line(&report_context, line)
|
||||
.expect("keepalive and text should convert"),
|
||||
);
|
||||
}
|
||||
|
||||
let sse = String::from_utf8(output).expect("sse should be utf8");
|
||||
assert!(!sse.contains("Unsupported provider stream event"), "{sse}");
|
||||
assert!(!sse.contains("unsupported_stream_event"), "{sse}");
|
||||
assert!(sse.contains("pong"), "{sse}");
|
||||
assert!(sse.contains("event: response.output_text.delta"), "{sse}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transforms_provider_errors_to_claude_error_events() {
|
||||
let cases = [
|
||||
|
||||
Reference in New Issue
Block a user