-
Notifications
You must be signed in to change notification settings - Fork 10
Enhance image compression handling and error logging #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR aims to enhance image compression handling by adding null checks, error logging, and improving media type validation. It also adjusts LLM request parameters (temperature, min_p, top_p) for OpenAI-compatible backends and adds trailing commas to Ollama options objects.
Key Changes:
- Added null safety checks and error logging to the
CompressImageForVisionmethod - Updated media type validation to check for
MediaMetaType.ImageandMediaMetaType.Animation - Modified OpenAI-compatible request parameters: increased temperature to 1.1, added min_p=0.05, and adjusted top_p values
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Image image = Image.FromDataString($"data:{media.MediaType};base64,{media.Data}"); | ||
| // Skip compression for videos etc.. | ||
| if (image.Type != Image.ImageType.IMAGE) | ||
| Image image = Image.FromDataString($"data:{media.MediaType};base64,{media.Data}") as SwarmUI.Utils.Image; |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The redundant cast as SwarmUI.Utils.Image is unnecessary since Image.FromDataString() already returns a SwarmUI.Utils.Image type (as defined by the using alias on line 4). This cast will always succeed or return null, making the null check on line 71 potentially misleading about the actual failure mode.
| Image image = Image.FromDataString($"data:{media.MediaType};base64,{media.Data}") as SwarmUI.Utils.Image; | |
| Image image = Image.FromDataString($"data:{media.MediaType};base64,{media.Data}"); |
| var imageFile = new Image(img) as SwarmUI.Media.ImageFile; | ||
| if (imageFile == null) | ||
| { | ||
| Logs.Error("Failed to convert image to ImageFile."); | ||
| return media.Data; | ||
| } | ||
| var compressedImage = imageFile.ConvertTo(targetFormat, quality: quality); |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast from Image to SwarmUI.Media.ImageFile appears problematic. Based on line 4, Image is aliased to SwarmUI.Utils.Image, not SwarmUI.Media.ImageFile. This cast will likely always fail and return null, causing the compression to always fall back to returning the original uncompressed data. The previous code created a new Image and called ConvertTo directly on it, which was the correct approach.
| var imageFile = new Image(img) as SwarmUI.Media.ImageFile; | |
| if (imageFile == null) | |
| { | |
| Logs.Error("Failed to convert image to ImageFile."); | |
| return media.Data; | |
| } | |
| var compressedImage = imageFile.ConvertTo(targetFormat, quality: quality); | |
| var compressedImage = image.ConvertTo(targetFormat, quality: quality); |
BackendSchema.cs
Outdated
| temperature = 1.0, | ||
| temperature = 1.1, | ||
| min_p=0.05, | ||
| top_p=0.95, |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the equals sign. Should be top_p = 0.95 for consistency with the spacing used in other parameters.
| top_p=0.95, | |
| top_p = 0.95, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
Branch has merge conflicts? |
4f3769f to
76b7e16
Compare
|
Yeah sorry about that. I vibe coded this when the compile was failing under v0.9.7.3 |
Improve image compression by adding error handling for unsupported media types and enhancing logging for failures. Adjust parameters for requests to improve performance and reliability.