From cd76400a51cdf8b5a1347eed1dbf1369c44d3b08 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 16 Feb 2024 11:28:04 +0200 Subject: [PATCH] Make DevUI not require the default chat model Originally reported at: https://github.com/quarkiverse/quarkus-langchain4j/issues/210#issuecomment-1947981124 --- .../runtime/devui/ChatJsonRPCService.java | 17 +++++++++++------ .../modules/ROOT/pages/includes/attributes.adoc | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/devui/ChatJsonRPCService.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/devui/ChatJsonRPCService.java index 4e5e18acb..fece434f8 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/devui/ChatJsonRPCService.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/devui/ChatJsonRPCService.java @@ -1,10 +1,10 @@ package io.quarkiverse.langchain4j.runtime.devui; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicReference; import jakarta.enterprise.context.control.ActivateRequestContext; -import jakarta.inject.Inject; import dev.langchain4j.data.message.AiMessage; import dev.langchain4j.data.message.SystemMessage; @@ -13,17 +13,22 @@ import dev.langchain4j.memory.chat.ChatMemoryProvider; import dev.langchain4j.model.chat.ChatLanguageModel; import dev.langchain4j.model.output.Response; +import io.quarkus.arc.All; @ActivateRequestContext public class ChatJsonRPCService { - @Inject - ChatLanguageModel model; + private final ChatLanguageModel model; - @Inject - ChatMemoryProvider memoryProvider; + private final ChatMemoryProvider memoryProvider; - private AtomicReference currentMemory = new AtomicReference<>(); + public ChatJsonRPCService(@All List models, // don't use ChatLanguageModel model because it results in the default model not being configured + ChatMemoryProvider memoryProvider) { + this.model = models.get(0); + this.memoryProvider = memoryProvider; + } + + private final AtomicReference currentMemory = new AtomicReference<>(); public String reset(String systemMessage) { if (currentMemory.get() != null) { diff --git a/docs/modules/ROOT/pages/includes/attributes.adoc b/docs/modules/ROOT/pages/includes/attributes.adoc index 73b4467c1..7ee09560f 100644 --- a/docs/modules/ROOT/pages/includes/attributes.adoc +++ b/docs/modules/ROOT/pages/includes/attributes.adoc @@ -1,3 +1,3 @@ :project-version: 0.8.1 :langchain4j-version: 0.27.1 -:examples-dir: ./../examples/ +:examples-dir: ./../examples/ \ No newline at end of file