Skip to content

Conversation

@JHZLO
Copy link
Contributor

@JHZLO JHZLO commented May 15, 2025

Summary

This PR refactors the stylePreset configuration logic in StabilityAiImageOptions.Builder to remove redundant assignments and ensure consistent merging behavior.

Motivation

  • Previously, stylePreset() could be called multiple times with potentially conflicting values.

  • The new implementation consolidates this into a single line using:

    .stylePreset(ModelOptionsUtils.mergeOption(
        runtimeOptions.getStyle(),
        defaultOptions.getStylePreset()))

This change ensures that if a runtime option is provided, it takes precedence; otherwise, the default is used—matching the behavior of other portable image options such as model, width, and responseFormat.

Why use getStyle() and not getStylePreset() in runtime options?

  • ImageOptions defines a getStyle() method, which is implemented in StabilityAiImageOptions as:
@Override
@JsonIgnore
public String getStyle() {
    return getStylePreset();
}
  • The @JsonIgnore annotation ensures that this method is excluded from JSON serialization, so the style field does not accidentally appear in the outgoing payload.
  • The actual JSON property used by the Stability API is style_preset, which is explicitly annotated:
@JsonProperty("style_preset")
private String stylePreset;
  • This implementation keeps the merging logic interface-compliant via getStyle(), while ensuring that only style_preset is serialized in API requests.

Impact

  • Improves clarity and predictability of the stylePreset merging process.
  • Prevents unintended overrides or inconsistencies due to multiple stylePreset() calls.
  • Ensures the correct field is serialized (style_preset) and avoids any accidental inclusion of an incorrect style field.

… builder

Replaces redundant or conflicting stylePreset assignments with a single mergeOption call using runtime style and default stylePreset.

Signed-off-by: Jhzlo <[email protected]>
@markpollack markpollack requested a review from sobychacko May 15, 2025 22:08
@markpollack markpollack added this to the 1.0.0 milestone May 15, 2025
@markpollack markpollack removed the request for review from sobychacko May 15, 2025 22:08
@sobychacko
Copy link
Contributor

Merged via 2721c9e.

@sobychacko sobychacko closed this May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants