mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 09:28:11 +00:00
Grok, but the image resolutions appear broken
This commit is contained in:
1 parent
c11b04c087
commit
5cb45c219c
4 files changed
+57
-78
No files matched your search
+28
@@ -0,0 +1,28 @@
|
||||
use crate::core::api_adapters::aspect_ratio::common_aspect_ratio::CommonAspectRatio;
|
||||
use grok_client::requests::image_websocket::messages::websocket_client_message::ClientMessageAspectRatio;
|
||||
|
||||
pub fn aspect_ratio_to_grok_image(aspect_ratio: CommonAspectRatio) -> ClientMessageAspectRatio {
|
||||
match aspect_ratio {
|
||||
// Exact
|
||||
CommonAspectRatio::Square => ClientMessageAspectRatio::Square,
|
||||
CommonAspectRatio::WideThreeByTwo => ClientMessageAspectRatio::WideThreeByTwo,
|
||||
CommonAspectRatio::TallTwoByThree => ClientMessageAspectRatio::TallTwoByThree,
|
||||
|
||||
// Non-matching
|
||||
CommonAspectRatio::Auto => ClientMessageAspectRatio::Square,
|
||||
|
||||
// Mismatch - wide
|
||||
CommonAspectRatio::Wide
|
||||
| CommonAspectRatio::WideFiveByFour
|
||||
| CommonAspectRatio::WideFourByThree
|
||||
| CommonAspectRatio::WideSixteenByNine
|
||||
| CommonAspectRatio::WideTwentyOneByNine => ClientMessageAspectRatio::WideThreeByTwo,
|
||||
|
||||
// Mismatch - tall
|
||||
CommonAspectRatio::Tall
|
||||
| CommonAspectRatio::TallFourByFive
|
||||
| CommonAspectRatio::TallThreeByFour
|
||||
| CommonAspectRatio::TallNineBySixteen
|
||||
| CommonAspectRatio::TallNineByTwentyOne => ClientMessageAspectRatio::TallTwoByThree,
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod aspect_ratio_to_artcraft_nano_banana_pro;
|
||||
pub mod aspect_ratio_to_artcraft_nano_banana;
|
||||
pub mod aspect_ratio_to_artcraft_nano_banana;
|
||||
pub mod aspect_ratio_to_grok_image;
|
||||
+21
-77
@@ -1,3 +1,4 @@
|
||||
use crate::core::api_adapters::aspect_ratio::convert::aspect_ratio_to_grok_image::aspect_ratio_to_grok_image;
|
||||
use crate::core::commands::enqueue::generate_error::GenerateError;
|
||||
use crate::core::commands::enqueue::task_enqueue_success::TaskEnqueueSuccess;
|
||||
use crate::core::commands::enqueue::text_to_image::enqueue_text_to_image_command::{EnqueueTextToImageRequest, TextToImageSize};
|
||||
@@ -54,18 +55,12 @@ pub async fn handle_grok(
|
||||
.map(|prompt| prompt.trim().to_string())
|
||||
.unwrap_or_else(|| "".to_string());
|
||||
|
||||
let aspect_ratio = match request.aspect_ratio {
|
||||
None => ClientMessageAspectRatio::Square,
|
||||
Some(TextToImageSize::Auto) => ClientMessageAspectRatio::Square,
|
||||
Some(TextToImageSize::Square) => ClientMessageAspectRatio::Square,
|
||||
Some(TextToImageSize::Wide) => ClientMessageAspectRatio::WideThreeByTwo,
|
||||
Some(TextToImageSize::Tall) => ClientMessageAspectRatio::TallTwoByThree,
|
||||
};
|
||||
let aspect_ratio = get_aspect_ratio(request);
|
||||
|
||||
grok_image_prompt_queue.enqueue(PromptItem {
|
||||
task_id: job_id.clone(),
|
||||
prompt,
|
||||
aspect_ratio,
|
||||
aspect_ratio: aspect_ratio.unwrap_or(ClientMessageAspectRatio::Square),
|
||||
})?;
|
||||
|
||||
Ok(TaskEnqueueSuccess {
|
||||
@@ -76,73 +71,22 @@ pub async fn handle_grok(
|
||||
})
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// fn handle_midjourney_errors(
|
||||
// app: &AppHandle,
|
||||
// maybe_errors: Option<Vec<TextToImageError>>
|
||||
// ) -> Result<TaskEnqueueSuccess, GenerateError> {
|
||||
// if let Some(errors) = maybe_errors {
|
||||
// if !errors.is_empty() {
|
||||
// let messages: Vec<String> = errors.iter()
|
||||
// .map(|e| format!("{:?}", e))
|
||||
// .collect();
|
||||
//
|
||||
// let combined_message = messages.join("; ");
|
||||
//
|
||||
// let event = FlashUserInputErrorEvent {
|
||||
// message: format!("Midjourney Error: {}", combined_message),
|
||||
// };
|
||||
//
|
||||
// if let Err(err) = event.send(&app) {
|
||||
// error!("Failed to send FlashUserInputErrorEvent: {:?}", err); // Fail open
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Err(GenerateError::ProviderFailure(ProviderFailureReason::MidjourneyJobEnqueueFailed))
|
||||
// }
|
||||
fn get_aspect_ratio(request: &EnqueueTextToImageRequest) -> Option<ClientMessageAspectRatio> {
|
||||
if let Some(common_aspect_ratio) = request.common_aspect_ratio {
|
||||
// Handle modern aspect ratio
|
||||
let aspect = aspect_ratio_to_grok_image(common_aspect_ratio);
|
||||
return Some(aspect);
|
||||
}
|
||||
|
||||
//async fn get_websocket(app: &AppHandle, creds_manager: &GrokCredentialManager, websocket_manager: &GrokWebsocketManager) -> Result<GrokWebsocket, GenerateError> {
|
||||
// let maybe_websocket = websocket_manager.grab_websocket()?;
|
||||
//
|
||||
// let websocket = match maybe_websocket {
|
||||
// Some(websocket) => websocket,
|
||||
// None => {
|
||||
// let cookies = match creds_manager.maybe_copy_cookie_store() {
|
||||
// Ok(Some(cookies)) => cookies.to_cookie_string(),
|
||||
// Ok(None) => {
|
||||
// error!("Grok credentials not found.");
|
||||
// ShowProviderLoginModalEvent::send_for_provider(GenerationProvider::Grok, &app);
|
||||
// return Err(GenerateError::needs_grok_credentials());
|
||||
// }
|
||||
// Err(err) => {
|
||||
// error!("Error reading Midjourney credentials: {:?}", err);
|
||||
// ShowProviderLoginModalEvent::send_for_provider(GenerationProvider::Grok, &app);
|
||||
// return Err(GenerateError::needs_grok_credentials());
|
||||
// },
|
||||
// };
|
||||
//
|
||||
// info!("Creating Grok websocket...");
|
||||
//
|
||||
// let create_websocket_result = create_listen_websocket(CreateListenWebsocketArgs {
|
||||
// cookies: &cookies,
|
||||
// }).await;
|
||||
//
|
||||
// let websocket = match create_websocket_result {
|
||||
// Ok(websocket) => GrokWebsocket::new(websocket),
|
||||
// Err(err) => {
|
||||
// error!("Error creating websocket: {:?}", err);
|
||||
// ShowProviderLoginModalEvent::send_for_provider(GenerationProvider::Grok, &app);
|
||||
// return Err(GenerateError::needs_grok_credentials());
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// info!("Setting managed Grok websocket...");
|
||||
// websocket_manager.set_websocket(websocket.clone())?;
|
||||
//
|
||||
// websocket
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// Ok(websocket)
|
||||
//}
|
||||
if let Some(aspect_ratio) = request.aspect_ratio {
|
||||
// Handle deprecated aspect ratio
|
||||
return match aspect_ratio {
|
||||
TextToImageSize::Auto => Some(ClientMessageAspectRatio::Square),
|
||||
TextToImageSize::Square => Some(ClientMessageAspectRatio::Square),
|
||||
TextToImageSize::Wide => Some(ClientMessageAspectRatio::WideThreeByTwo),
|
||||
TextToImageSize::Tall => Some(ClientMessageAspectRatio::TallTwoByThree),
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -25,6 +25,12 @@ export const IMAGE_MODELS: ImageModel[] = [
|
||||
maxImagePromptCount: 6,
|
||||
progressBarTime: 10000,
|
||||
canChangeAspectRatio: true,
|
||||
defaultAspectRatio: CommonAspectRatio.Square,
|
||||
aspectRatios: [
|
||||
CommonAspectRatio.Square,
|
||||
CommonAspectRatio.WideThreeByTwo,
|
||||
CommonAspectRatio.TallTwoByThree,
|
||||
]
|
||||
}),
|
||||
new ImageModel({
|
||||
id: "midjourney",
|
||||
|
||||
Reference in new issue
Block a user