Skip to content

Commit

Permalink
Add langchain4j to github actions ci
Browse files Browse the repository at this point in the history
  • Loading branch information
anunnakian committed Nov 10, 2024
1 parent 7fc405f commit 3f9f93b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tech.jhipster.lite.generator.server.springboot.mvc.sample.langchain4j.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
import static tech.jhipster.lite.module.domain.JHipsterModule.toSrcMainJava;
import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
Expand All @@ -23,12 +21,16 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {

String packagePath = properties.packagePath();
JHipsterDestination mainDestination = toSrcMainJava().append(packagePath).append(SAMPLE);
JHipsterDestination testDestination = toSrcTestJava().append(packagePath).append(SAMPLE);

//@formatter:off
return moduleBuilder(properties)
.files()
.batch(SOURCE.append("main").append(PRIMARY), mainDestination.append(PRIMARY))
.addTemplate("ChatResource.java.mustache")
.addTemplate("ChatResource.java")
.and()
.batch(SOURCE.append("test").append(SAMPLE).append(PRIMARY), testDestination.append(PRIMARY))
.addTemplate("ChatResourceTest.java")
.and()
.and()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ChatResource {
}

@GetMapping("/chat")
public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
public String send(@RequestParam(value = "message", defaultValue = "Hello") String message) {
return chatLanguageModel.generate(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package {{packageName}}.sample.infrastructure.primary;

import static org.assertj.core.api.Assertions.*;

import {{packageName}}.UnitTest;
import dev.langchain4j.model.chat.ChatLanguageModel;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@UnitTest
@ExtendWith(MockitoExtension.class)
class ChatResourceTest {
private static final String ANSWER = "Hello! How can I assist you today?";
@Mock
private ChatLanguageModel chatLanguageModel;
@InjectMocks
private ChatResource chat;
@Test
void shouldBeUnauthorizedForUnknownAccount() {
Mockito.when(chatLanguageModel.generate("Hello")).thenReturn(ANSWER);
assertThat(chat.send("Hello")).isEqualTo(ANSWER);
}
}

0 comments on commit 3f9f93b

Please sign in to comment.