use serde::{Deserialize, Serialize};
use crate::types::question::Questions;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SystemOneRequest {
pub state: serde_json::Value,
pub model: String,
pub questions: Questions,
}
impl SystemOneRequest {
#[must_use]
pub fn new(state: serde_json::Value, questions: Questions) -> Self {
Self {
state,
model: String::new(),
questions,
}
}
#[must_use]
pub fn with_model(mut self, model: impl Into<String>) -> Self {
self.model = model.into();
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::question::Question;
use serde_json::json;
#[test]
fn serializes_state_model_questions() {
let mut questions = Questions::new();
questions.insert("urgent".into(), Question::noul("urgent?"));
let req = SystemOneRequest::new(json!("hello"), questions).with_model("jev-latest");
let value = serde_json::to_value(&req).unwrap();
assert_eq!(value["state"], json!("hello"));
assert_eq!(value["model"], "jev-latest");
assert_eq!(value["questions"]["urgent"]["type"], "noul");
}
}