From 86dcbfbbc1c717975ba68d5a8460df74e3f4d974 Mon Sep 17 00:00:00 2001 From: Mohamed Date: Sun, 10 Nov 2024 17:07:40 +0100 Subject: [PATCH] Generate LangChain4j sample --- .../domain/SampleLangChain4jModuleFactory.java | 11 +++++++---- .../primary/SampleLangChain4jModuleConfiguration.java | 1 - .../ChatResource.java.mustache} | 6 +++--- .../features/server/springboot/langchain4j.feature | 7 +++++++ 4 files changed, 17 insertions(+), 8 deletions(-) rename src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/{secondary/ChatController.java.mustache => primary/ChatResource.java.mustache} (78%) diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/domain/SampleLangChain4jModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/domain/SampleLangChain4jModuleFactory.java index 4ead66a68a0..608d59defdb 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/domain/SampleLangChain4jModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/domain/SampleLangChain4jModuleFactory.java @@ -5,27 +5,30 @@ import static tech.jhipster.lite.module.domain.JHipsterModule.toSrcMainJava; import tech.jhipster.lite.module.domain.JHipsterModule; +import tech.jhipster.lite.module.domain.file.JHipsterDestination; import tech.jhipster.lite.module.domain.file.JHipsterSource; import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties; import tech.jhipster.lite.shared.error.domain.Assert; public class SampleLangChain4jModuleFactory { + private static final String SAMPLE = "sample"; + private static final JHipsterSource SOURCE = from("server/springboot/mvc/sample/langchain4j"); - private static final String SECONDARY = "infrastructure/secondary"; - private static final String SECONDARY_DESTINATION = "sample/" + SECONDARY; + private static final String PRIMARY = "infrastructure/primary"; public JHipsterModule buildModule(JHipsterModuleProperties properties) { Assert.notNull("properties", properties); String packagePath = properties.packagePath(); + JHipsterDestination mainDestination = toSrcMainJava().append(packagePath).append(SAMPLE); //@formatter:off return moduleBuilder(properties) .files() - .batch(SOURCE.append("main").append(SECONDARY), toSrcMainJava().append(packagePath).append(SECONDARY_DESTINATION)) - .addTemplate("ChatController.java.mustache") + .batch(SOURCE.append("main").append(PRIMARY), mainDestination.append(PRIMARY)) + .addTemplate("ChatResource.java.mustache") .and() .and() .build(); diff --git a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/infrastructure/primary/SampleLangChain4jModuleConfiguration.java b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/infrastructure/primary/SampleLangChain4jModuleConfiguration.java index 6a246cbb878..92e0f632273 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/infrastructure/primary/SampleLangChain4jModuleConfiguration.java +++ b/src/main/java/tech/jhipster/lite/generator/server/springboot/mvc/sample/langchain4j/infrastructure/primary/SampleLangChain4jModuleConfiguration.java @@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import tech.jhipster.lite.generator.server.springboot.mvc.sample.langchain4j.application.SampleLangChain4jApplicationService; -import tech.jhipster.lite.generator.server.springboot.mvc.sample.langchain4j.domain.SampleLangChain4jModuleFactory; import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization; import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition; import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource; diff --git a/src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/secondary/ChatController.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/primary/ChatResource.java.mustache similarity index 78% rename from src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/secondary/ChatController.java.mustache rename to src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/primary/ChatResource.java.mustache index 0eb3ae1c385..ed77ed880e3 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/secondary/ChatController.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/langchain4j/main/infrastructure/primary/ChatResource.java.mustache @@ -1,4 +1,4 @@ -package {{packageName}}.sample.infrastructure.secondary; +package {{packageName}}.sample.infrastructure.primary; import dev.langchain4j.model.chat.ChatLanguageModel; import org.springframework.web.bind.annotation.GetMapping; @@ -6,11 +6,11 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController -public class ChatController { +public class ChatResource { ChatLanguageModel chatLanguageModel; - public ChatController(ChatLanguageModel chatLanguageModel) { + public ChatResource(ChatLanguageModel chatLanguageModel) { this.chatLanguageModel = chatLanguageModel; } diff --git a/src/test/features/server/springboot/langchain4j.feature b/src/test/features/server/springboot/langchain4j.feature index 38975e08172..7347f894f80 100644 --- a/src/test/features/server/springboot/langchain4j.feature +++ b/src/test/features/server/springboot/langchain4j.feature @@ -8,3 +8,10 @@ Feature: LangChain4j module Then I should have entries in "src/main/resources/config/application.yml" | open-ai | | langchain4j | + + Scenario: Should add Spring Boot LangChain4j Sample + When I apply "spring-boot-langchain4j-sample" module to default project with maven file + | packageName | tech.jhipster.chips | + | baseName | jhipster | + Then I should have files in "src/main/java/tech/jhipster/chips/sample/infrastructure/primary" + | ChatResource.java |