2025-05-10 09:18:01 +03:00
|
|
|
use mxlink::mime;
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
pub struct ImageGenerationParams {
|
Fix sticker generation for newer GPT image models
Sticker generation was failing when using newer GPT image models
(gpt-image-1, gpt-image-1-mini, gpt-image-1.5). The issue occurred
because stickers requested 256x256 size, but these models only support
1024x1024, 1536x1024, 1024x1536, and auto.
To reproduce, send `!bai sticker Something` to an agent configured
with a GPT image model. The error was:
invalid_request_error: Invalid value: '256x256'. Supported values
are: '1024x1024', '1024x1536', '1536x1024', and 'auto'. (param: size)
(code: invalid_value)
The fix replaces the hardcoded 256x256 size override with a
`smallest_size_possible` flag, letting each provider determine the
appropriate sticker size based on the model being used.
The `openai_compat` provider still defaults to requesting 256x256 in all cases
(regardless of model name).
2026-02-04 02:36:50 +02:00
|
|
|
pub smallest_size_possible: bool,
|
2025-05-10 09:18:01 +03:00
|
|
|
|
|
|
|
|
pub cheaper_model_switching_allowed: bool,
|
|
|
|
|
|
|
|
|
|
pub cheaper_quality_switching_allowed: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ImageGenerationParams {
|
Fix sticker generation for newer GPT image models
Sticker generation was failing when using newer GPT image models
(gpt-image-1, gpt-image-1-mini, gpt-image-1.5). The issue occurred
because stickers requested 256x256 size, but these models only support
1024x1024, 1536x1024, 1024x1536, and auto.
To reproduce, send `!bai sticker Something` to an agent configured
with a GPT image model. The error was:
invalid_request_error: Invalid value: '256x256'. Supported values
are: '1024x1024', '1024x1536', '1536x1024', and 'auto'. (param: size)
(code: invalid_value)
The fix replaces the hardcoded 256x256 size override with a
`smallest_size_possible` flag, letting each provider determine the
appropriate sticker size based on the model being used.
The `openai_compat` provider still defaults to requesting 256x256 in all cases
(regardless of model name).
2026-02-04 02:36:50 +02:00
|
|
|
pub fn with_smallest_size_possible(mut self, value: bool) -> Self {
|
|
|
|
|
self.smallest_size_possible = value;
|
2025-05-10 09:18:01 +03:00
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_cheaper_model_switching_allowed(mut self, value: bool) -> Self {
|
|
|
|
|
self.cheaper_model_switching_allowed = value;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_cheaper_quality_switching_allowed(mut self, value: bool) -> Self {
|
|
|
|
|
self.cheaper_quality_switching_allowed = value;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ImageGenerationResult {
|
|
|
|
|
pub bytes: Vec<u8>,
|
|
|
|
|
pub mime_type: mime::Mime,
|
|
|
|
|
pub revised_prompt: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
2025-05-10 11:47:50 +03:00
|
|
|
pub struct ImageEditParams {}
|
2025-05-10 09:18:01 +03:00
|
|
|
|
|
|
|
|
pub struct ImageEditResult {
|
|
|
|
|
pub bytes: Vec<u8>,
|
|
|
|
|
pub mime_type: mime::Mime,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ImageSource {
|
|
|
|
|
pub filename: String,
|
|
|
|
|
pub bytes: Vec<u8>,
|
|
|
|
|
pub mime_type: mime::Mime,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ImageSource {
|
|
|
|
|
pub fn new(filename: String, bytes: Vec<u8>, mime_type: mime::Mime) -> Self {
|
2025-05-10 11:47:50 +03:00
|
|
|
Self {
|
|
|
|
|
filename,
|
|
|
|
|
bytes,
|
|
|
|
|
mime_type,
|
|
|
|
|
}
|
2025-05-10 09:18:01 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 10:31:06 +02:00
|
|
|
impl From<ImageSource> for async_openai::types::images::ImageInput {
|
2025-05-10 09:33:44 +03:00
|
|
|
fn from(value: ImageSource) -> Self {
|
2025-11-30 10:31:06 +02:00
|
|
|
async_openai::types::images::ImageInput::from_vec_u8(value.filename, value.bytes)
|
2025-05-10 09:18:01 +03:00
|
|
|
}
|
|
|
|
|
}
|