-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #1593 SpringBoot scanBasePackages does not take effect (#36)
Changes Made: - add scanBasePackages(class) as basePackages - unit test Relevant Links: - langchain4j/langchain4j#1593
- Loading branch information
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...angchain4j/service/spring/mode/automatic/scanPackages/aiService/ScanPackageAiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.scanPackages.aiService; | ||
|
||
import dev.langchain4j.service.spring.AiService; | ||
|
||
@AiService | ||
public interface ScanPackageAiService { | ||
|
||
String chat(String userMessage); | ||
} |
12 changes: 12 additions & 0 deletions
12
.../service/spring/mode/automatic/scanPackages/package1/ScanPackageAiServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.scanPackages.package1; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication(scanBasePackages = {"dev.langchain4j.service.spring.mode.automatic.scanPackages.aiService"}) | ||
public class ScanPackageAiServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ScanPackageAiServiceApplication.class, args); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ngchain4j/service/spring/mode/automatic/scanPackages/package1/ScanPackageAiServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.scanPackages.package1; | ||
|
||
import dev.langchain4j.service.spring.AiServicesAutoConfig; | ||
import dev.langchain4j.service.spring.mode.automatic.scanPackages.aiService.ScanPackageAiService; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static dev.langchain4j.service.spring.mode.ApiKeys.OPENAI_API_KEY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ScanPackageAiServiceIT { | ||
|
||
ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(AiServicesAutoConfig.class)); | ||
|
||
@Test | ||
void should_create_AI_service_that_use_scanPackages_value() { | ||
|
||
contextRunner | ||
.withPropertyValues( | ||
"langchain4j.open-ai.chat-model.api-key=" + OPENAI_API_KEY, | ||
"langchain4j.open-ai.chat-model.max-tokens=20", | ||
"langchain4j.open-ai.chat-model.temperature=0.0" | ||
) | ||
.withUserConfiguration(ScanPackageAiServiceApplication.class) | ||
.run(context -> { | ||
|
||
// given | ||
ScanPackageAiService aiService = context.getBean(ScanPackageAiService.class); | ||
|
||
// when | ||
String answer = aiService.chat("What is the capital of Germany?"); | ||
|
||
// then | ||
assertThat(answer).containsIgnoringCase("Berlin"); | ||
}); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
.../service/spring/mode/automatic/scanPackages/package2/ScanPackageAiServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.scanPackages.package2; | ||
|
||
import dev.langchain4j.service.spring.mode.automatic.scanPackages.aiService.ScanPackageAiService; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication(scanBasePackageClasses = ScanPackageAiService.class) | ||
public class ScanPackageAiServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ScanPackageAiServiceApplication.class, args); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ngchain4j/service/spring/mode/automatic/scanPackages/package2/ScanPackageAiServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.langchain4j.service.spring.mode.automatic.scanPackages.package2; | ||
|
||
import dev.langchain4j.service.spring.AiServicesAutoConfig; | ||
import dev.langchain4j.service.spring.mode.automatic.scanPackages.aiService.ScanPackageAiService; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static dev.langchain4j.service.spring.mode.ApiKeys.OPENAI_API_KEY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ScanPackageAiServiceIT { | ||
|
||
ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(AiServicesAutoConfig.class)); | ||
|
||
@Test | ||
void should_create_AI_service_that_use_scanPackageClass_value() { | ||
|
||
contextRunner | ||
.withPropertyValues( | ||
"langchain4j.open-ai.chat-model.api-key=" + OPENAI_API_KEY, | ||
"langchain4j.open-ai.chat-model.max-tokens=20", | ||
"langchain4j.open-ai.chat-model.temperature=0.0" | ||
) | ||
.withUserConfiguration(ScanPackageAiServiceApplication.class) | ||
.run(context -> { | ||
|
||
// given | ||
ScanPackageAiService aiService = context.getBean(ScanPackageAiService.class); | ||
|
||
// when | ||
String answer = aiService.chat("What is the capital of Germany?"); | ||
|
||
// then | ||
assertThat(answer).containsIgnoringCase("Berlin"); | ||
}); | ||
} | ||
|
||
} |