use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CancelGenerationRequest {
pub request_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CancelGenerationResponse {
pub request_id: String,
pub cancelled: bool,
pub detail: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_verdict_survives_a_round_trip_and_keeps_both_states() {
for cancelled in [true, false] {
let response = CancelGenerationResponse {
request_id: "chatcmpl-1".to_string(),
cancelled,
detail: "…".to_string(),
};
let json = serde_json::to_string(&response).unwrap();
assert_eq!(
serde_json::from_str::<CancelGenerationResponse>(&json).unwrap(),
response
);
assert!(json.contains("\"cancelled\""), "{json}");
}
}
#[test]
fn the_request_names_only_the_id_the_server_already_stated() {
let parsed: CancelGenerationRequest =
serde_json::from_str(r#"{"request_id":"chatcmpl-abc"}"#).unwrap();
assert_eq!(parsed.request_id, "chatcmpl-abc");
}
}