[Frontend] Add /abort_requests to the RLHF dev API router (#47173)
Signed-off-by: aoshen02 <aoshen@inferact.ai> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
a02984ed47
commit
83762b77b0
@@ -64,6 +64,13 @@ impl InflightRequests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Collect the internal engine ids of every in-flight request. Used to
|
||||
/// abort all outstanding requests when no external ids are given.
|
||||
pub(crate) fn all_internal_ids(&self) -> Vec<String> {
|
||||
let map = self.map.lock();
|
||||
map.values().flat_map(|internal_ids| internal_ids.keys()).cloned().collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn is_empty(&self) -> bool {
|
||||
self.map.lock().is_empty()
|
||||
|
||||
@@ -122,7 +122,12 @@ impl Llm {
|
||||
/// tracking entries themselves are removed when the corresponding output
|
||||
/// streams are dropped, not here.
|
||||
pub async fn abort(&self, external_ids: &[String]) -> Result<()> {
|
||||
let internal_ids = self.inflight.resolve(external_ids);
|
||||
// Empty `external_ids` means abort every in-flight request.
|
||||
let internal_ids = if external_ids.is_empty() {
|
||||
self.inflight.all_internal_ids()
|
||||
} else {
|
||||
self.inflight.resolve(external_ids)
|
||||
};
|
||||
if internal_ids.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -20,12 +20,8 @@ pub async fn abort_requests(
|
||||
body: Result<Json<AbortRequestsRequest>, JsonRejection>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
let Json(body) = body.map_err(|error| ApiError::json_parse_error(error.body_text()))?;
|
||||
let request_ids = body.request_ids.ok_or_else(|| {
|
||||
ApiError::invalid_request(
|
||||
"Missing 'request_ids' in request body".to_string(),
|
||||
Some("request_ids"),
|
||||
)
|
||||
})?;
|
||||
// Empty/missing `request_ids` aborts all in-flight requests.
|
||||
let request_ids = body.request_ids.unwrap_or_default();
|
||||
|
||||
state
|
||||
.chat
|
||||
|
||||
@@ -5276,10 +5276,12 @@ async fn abort_requests_route_returns_ok_for_well_formed_body() {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
#[serial]
|
||||
async fn abort_requests_route_rejects_missing_request_ids() {
|
||||
async fn abort_requests_route_aborts_all_when_request_ids_missing() {
|
||||
let (app, engine_task) =
|
||||
test_admin_app_with_engine_script(|_dealer, _push| boxed_test_future(async move {})).await;
|
||||
|
||||
// Missing `request_ids` means "abort all in-flight requests"; with no
|
||||
// in-flight requests this is a no-op that still succeeds.
|
||||
let response = app
|
||||
.clone()
|
||||
.call(
|
||||
@@ -5293,11 +5295,10 @@ async fn abort_requests_route_rejects_missing_request_ids() {
|
||||
.await
|
||||
.expect("call app");
|
||||
|
||||
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
||||
let status = response.status();
|
||||
let body = to_bytes(response.into_body(), usize::MAX).await.expect("read body");
|
||||
let json: serde_json::Value = serde_json::from_slice(&body).expect("decode json");
|
||||
assert_eq!(json["error"]["type"], "invalid_request_error");
|
||||
assert_eq!(json["error"]["param"], "request_ids");
|
||||
assert_eq!(status, StatusCode::OK, "{}", String::from_utf8_lossy(&body));
|
||||
assert!(body.is_empty());
|
||||
engine_task.abort_and_join().await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user