ai_json_template/
ai_json_template_for_vec.rs1crate::ix!();
3
4impl<T> AiJsonTemplate for Vec<T>
10where
11 T: Send + Sync + AiJsonTemplate + 'static,
12{
13 fn to_template() -> JsonValue {
14 trace!(
15 "AiJsonTemplate::to_template for Vec<{}>",
16 type_name::<T>()
17 );
18
19 let mut obj = serde_json::Map::new();
20 obj.insert(
21 "type".to_string(),
22 JsonValue::String("array_of".to_string())
23 );
24
25 obj.insert(
26 "generation_instructions".to_string(),
27 JsonValue::String(format!("Provide a JSON array of items, each conforming to {}.", type_name::<T>()))
28 );
29
30 obj.insert("required".to_string(), JsonValue::Bool(true));
32
33 let item_schema = T::to_template();
35 obj.insert("item_template".to_string(), item_schema);
36
37 JsonValue::Object(obj)
38 }
39}
40
41impl<T> AiJsonTemplateWithJustification for Vec<T>
47where
48 T: Send + Sync + AiJsonTemplateWithJustification + 'static,
49{
50 fn to_template_with_justification() -> JsonValue {
51 trace!(
52 "AiJsonTemplateWithJustification::to_template_with_justification for Vec<{}>",
53 type_name::<T>()
54 );
55
56 let mut obj = serde_json::Map::new();
57
58 obj.insert(
59 "type".to_string(),
60 JsonValue::String("array_of".to_string())
61 );
62
63 obj.insert("required".to_string(), JsonValue::Bool(true));
64
65 obj.insert("has_justification".to_string(), JsonValue::Bool(true));
67
68 obj.insert(
69 "generation_instructions".to_string(),
70 JsonValue::String(format!("Provide a JSON array of items, each conforming to {}. We do not want you to justify each individual element.", type_name::<T>()))
71 );
72
73 let item_schema = T::to_template_with_justification();
75 obj.insert("item_template".to_string(), item_schema);
76
77 JsonValue::Object(obj)
78 }
79}