Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(gateway): answer a queued generation INPUT_TOO_LONG with 400 (#497)
Krisztian Gajdar0cb086ddca04
diff --git a/packages/sie_gateway/src/handlers/proxy.rs b/packages/sie_gateway/src/handlers/proxy.rsindex 2dc501283..e5ccd60c6 100644--- a/packages/sie_gateway/src/handlers/proxy.rs+++ b/packages/sie_gateway/src/handlers/proxy.rs@@ -4129,7 +4129,7 @@ pub(crate) async fn run_streaming_generate(pub(crate) fn worker_error_http_status(code: &str) -> StatusCode {match code {"invalid_request" | "unsupported_field" => StatusCode::BAD_REQUEST,- "context_exceeded" => StatusCode::BAD_REQUEST,+ "context_exceeded" | INPUT_TOO_LONG_ERROR_CODE => StatusCode::BAD_REQUEST,PAYLOAD_TOO_LARGE_ERROR_CODE => StatusCode::PAYLOAD_TOO_LARGE,RESOURCE_EXHAUSTED_ERROR_CODE | MODEL_LOADING_ERROR_CODE | LORA_LOADING_ERROR_CODE => {StatusCode::SERVICE_UNAVAILABLE@@ -4150,7 +4150,7 @@ pub(crate) fn worker_error_openai_type(code: &str) -> &'static str {"invalid_request" | "unsupported_field" | PAYLOAD_TOO_LARGE_ERROR_CODE => {oai_type::INVALID_REQUEST}- "context_exceeded" => oai_type::CONTEXT_LENGTH_EXCEEDED,+ "context_exceeded" | INPUT_TOO_LONG_ERROR_CODE => oai_type::CONTEXT_LENGTH_EXCEEDED,"rate_limit_exceeded" => oai_type::RATE_LIMIT,COLD_START_RATE_LIMITED_ERROR_CODE => oai_type::RATE_LIMIT,_ => oai_type::SERVER_ERROR,@@ -25001,6 +25001,33 @@ mod tests {assert_eq!(value["error"]["attempt_id"], "att-large-1");}+ #[tokio::test]+ async fn test_an_input_too_long_generation_worker_error_returns_400() {+ let err = StreamingDriverErr::WorkerError {+ code: INPUT_TOO_LONG_ERROR_CODE.to_string(),+ message: "the rendered prompt exceeds the model's input limit".to_string(),+ param: Some("prompt".to_string()),+ retry_after_s: None,+ request_id: "req-too-long-1".to_string(),+ attempt_id: "att-too-long-1".to_string(),+ };+ let response = build_streaming_error_response(&err);++ assert_eq!(response.status(), StatusCode::BAD_REQUEST);+ assert!(response.headers().get("retry-after").is_none());+ let body = axum::body::to_bytes(response.into_body(), 16 * 1024)+ .await+ .unwrap();+ let value: serde_json::Value = serde_json::from_slice(&body).unwrap();+ assert_eq!(value["error"]["code"], INPUT_TOO_LONG_ERROR_CODE);+ assert_eq!(value["error"]["type"], oai_type::CONTEXT_LENGTH_EXCEEDED);+ assert_eq!(+ value["error"]["message"],+ "the rendered prompt exceeds the model's input limit"+ );+ assert_eq!(value["error"]["attempt_id"], "att-too-long-1");+ }+#[tokio::test]async fn test_streaming_unsupported_field_preserves_exact_parameter() {let err = StreamingDriverErr::WorkerError {diff --git a/packages/sie_gateway/src/queue/streaming.rs b/packages/sie_gateway/src/queue/streaming.rsindex c49768f09..9dc4c97e0 100644--- a/packages/sie_gateway/src/queue/streaming.rs+++ b/packages/sie_gateway/src/queue/streaming.rs@@ -321,6 +321,7 @@ pub(crate) fn client_safe_worker_error_code(code: &str) -> &'static str {match code {"inference_error" => "inference_error","grammar_compile_failed" => "grammar_compile_failed",+ "INPUT_TOO_LONG" => "INPUT_TOO_LONG","MODEL_LOADING" => "MODEL_LOADING","MODEL_OUTPUT_PARSE_ERROR" => "MODEL_OUTPUT_PARSE_ERROR","RESOURCE_EXHAUSTED" => "RESOURCE_EXHAUSTED",@@ -1435,11 +1436,37 @@ mod tests {assert!(rust_params.is_subset(&python_params));}+ #[test]+ fn test_every_code_the_worker_publishes_as_client_safe_is_kept() {+ let python_source =+ include_str!("../../../sie_server/src/sie_server/adapters/_generation_base.py");+ let declaration = python_source+ .split_once("_CLIENT_SAFE_GENERATION_ERROR_CODES = frozenset(")+ .expect("Python client-safe generation error codes must exist")+ .1+ .split_once('{')+ .expect("Python client-safe generation error codes must open")+ .1+ .split_once('}')+ .expect("Python client-safe generation error codes must close")+ .0;+ let python_codes: BTreeSet<_> = declaration+ .lines()+ .filter_map(|line| line.trim().strip_prefix('"')?.strip_suffix("\","))+ .collect();++ assert!(python_codes.contains("INPUT_TOO_LONG"));+ for code in python_codes {+ assert_eq!(client_safe_worker_error_code(code), code, "{code}");+ }+ }+#[test]fn test_worker_error_public_contract_preserves_only_sanctioned_codes() {for code in ["inference_error","grammar_compile_failed",+ "INPUT_TOO_LONG","MODEL_LOADING","MODEL_OUTPUT_PARSE_ERROR","RESOURCE_EXHAUSTED",