Skip to content

Commit

Permalink
Generate LangChain4j sample
Browse files Browse the repository at this point in the history
  • Loading branch information
anunnakian committed Nov 10, 2024
1 parent fb53f99 commit 86dcbfb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package {{packageName}}.sample.infrastructure.secondary;
package {{packageName}}.sample.infrastructure.primary;

import dev.langchain4j.model.chat.ChatLanguageModel;
import org.springframework.web.bind.annotation.GetMapping;
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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/features/server/springboot/langchain4j.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

0 comments on commit 86dcbfb

Please sign in to comment.