async_openai/types/images/
stream.rs1use serde::{Deserialize, Serialize};
2
3use crate::types::images::{
4 ImageBackground, ImageGenUsage, ImageOutputFormat, ImageQuality, ImageSize,
5};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ImageGenPartialImageEvent {
10 pub b64_json: String,
12 pub created_at: u64,
14 pub size: ImageSize,
16 pub quality: ImageQuality,
18 pub background: ImageBackground,
20 pub output_format: ImageOutputFormat,
22 pub partial_image_index: u8,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct ImageGenCompletedEvent {
29 pub b64_json: String,
31 pub created_at: u64,
33 pub size: ImageSize,
35 pub quality: ImageQuality,
37 pub background: ImageBackground,
39 pub output_format: ImageOutputFormat,
41 pub usage: ImageGenUsage,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(tag = "type")]
47pub enum ImageGenStreamEvent {
48 #[serde(rename = "image_generation.partial_image")]
50 PartialImage(ImageGenPartialImageEvent),
51 #[serde(rename = "image_generation.completed")]
53 Completed(ImageGenCompletedEvent),
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct ImageEditPartialImageEvent {
59 pub b64_json: String,
61 pub created_at: u64,
63 pub size: ImageSize,
65 pub quality: ImageQuality,
67 pub background: ImageBackground,
69 pub output_format: ImageOutputFormat,
71 pub partial_image_index: u8,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct ImageEditCompletedEvent {
78 pub b64_json: String,
80 pub created_at: u64,
82 pub size: ImageSize,
84 pub quality: ImageQuality,
86 pub background: ImageBackground,
88 pub output_format: ImageOutputFormat,
90 pub usage: ImageGenUsage,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(tag = "type")]
96pub enum ImageEditStreamEvent {
97 #[serde(rename = "image_edit.partial_image")]
99 PartialImage(ImageEditPartialImageEvent),
100 #[serde(rename = "image_edit.completed")]
102 Completed(ImageEditCompletedEvent),
103}
104
105#[cfg(feature = "_api")]
106pub type ImageEditStream = std::pin::Pin<
107 Box<dyn futures::Stream<Item = Result<ImageEditStreamEvent, crate::error::OpenAIError>> + Send>,
108>;
109
110#[cfg(feature = "_api")]
111pub type ImageGenStream = std::pin::Pin<
112 Box<dyn futures::Stream<Item = Result<ImageGenStreamEvent, crate::error::OpenAIError>> + Send>,
113>;
114
115#[cfg(feature = "_api")]
116macro_rules! impl_event_type {
117 ($($ty:ty => $event_type:expr),* $(,)?) => {
118 $(
119 impl crate::traits::EventType for $ty {
120 fn event_type(&self) -> &'static str {
121 $event_type
122 }
123 }
124 )*
125 };
126}
127
128#[cfg(feature = "_api")]
129impl_event_type! {
130 ImageGenPartialImageEvent => "image_generation.partial_image",
131 ImageGenCompletedEvent => "image_generation.completed",
132 ImageEditPartialImageEvent => "image_edit.partial_image",
133 ImageEditCompletedEvent => "image_edit.completed",
134}
135
136#[cfg(feature = "_api")]
137impl crate::traits::EventType for ImageGenStreamEvent {
138 fn event_type(&self) -> &'static str {
139 match self {
140 ImageGenStreamEvent::PartialImage(event) => event.event_type(),
141 ImageGenStreamEvent::Completed(event) => event.event_type(),
142 }
143 }
144}
145
146#[cfg(feature = "_api")]
147impl crate::traits::EventType for ImageEditStreamEvent {
148 fn event_type(&self) -> &'static str {
149 match self {
150 ImageEditStreamEvent::PartialImage(event) => event.event_type(),
151 ImageEditStreamEvent::Completed(event) => event.event_type(),
152 }
153 }
154}