use serde::{Deserialize, Serialize};
use crate::core::config::ResponseFormatConfig;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ResponseFormat {
#[default]
Passthrough,
WebSearchCall,
CodeInterpreterCall,
FileSearchCall,
}
impl From<ResponseFormatConfig> for ResponseFormat {
fn from(config: ResponseFormatConfig) -> Self {
match config {
ResponseFormatConfig::Passthrough => ResponseFormat::Passthrough,
ResponseFormatConfig::WebSearchCall => ResponseFormat::WebSearchCall,
ResponseFormatConfig::CodeInterpreterCall => ResponseFormat::CodeInterpreterCall,
ResponseFormatConfig::FileSearchCall => ResponseFormat::FileSearchCall,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_response_format_serde() {
let formats = vec![
(ResponseFormat::Passthrough, "\"passthrough\""),
(ResponseFormat::WebSearchCall, "\"web_search_call\""),
(
ResponseFormat::CodeInterpreterCall,
"\"code_interpreter_call\"",
),
(ResponseFormat::FileSearchCall, "\"file_search_call\""),
];
for (format, expected) in formats {
let serialized = serde_json::to_string(&format).unwrap();
assert_eq!(serialized, expected);
let deserialized: ResponseFormat = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, format);
}
}
#[test]
fn test_response_format_default() {
assert_eq!(ResponseFormat::default(), ResponseFormat::Passthrough);
}
}