ai_providers/openai/request/input_models/
input_reference.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
4pub struct InputReference {
5 pub id: String,
6 #[serde(rename = "type")]
7 #[serde(skip_serializing_if = "Option::is_none")]
8 pub type_field: Option<String>,
9}
10
11impl InputReference {
12 pub fn new(id: impl Into<String>) -> Self {
13 Self {
14 id: id.into(),
15 type_field: None,
16 }
17 }
18
19 pub fn insert_type(mut self) -> Self {
20 self.type_field = Some("item_reference".to_string());
21 self
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn test_json_values() {
31 let input_reference = InputReference::new("123").insert_type();
32 let json_value = serde_json::to_value(&input_reference).unwrap();
33 assert_eq!(
34 json_value,
35 serde_json::json!({
36 "id": "123",
37 "type": "item_reference"
38 })
39 );
40 }
41}