Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions lib/llm/src/http/service/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,17 +2786,9 @@ mod tests {
assert!(request.unsupported_fields.contains_key("documents"));
assert!(request.unsupported_fields.contains_key("chat_template"));

// Unsupported fields should now produce a warning but not an error
let result = validate_chat_completion_fields_generic(&request);
assert!(result.is_err());
if let Err(error_response) = result {
assert_eq!(error_response.0, StatusCode::BAD_REQUEST);
let msg = &error_response.1.message;
assert!(msg.contains("Unsupported parameter"));
// Verify all fields appear in the error message
assert!(msg.contains("add_special_tokens"));
assert!(msg.contains("documents"));
assert!(msg.contains("chat_template"));
}
assert!(result.is_ok());
}

#[test]
Expand All @@ -2819,16 +2811,9 @@ mod tests {
);
assert!(request.unsupported_fields.contains_key("response_format"));

// Unsupported fields should now produce a warning but not an error
let result = validate_completion_fields_generic(&request);
assert!(result.is_err());
if let Err(error_response) = result {
assert_eq!(error_response.0, StatusCode::BAD_REQUEST);
let msg = &error_response.1.message;
assert!(msg.contains("Unsupported parameter"));
// Verify both fields appear in error message
assert!(msg.contains("add_special_tokens"));
assert!(msg.contains("response_format"));
}
assert!(result.is_ok());
}

#[tokio::test]
Expand Down
25 changes: 25 additions & 0 deletions lib/llm/src/protocols/openai/chat_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,29 @@ mod tests {
assert_eq!(output_options.skip_special_tokens, Some(skip_value));
}
}

#[test]
fn test_unsupported_fields_warn_not_error() {
use crate::engines::ValidateRequest;

let json_str = json!({
"model": "test-model",
"messages": [{"role": "user", "content": "Hello"}],
"add_special_tokens": true,
"prompt_cache_key": "key123",
"request_id": "req-456",
"chat_template": "custom"
});
let request: NvCreateChatCompletionRequest =
serde_json::from_value(json_str).expect("Failed to deserialize request");

// These fields should be captured as unsupported
assert!(request.unsupported_fields.contains_key("add_special_tokens"));
assert!(request.unsupported_fields.contains_key("prompt_cache_key"));
assert!(request.unsupported_fields.contains_key("request_id"));
assert!(request.unsupported_fields.contains_key("chat_template"));

// Validation should succeed (warn, not error)
assert!(ValidateRequest::validate(&request).is_ok());
}
}
8 changes: 6 additions & 2 deletions lib/llm/src/protocols/openai/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ pub const MAX_REPETITION_PENALTY: f32 = 2.0;
// Shared Fields
//

/// Validates that no unsupported fields are present in the request
/// Validates unsupported fields in the request.
/// Instead of rejecting requests with unsupported fields, this now logs a warning
/// and allows the request to proceed. This improves compatibility with clients
/// that send extra parameters (e.g. add_special_tokens, prompt_cache_key,
/// request_id, chat_template).
pub fn validate_no_unsupported_fields(
unsupported_fields: &std::collections::HashMap<String, serde_json::Value>,
) -> Result<(), anyhow::Error> {
Expand All @@ -106,7 +110,7 @@ pub fn validate_no_unsupported_fields(
.keys()
.map(|s| format!("`{}`", s))
.collect();
anyhow::bail!("Unsupported parameter(s): {}", fields.join(", "));
tracing::warn!("Ignoring unsupported parameter(s): {}", fields.join(", "));
}
Ok(())
}
Expand Down
Loading