|
32 | 32 | import org.springframework.data.mongodb.core.MongoTemplate; |
33 | 33 | import org.springframework.data.mongodb.core.query.Criteria; |
34 | 34 | import org.springframework.data.mongodb.core.query.Query; |
35 | | -import org.springframework.lang.Nullable; |
36 | 35 |
|
37 | 36 | /** |
38 | 37 | * An implementation of {@link ChatMemoryRepository} for MongoDB. |
@@ -80,14 +79,23 @@ public void deleteByConversationId(String conversationId) { |
80 | 79 | this.mongoTemplate.remove(Query.query(Criteria.where("conversationId").is(conversationId)), Conversation.class); |
81 | 80 | } |
82 | 81 |
|
83 | | - public static @Nullable Message mapMessage(Conversation conversation) { |
| 82 | + public static Message mapMessage(Conversation conversation) { |
84 | 83 | return switch (conversation.message().type()) { |
85 | | - case "USER" -> new UserMessage(conversation.message().content()); |
86 | | - case "ASSISTANT" -> new AssistantMessage(conversation.message().content()); |
87 | | - case "SYSTEM" -> new SystemMessage(conversation.message().content()); |
| 84 | + case "USER" -> UserMessage.builder() |
| 85 | + .text(conversation.message().content()) |
| 86 | + .metadata(conversation.message().metadata()) |
| 87 | + .build(); |
| 88 | + case "ASSISTANT" -> AssistantMessage.builder() |
| 89 | + .content(conversation.message().content()) |
| 90 | + .properties(conversation.message().metadata()) |
| 91 | + .build(); |
| 92 | + case "SYSTEM" -> SystemMessage.builder() |
| 93 | + .text(conversation.message().content()) |
| 94 | + .metadata(conversation.message().metadata()) |
| 95 | + .build(); |
88 | 96 | default -> { |
89 | 97 | logger.warn("Unsupported message type: {}", conversation.message().type()); |
90 | | - yield null; |
| 98 | + throw new IllegalStateException("Unsupported message type: " + conversation.message().type()); |
91 | 99 | } |
92 | 100 | }; |
93 | 101 | } |
|
0 commit comments