feat: timeout
This commit is contained in:
@@ -21,10 +21,13 @@ use secrecy::ExposeSecret;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_with::DeserializeFromStr;
|
use serde_with::DeserializeFromStr;
|
||||||
use serde_with::SerializeDisplay;
|
use serde_with::SerializeDisplay;
|
||||||
|
use tokio::select;
|
||||||
|
use tokio::time::sleep;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::time::Duration;
|
||||||
use strum::EnumString;
|
use strum::EnumString;
|
||||||
use strum::VariantArray;
|
use strum::VariantArray;
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
@@ -682,12 +685,21 @@ pub async fn create_chat_completion(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let upstream_response = match upstream_request.send().await {
|
let upstream_response = select! {
|
||||||
Ok(upstream_response) => upstream_response,
|
_ = sleep(Duration::from_secs(20)) => {
|
||||||
Err(upstream_error) => {
|
tracing::error!("timed out");
|
||||||
tracing::error!(?upstream_error);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upstream_response_result = upstream_request.send() => {
|
||||||
|
match upstream_response_result {
|
||||||
|
Ok(upstream_response) => upstream_response,
|
||||||
|
Err(upstream_error) => {
|
||||||
|
tracing::error!(?upstream_error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(upstream_error) = upstream_response.error_for_status_ref() {
|
if let Err(upstream_error) = upstream_response.error_for_status_ref() {
|
||||||
|
|||||||
Reference in New Issue
Block a user