fix(openai): improve Responses API streaming reliability and diagnostics
This commit is contained in:
@@ -26,7 +26,7 @@ impl OpenAIProvider {
|
|||||||
.timeout(std::time::Duration::from_secs(300))
|
.timeout(std::time::Duration::from_secs(300))
|
||||||
.pool_idle_timeout(std::time::Duration::from_secs(90))
|
.pool_idle_timeout(std::time::Duration::from_secs(90))
|
||||||
.pool_max_idle_per_host(4)
|
.pool_max_idle_per_host(4)
|
||||||
.tcp_keepalive(std::time::Duration::from_secs(30))
|
.tcp_keepalive(std::time::Duration::from_secs(15))
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@@ -441,6 +441,7 @@ impl super::Provider for OpenAIProvider {
|
|||||||
self.client
|
self.client
|
||||||
.post(&url)
|
.post(&url)
|
||||||
.header("Authorization", format!("Bearer {}", api_key))
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.header("Accept", "text/event-stream")
|
||||||
.json(&body),
|
.json(&body),
|
||||||
)
|
)
|
||||||
.map_err(|e| AppError::ProviderError(format!("Failed to create EventSource for Responses API: {}", e)))?;
|
.map_err(|e| AppError::ProviderError(format!("Failed to create EventSource for Responses API: {}", e)))?;
|
||||||
@@ -527,8 +528,8 @@ impl super::Provider for OpenAIProvider {
|
|||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// If the probe returned 200, but the stream ended, it might be a silent failure or timeout.
|
// If the probe returned 200, but the stream ended, it might be a silent failure or timeout.
|
||||||
tracing::warn!("Responses stream ended prematurely (probe returned 200)");
|
tracing::warn!("Responses stream ended prematurely (probe returned 200). Error: {}", e);
|
||||||
Err(AppError::ProviderError(format!("Responses stream error (probe returned 200): {}", e)))?;
|
Err(AppError::ProviderError(format!("Responses stream error (connection closed by server after 200 OK): {}", e)))?;
|
||||||
}
|
}
|
||||||
Err(probe_err) => {
|
Err(probe_err) => {
|
||||||
tracing::error!("OpenAI Responses Stream Error Probe failed: {}", probe_err);
|
tracing::error!("OpenAI Responses Stream Error Probe failed: {}", probe_err);
|
||||||
|
|||||||
Reference in New Issue
Block a user