From 0256ee337e13327745282279ce8363c3aa4751c1 Mon Sep 17 00:00:00 2001 From: Arnaud Mengus Date: Mon, 27 May 2024 14:55:13 +0000 Subject: [PATCH] Adding vectorStoreClass and embeddingModelClass to SiloEntity --- backend/build.gradle | 20 +++++++++---- .../java/ai/dragon/entity/SiloEntity.java | 12 +++++++- .../listener/StartupApplicationListener.java | 28 +++++++++++++++++++ .../ai/dragon/DragonApplicationTests.java | 2 ++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/ai/dragon/listener/StartupApplicationListener.java diff --git a/backend/build.gradle b/backend/build.gradle index 1634e12b..0efab224 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -20,26 +20,36 @@ repositories { } dependencies { - compileOnly 'org.projectlombok:lombok:1.18.32' - annotationProcessor 'org.projectlombok:lombok:1.18.32' annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf:3.2.5' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.hibernate.validator:hibernate-validator' - implementation 'dev.langchain4j:langchain4j-open-ai:0.30.0' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0' + + implementation 'dev.langchain4j:langchain4j-open-ai:0.31.0' + implementation 'dev.langchain4j:langchain4j:0.31.0' + implementation 'dev.langchain4j:langchain4j-core:0.31.0' + implementation 'dev.langchain4j:langchain4j-embeddings:0.31.0' + implementation 'dev.langchain4j:langchain4j-open-ai:0.31.0' + implementation 'dev.langchain4j:langchain4j-easy-rag:0.31.0' + implementation platform('org.dizitart:nitrite-bom:4.2.1') implementation 'org.dizitart:nitrite' implementation 'org.dizitart:nitrite-support' implementation 'org.dizitart:nitrite-mvstore-adapter' implementation 'org.dizitart:nitrite-jackson-mapper' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0' + implementation 'net.sourceforge.argparse4j:argparse4j:0.9.0' - developmentOnly("org.springframework.boot:spring-boot-devtools") + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + + compileOnly 'org.projectlombok:lombok:1.18.32' + annotationProcessor 'org.projectlombok:lombok:1.18.32' testCompileOnly 'org.projectlombok:lombok:1.18.32' testAnnotationProcessor 'org.projectlombok:lombok:1.18.32' } diff --git a/backend/src/main/java/ai/dragon/entity/SiloEntity.java b/backend/src/main/java/ai/dragon/entity/SiloEntity.java index e18dd82a..18cc2752 100644 --- a/backend/src/main/java/ai/dragon/entity/SiloEntity.java +++ b/backend/src/main/java/ai/dragon/entity/SiloEntity.java @@ -5,6 +5,8 @@ import org.dizitart.no2.repository.annotations.Entity; import org.dizitart.no2.repository.annotations.Id; +import dev.langchain4j.model.embedding.bge.small.en.v15.BgeSmallEnV15QuantizedEmbeddingModel; +import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; import lombok.Getter; @@ -24,10 +26,18 @@ public class SiloEntity implements IAbstractEntity { @Schema(description = "Name of the Silo") private String name; - private String embeddingStoreClass; + @NotNull + @Schema(description = "Java Class to be used for the Vector Store") + private String vectorStoreClass; + + @NotNull + @Schema(description = "Java Class to be used for the Embedding Model") + private String embeddingModelClass; public SiloEntity() { this.uuid = UUID.randomUUID(); this.name = String.format("Silo %s", this.uuid.toString()); + this.vectorStoreClass = InMemoryEmbeddingStore.class.getCanonicalName(); + this.embeddingModelClass = BgeSmallEnV15QuantizedEmbeddingModel.class.getCanonicalName(); } } diff --git a/backend/src/main/java/ai/dragon/listener/StartupApplicationListener.java b/backend/src/main/java/ai/dragon/listener/StartupApplicationListener.java new file mode 100644 index 00000000..b7cd24f6 --- /dev/null +++ b/backend/src/main/java/ai/dragon/listener/StartupApplicationListener.java @@ -0,0 +1,28 @@ +package ai.dragon.listener; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.context.annotation.Profile; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +@Component +@Profile("!test") +public class StartupApplicationListener implements ApplicationListener { + @Autowired + private ServletWebServerApplicationContext webServerAppCtxt; + + @Override + public void onApplicationEvent(@NonNull ContextRefreshedEvent event) { + String scheme = "http"; + String host = "localhost"; + int port = webServerAppCtxt.getWebServer().getPort(); + + System.out.println("================================================"); + System.out.println(String.format("APP URL\t\t : %s://%s:%d/", scheme, host, port)); + System.out.println(String.format("Swagger UI\t : %s://%s:%d/api/swagger-ui.html", scheme, host, port)); + System.out.println("================================================"); + } +} diff --git a/backend/src/test/java/ai/dragon/DragonApplicationTests.java b/backend/src/test/java/ai/dragon/DragonApplicationTests.java index 60896218..41971a89 100644 --- a/backend/src/test/java/ai/dragon/DragonApplicationTests.java +++ b/backend/src/test/java/ai/dragon/DragonApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class DragonApplicationTests { @Test void contextLoads() {