Skip to content
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

AiService support @Profile #41

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

Martin7-1
Copy link
Contributor

Close langchain4j#1430

  1. Support @AiService with @Profile.

Copy link
Owner

@langchain4j langchain4j left a comment

Choose a reason for hiding this comment

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

@Martin7-1 thank you!

if (aiServiceClass.isAnnotationPresent(Profile.class)) {
Profile profileAnnotation = aiServiceClass.getAnnotation(Profile.class);
String[] profiles = profileAnnotation.value();
if (!environment.matchesProfiles(profiles)) {
Copy link
Owner

Choose a reason for hiding this comment

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

is this filtering really required twice? (also in AiServiceScannerProcessor)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. Good question. Maybe we only need to filter it in AiServiceScannerProcessor to skip scanning the BeanDefinition with AiService.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Now only the AiServiceScannerProcessor do filtering with @Profile

Copy link
Owner

Choose a reason for hiding this comment

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

Would it be possible to filter only in AiServicesAutoConfig?
AiServiceScannerProcessor is dealing with packages for scanning, AiServicesAutoConfig is the one who decides if @AiService bean should be created or not

if (aiServiceClass.isAnnotationPresent(Profile.class)) {
Profile profileAnnotation = aiServiceClass.getAnnotation(Profile.class);
String[] profiles = profileAnnotation.value();
if (!environment.matchesProfiles(profiles)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Would it be possible to filter only in AiServicesAutoConfig?
AiServiceScannerProcessor is dealing with packages for scanning, AiServicesAutoConfig is the one who decides if @AiService bean should be created or not

@Martin7-1
Copy link
Contributor Author

Martin7-1 commented Sep 17, 2024

@langchain4j At first I did want to do filtering in AiServiceAutoConfig, but when I implemented it I ran into: Failed to instantiate [dev.langchain4j.service.spring.mode.automatic.withProfiles. AiServiceWithProfiles]: Specified class is an interface. It seems that Spring Boot still wants to find an implementation of @AiService and register it. so I think we should filter it during the registration phase of the BeanDefinition.

I haven't found a way to do this in AiServiceAutoConfig yet, let me know if you know one.

Copy link
Owner

@langchain4j langchain4j left a comment

Choose a reason for hiding this comment

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

@Martin7-1 great job, thank you!

@langchain4j langchain4j merged commit 3648f2c into langchain4j:main Sep 18, 2024
0 of 5 checks passed
langchain4j added a commit that referenced this pull request Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] @AiService cannot be used along with the @Profile annotation
2 participants