Skip to main content

systemprompt_files/models/
image_metadata.rs

1use serde::{Deserialize, Serialize};
2use systemprompt_identifiers::AiRequestId;
3
4#[derive(Debug, Clone, Default, Serialize, Deserialize)]
5pub struct ImageMetadata {
6    #[serde(default, skip_serializing_if = "Option::is_none")]
7    pub width: Option<u32>,
8
9    #[serde(default, skip_serializing_if = "Option::is_none")]
10    pub height: Option<u32>,
11
12    #[serde(default, skip_serializing_if = "Option::is_none")]
13    pub alt_text: Option<String>,
14
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    pub description: Option<String>,
17
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub generation: Option<ImageGenerationInfo>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct ImageGenerationInfo {
24    pub prompt: String,
25    pub model: String,
26    pub provider: String,
27
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub resolution: Option<String>,
30
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub aspect_ratio: Option<String>,
33
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub generation_time_ms: Option<i32>,
36
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub cost_estimate: Option<f32>,
39
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub request_id: Option<String>,
42}
43
44impl ImageMetadata {
45    pub const fn new() -> Self {
46        Self {
47            width: None,
48            height: None,
49            alt_text: None,
50            description: None,
51            generation: None,
52        }
53    }
54
55    pub const fn with_dimensions(mut self, width: u32, height: u32) -> Self {
56        self.width = Some(width);
57        self.height = Some(height);
58        self
59    }
60
61    pub fn with_alt_text(mut self, alt: impl Into<String>) -> Self {
62        self.alt_text = Some(alt.into());
63        self
64    }
65
66    pub fn with_description(mut self, desc: impl Into<String>) -> Self {
67        self.description = Some(desc.into());
68        self
69    }
70
71    pub fn with_generation(mut self, generation: ImageGenerationInfo) -> Self {
72        self.generation = Some(generation);
73        self
74    }
75}
76
77impl ImageGenerationInfo {
78    pub fn new(
79        prompt: impl Into<String>,
80        model: impl Into<String>,
81        provider: impl Into<String>,
82    ) -> Self {
83        Self {
84            prompt: prompt.into(),
85            model: model.into(),
86            provider: provider.into(),
87            resolution: None,
88            aspect_ratio: None,
89            generation_time_ms: None,
90            cost_estimate: None,
91            request_id: None,
92        }
93    }
94
95    pub fn with_resolution(mut self, resolution: impl Into<String>) -> Self {
96        self.resolution = Some(resolution.into());
97        self
98    }
99
100    pub fn with_aspect_ratio(mut self, aspect_ratio: impl Into<String>) -> Self {
101        self.aspect_ratio = Some(aspect_ratio.into());
102        self
103    }
104
105    pub const fn with_generation_time(mut self, time_ms: i32) -> Self {
106        self.generation_time_ms = Some(time_ms);
107        self
108    }
109
110    pub const fn with_cost_estimate(mut self, cost: f32) -> Self {
111        self.cost_estimate = Some(cost);
112        self
113    }
114
115    pub fn with_request_id(mut self, request_id: &AiRequestId) -> Self {
116        self.request_id = Some(request_id.as_str().to_string());
117        self
118    }
119}