Skip to content

feat: add hugging face text to image integration #1162

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

d-lobo
Copy link

@d-lobo d-lobo commented Aug 4, 2024

Hi,

I was experimenting with Spring AI and some models deployed on hugging face, realizing that a lot of stuff is missing for huggingface explaining the reason for this PR.
The changes provide a baseline implementation for querying text-to-image models deployed on huggingface.
I tried to align the code as much as possible on the existing implementation for chat models, however in order to support different image types on the api, I was required to add a custom template for swagger codegen, since the default templates generate a priorization for application/json with regards to the accept header (which in turn allows the generated api to retrieve base64 encoded strings only, leading to the fact, that only PNG images could be generated). This seems unfavorable for an text-to-image api. Thus the modified templates adds the possibility to specify the desired image type on requesting the model.

  • adds huggingface text-to-image integration
  • provided modified template for swagger codegen (only used for text-to-image inference api)

@markpollack
Copy link
Member

thanks you very much, i did the original quick pass around hugging face and appreciate this improvement.

@d-lobo
Copy link
Author

d-lobo commented Sep 20, 2024

thank you for your response. I wasn't sure if this PR would be considered useful at this moment. However I think I have to make smaller adjustments, as some aspects of the codebase have changed in the meantime, due to other merged PRs, thus marking it as draft. Will take some time, since I'm on vacation right now :D

@d-lobo d-lobo marked this pull request as draft September 20, 2024 08:48
@d-lobo d-lobo marked this pull request as ready for review October 27, 2024 17:06
@d-lobo
Copy link
Author

d-lobo commented Oct 27, 2024

@markpollack should be now ready to review. If you see any room for improvements, kindly let me know

@d-lobo d-lobo force-pushed the add-huggingface-text-to-image branch from 97e4628 to 89ffb0c Compare November 20, 2024 22:31
@d-lobo d-lobo force-pushed the add-huggingface-text-to-image branch from 89ffb0c to 0038772 Compare November 20, 2024 22:48
import org.springframework.ai.huggingface.model.chat.AllOfGenerateResponseDetails;
import org.springframework.ai.huggingface.model.chat.GenerateParameters;
import org.springframework.ai.huggingface.model.chat.GenerateRequest;
import org.springframework.ai.huggingface.model.chat.GenerateResponse;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like your code style settings don't align with those of the project. None of these lines should change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not related to code style, I have changed the buildpath in openapi codegen configuration to improve the package structure of generated code. Is this an undesired change ?
However I used the default code styles of my IDE, changed it now to settings mentioned here: https://github.com/spring-projects/spring-framework/wiki/IntelliJ-IDEA-Editor-Settings

@nealeu
Copy link

nealeu commented Jan 3, 2025

Probably going to clash heavily with #486, but then would be a nice addition IMO

@d-lobo
Copy link
Author

d-lobo commented Jan 10, 2025

I could rebase my work on the branch of #486 and adapt accordingly, if this would help. We could also wait until #486 is merged and I update and adapt my branch. Just give me a hint, how to go forward

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