[Frontend] Omit absent fields from /inference/v1/generate stream chunks (#57264)
Signed-off-by: aoshen02 <aoshen@inferact.ai> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
e6b1a5e5e3
commit
8538017f4b
@@ -679,6 +679,36 @@ mod tests {
|
||||
assert!(response.mm_placeholders.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stream_chunk_omits_absent_fields() {
|
||||
// Contract shared with the Python frontend: absent optional fields
|
||||
// are omitted from stream chunks, not serialized as null.
|
||||
let chunk = GenerateStreamResponse {
|
||||
request_id: "raw-1".to_string(),
|
||||
choices: vec![GenerateResponseStreamChoice {
|
||||
index: 0,
|
||||
logprobs: None,
|
||||
finish_reason: None,
|
||||
token_ids: vec![1],
|
||||
}],
|
||||
usage: None,
|
||||
prompt_token_ids: None,
|
||||
mm_placeholders: None,
|
||||
};
|
||||
|
||||
let json = serde_json::to_value(&chunk).expect("serialize chunk");
|
||||
|
||||
for key in ["usage", "prompt_token_ids", "mm_placeholders"] {
|
||||
assert!(json.get(key).is_none(), "{key} should be omitted");
|
||||
}
|
||||
for key in ["logprobs", "finish_reason"] {
|
||||
assert!(
|
||||
json["choices"][0].get(key).is_none(),
|
||||
"{key} should be omitted"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_mm_placeholders_returns_none_without_features() {
|
||||
assert!(extract_mm_placeholders(None).is_none());
|
||||
|
||||
Reference in New Issue
Block a user