Skip to content

Commit 1f7a7c3

Browse files
authored
Merge pull request #146 from quarkiverse/#144
Make @ApplicationScoped beans work with ChatMemoryRemover
2 parents d9b008a + 266f7f0 commit 1f7a7c3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

core/runtime/src/main/java/io/quarkiverse/langchain4j/ChatMemoryRemover.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.langchain4j.memory.ChatMemory;
66
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
77
import io.quarkiverse.langchain4j.runtime.aiservice.ChatMemoryRemovable;
8+
import io.quarkus.arc.ClientProxy;
89

910
/**
1011
* Allows the application to manually control when a {@link ChatMemory} should be removed from the underlying
@@ -22,7 +23,8 @@ private ChatMemoryRemover() {
2223
* @param memoryId The object used as memory IDs for which the corresponding {@link ChatMemory} should be removed
2324
*/
2425
public static void remove(Object aiService, Object memoryId) {
25-
if (aiService instanceof ChatMemoryRemovable r) {
26+
var obj = ClientProxy.unwrap(aiService);
27+
if (obj instanceof ChatMemoryRemovable r) {
2628
r.remove(memoryId);
2729
}
2830
}
@@ -32,7 +34,8 @@ public static void remove(Object aiService, Object memoryId) {
3234
* @param memoryIds The objects used as memory IDs for which the corresponding {@link ChatMemory} should be removed
3335
*/
3436
public static void remove(Object aiService, List<Object> memoryIds) {
35-
if (aiService instanceof ChatMemoryRemovable r) {
37+
var obj = ClientProxy.unwrap(aiService);
38+
if (obj instanceof ChatMemoryRemovable r) {
3639
r.remove(memoryIds.toArray(EMPTY_OBJECT_ARRAY));
3740
}
3841
}

openai/openai-vanilla/deployment/src/test/java/org/acme/examples/aiservices/CustomChatMemoryStoreTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Optional;
1515
import java.util.concurrent.atomic.AtomicInteger;
1616

17+
import jakarta.enterprise.context.ApplicationScoped;
1718
import jakarta.enterprise.inject.Produces;
1819
import jakarta.inject.Inject;
1920
import jakarta.inject.Singleton;
@@ -81,7 +82,7 @@ void setup() {
8182
}
8283

8384
@RegisterAiService
84-
@Singleton
85+
@ApplicationScoped
8586
interface ChatWithSeparateMemoryForEachUser {
8687

8788
String chat(@MemoryId int memoryId, @UserMessage String userMessage);

0 commit comments

Comments
 (0)