Summary
Refactored Image Object
Description
In the case of the original image objects, we initialized them by passing both base64 and URL as constructor arguments, and returned their values through the getUrl and getBase64 methods.
However, this approach made it challenging to clearly indicate small differences between various providers leading to scalability issues when adding new types beyond base64 and URL.
To solve this, we have separated the original Image object into the Image and ImageType interfaces. Each module defines an enum that implements the ImageType interface (e.g., OpenAiImageType, etc.), allowing us to distinguish between the image's provider and format. This enum can be flexibly applied to situations like the Request's Response Format.
// example code
(req, res) -> {
return switch(req.responseFormat()) {
case URL -> new MyUrlImage(res.data());
case B64 -> new MyBase64Image(res.data());
default -> throw new MyException("Unsupported type")
}
}
Moreover, through the Image interface, all image objects can be uniformly treated, making the design easily adaptable even when new response formats or providers are added.
Please kindly review the proposed structure change to resolve this issue.
I am requesting your review as you are the most recent committer to this file. @markpollack
Thank you.
Comment From: markpollack
Thanks, trying to catch up on many things, i'll get to it. Appreciate the PR.