Skip to content

Commit c72730e

Browse files
author
Enrico Rampazzo
committed
removed Cassandra leftover, reformatted code
Signed-off-by: Enrico Rampazzo <[email protected]>
1 parent 10089b1 commit c72730e

File tree

10 files changed

+188
-168
lines changed

10 files changed

+188
-168
lines changed

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/chat/memory/neo4j/Neo4jChatMemoryAutoConfiguration.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ public class Neo4jChatMemoryAutoConfiguration {
4141
@ConditionalOnMissingBean
4242
public Neo4jChatMemory chatMemory(Neo4jChatMemoryProperties properties, Driver driver) {
4343

44-
var builder = Neo4jChatMemoryConfig.builder().withMediaLabel(properties.getMediaLabel())
45-
.withMessageLabel(properties.getMessageLabel()).withMetadataLabel(properties.getMetadataLabel())
46-
.withSessionLabel(properties.getSessionLabel()).withToolCallLabel(properties.getToolCallLabel())
47-
.withToolResponseLabel(properties.getToolResponseLabel())
48-
.withDriver(driver);
44+
var builder = Neo4jChatMemoryConfig.builder()
45+
.withMediaLabel(properties.getMediaLabel())
46+
.withMessageLabel(properties.getMessageLabel())
47+
.withMetadataLabel(properties.getMetadataLabel())
48+
.withSessionLabel(properties.getSessionLabel())
49+
.withToolCallLabel(properties.getToolCallLabel())
50+
.withToolResponseLabel(properties.getToolResponseLabel())
51+
.withDriver(driver);
4952

5053
return Neo4jChatMemory.create(builder.build());
5154
}

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/chat/memory/neo4j/Neo4jChatMemoryProperties.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@
2929
public class Neo4jChatMemoryProperties {
3030

3131
public static final String CONFIG_PREFIX = "spring.ai.chat.memory.neo4j";
32+
3233
private String sessionLabel = Neo4jChatMemoryConfig.DEFAULT_SESSION_LABEL;
34+
3335
private String toolCallLabel = Neo4jChatMemoryConfig.DEFAULT_TOOL_CALL_LABEL;
36+
3437
private String metadataLabel = Neo4jChatMemoryConfig.DEFAULT_METADATA_LABEL;
38+
3539
private String messageLabel = Neo4jChatMemoryConfig.DEFAULT_MESSAGE_LABEL;
40+
3641
private String toolResponseLabel = Neo4jChatMemoryConfig.DEFAULT_TOOL_RESPONSE_LABEL;
42+
3743
private String mediaLabel = Neo4jChatMemoryConfig.DEFAULT_MEDIA_LABEL;
3844

3945
public String getSessionLabel() {
@@ -83,4 +89,5 @@ public void setToolResponseLabel(String toolResponseLabel) {
8389
public void setMediaLabel(String mediaLabel) {
8490
this.mediaLabel = mediaLabel;
8591
}
92+
8693
}

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/chat/memory/neo4j/Neo4jChatMemoryAutoConfigurationIT.java

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -49,78 +49,82 @@ class Neo4jChatMemoryAutoConfigurationIT {
4949

5050
static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("neo4j");
5151

52-
@SuppressWarnings({"rawtypes", "resource"})
52+
@SuppressWarnings({ "rawtypes", "resource" })
5353
@Container
54-
static Neo4jContainer neo4jContainer = (Neo4jContainer) new Neo4jContainer(DEFAULT_IMAGE_NAME.withTag("5")).withoutAuthentication().withExposedPorts(7474,7687);
54+
static Neo4jContainer neo4jContainer = (Neo4jContainer) new Neo4jContainer(DEFAULT_IMAGE_NAME.withTag("5"))
55+
.withoutAuthentication()
56+
.withExposedPorts(7474, 7687);
5557

5658
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
57-
.withConfiguration(
58-
AutoConfigurations.of(Neo4jChatMemoryAutoConfiguration.class, Neo4jAutoConfiguration.class));
59-
59+
.withConfiguration(AutoConfigurations.of(Neo4jChatMemoryAutoConfiguration.class, Neo4jAutoConfiguration.class));
6060

6161
@Test
6262
void addAndGet() {
63-
this.contextRunner.withPropertyValues("spring.neo4j.uri=" + neo4jContainer.getBoltUrl())
64-
.run(context -> {
65-
Neo4jChatMemory memory = context.getBean(Neo4jChatMemory.class);
66-
67-
String sessionId = UUIDs.timeBased().toString();
68-
assertThat(memory.get(sessionId, Integer.MAX_VALUE)).isEmpty();
69-
70-
UserMessage userMessage = new UserMessage("test question");
71-
72-
73-
memory.add(sessionId, userMessage);
74-
List<Message> messages = memory.get(sessionId, Integer.MAX_VALUE);
75-
assertThat(messages).hasSize(1);
76-
assertThat(messages.get(0)).usingRecursiveAssertion().isEqualTo(userMessage);
77-
78-
memory.clear(sessionId);
79-
assertThat(memory.get(sessionId, Integer.MAX_VALUE)).isEmpty();
80-
81-
AssistantMessage assistantMessage = new AssistantMessage("test answer", Map.of(),
82-
List.of(new AssistantMessage.ToolCall(
83-
"id", "type", "name", "arguments")));
84-
85-
memory.add(sessionId, List.of(userMessage, assistantMessage));
86-
messages = memory.get(sessionId, Integer.MAX_VALUE);
87-
assertThat(messages).hasSize(2);
88-
assertThat(messages.get(1)).isEqualTo(userMessage);
89-
90-
assertThat(messages.get(0)).isEqualTo(assistantMessage);
91-
memory.clear(sessionId);
92-
MimeType textPlain = MimeType.valueOf("text/plain");
93-
List<Media> media = List.of(Media.builder().name("some media").id(UUIDs.random().toString())
94-
.mimeType(textPlain).data("hello".getBytes(StandardCharsets.UTF_8)).build(),
95-
Media.builder().data(URI.create("http://www.google.com").toURL()).mimeType(textPlain).build());
96-
UserMessage userMessageWithMedia = new UserMessage("Message with media", media);
97-
memory.add(sessionId, userMessageWithMedia);
98-
99-
messages = memory.get(sessionId, Integer.MAX_VALUE);
100-
assertThat(messages.size()).isEqualTo(1);
101-
assertThat(messages.get(0)).isEqualTo(userMessageWithMedia);
102-
assertThat(((UserMessage)messages.get(0)).getMedia()).hasSize(2);
103-
assertThat(((UserMessage) messages.get(0)).getMedia()).usingRecursiveFieldByFieldElementComparator().isEqualTo(media);
104-
memory.clear(sessionId);
105-
ToolResponseMessage toolResponseMessage = new ToolResponseMessage(List.of(
106-
new ToolResponse("id", "name", "responseData"),
107-
new ToolResponse("id2", "name2", "responseData2")),
108-
Map.of("id", "id", "metadataKey", "metadata"));
109-
memory.add(sessionId, toolResponseMessage);
110-
messages = memory.get(sessionId, Integer.MAX_VALUE);
111-
assertThat(messages.size()).isEqualTo(1);
112-
assertThat(messages.get(0)).isEqualTo(toolResponseMessage);
113-
114-
memory.clear(sessionId);
115-
SystemMessage sm = new SystemMessage("this is a System message");
116-
memory.add(sessionId, sm);
117-
messages = memory.get(sessionId, Integer.MAX_VALUE);
118-
assertThat(messages).hasSize(1);
119-
assertThat(messages.get(0)).usingRecursiveAssertion().isEqualTo(sm);
120-
});
63+
this.contextRunner.withPropertyValues("spring.neo4j.uri=" + neo4jContainer.getBoltUrl()).run(context -> {
64+
Neo4jChatMemory memory = context.getBean(Neo4jChatMemory.class);
65+
66+
String sessionId = UUIDs.timeBased().toString();
67+
assertThat(memory.get(sessionId, Integer.MAX_VALUE)).isEmpty();
68+
69+
UserMessage userMessage = new UserMessage("test question");
70+
71+
memory.add(sessionId, userMessage);
72+
List<Message> messages = memory.get(sessionId, Integer.MAX_VALUE);
73+
assertThat(messages).hasSize(1);
74+
assertThat(messages.get(0)).usingRecursiveAssertion().isEqualTo(userMessage);
75+
76+
memory.clear(sessionId);
77+
assertThat(memory.get(sessionId, Integer.MAX_VALUE)).isEmpty();
78+
79+
AssistantMessage assistantMessage = new AssistantMessage("test answer", Map.of(),
80+
List.of(new AssistantMessage.ToolCall("id", "type", "name", "arguments")));
81+
82+
memory.add(sessionId, List.of(userMessage, assistantMessage));
83+
messages = memory.get(sessionId, Integer.MAX_VALUE);
84+
assertThat(messages).hasSize(2);
85+
assertThat(messages.get(1)).isEqualTo(userMessage);
86+
87+
assertThat(messages.get(0)).isEqualTo(assistantMessage);
88+
memory.clear(sessionId);
89+
MimeType textPlain = MimeType.valueOf("text/plain");
90+
List<Media> media = List.of(
91+
Media.builder()
92+
.name("some media")
93+
.id(UUIDs.random().toString())
94+
.mimeType(textPlain)
95+
.data("hello".getBytes(StandardCharsets.UTF_8))
96+
.build(),
97+
Media.builder().data(URI.create("http://www.google.com").toURL()).mimeType(textPlain).build());
98+
UserMessage userMessageWithMedia = new UserMessage("Message with media", media);
99+
memory.add(sessionId, userMessageWithMedia);
100+
101+
messages = memory.get(sessionId, Integer.MAX_VALUE);
102+
assertThat(messages.size()).isEqualTo(1);
103+
assertThat(messages.get(0)).isEqualTo(userMessageWithMedia);
104+
assertThat(((UserMessage) messages.get(0)).getMedia()).hasSize(2);
105+
assertThat(((UserMessage) messages.get(0)).getMedia()).usingRecursiveFieldByFieldElementComparator()
106+
.isEqualTo(media);
107+
memory.clear(sessionId);
108+
ToolResponseMessage toolResponseMessage = new ToolResponseMessage(
109+
List.of(new ToolResponse("id", "name", "responseData"),
110+
new ToolResponse("id2", "name2", "responseData2")),
111+
Map.of("id", "id", "metadataKey", "metadata"));
112+
memory.add(sessionId, toolResponseMessage);
113+
messages = memory.get(sessionId, Integer.MAX_VALUE);
114+
assertThat(messages.size()).isEqualTo(1);
115+
assertThat(messages.get(0)).isEqualTo(toolResponseMessage);
116+
117+
memory.clear(sessionId);
118+
SystemMessage sm = new SystemMessage("this is a System message");
119+
memory.add(sessionId, sm);
120+
messages = memory.get(sessionId, Integer.MAX_VALUE);
121+
assertThat(messages).hasSize(1);
122+
assertThat(messages.get(0)).usingRecursiveAssertion().isEqualTo(sm);
123+
});
121124
}
125+
122126
@Test
123-
void setCustomConfiguration(){
127+
void setCustomConfiguration() {
124128
final String sessionLabel = "LabelSession";
125129
final String toolCallLabel = "LabelToolCall";
126130
final String metadataLabel = "LabelMetadata";
@@ -129,25 +133,24 @@ void setCustomConfiguration(){
129133
final String mediaLabel = "LabelMedia";
130134

131135
final String propertyBase = "spring.ai.chat.memory.neo4j.%s=%s";
132-
this.contextRunner.withPropertyValues("spring.neo4j.uri=" + neo4jContainer.getBoltUrl(),
133-
propertyBase.formatted("sessionlabel", sessionLabel),
134-
propertyBase.formatted("toolcallLabel", toolCallLabel),
135-
propertyBase.formatted("metadatalabel", metadataLabel),
136-
propertyBase.formatted("messagelabel", messageLabel),
137-
propertyBase.formatted("toolresponselabel", toolResponseLabel),
138-
propertyBase.formatted("medialabel", mediaLabel))
139-
.run(context -> {
140-
Neo4jChatMemory chatMemory = context.getBean(Neo4jChatMemory.class);
141-
Neo4jChatMemoryConfig config = chatMemory.getConfig();
142-
assertThat(config.getMessageLabel()).isEqualTo(messageLabel);
143-
assertThat(config.getMediaLabel()).isEqualTo(mediaLabel);
144-
assertThat(config.getMetadataLabel()).isEqualTo(metadataLabel);
145-
assertThat(config.getSessionLabel()).isEqualTo(sessionLabel);
146-
assertThat(config.getToolResponseLabel()).isEqualTo(toolResponseLabel);
147-
assertThat(config.getToolCallLabel()).isEqualTo(toolCallLabel);
148-
});
136+
this.contextRunner
137+
.withPropertyValues("spring.neo4j.uri=" + neo4jContainer.getBoltUrl(),
138+
propertyBase.formatted("sessionlabel", sessionLabel),
139+
propertyBase.formatted("toolcallLabel", toolCallLabel),
140+
propertyBase.formatted("metadatalabel", metadataLabel),
141+
propertyBase.formatted("messagelabel", messageLabel),
142+
propertyBase.formatted("toolresponselabel", toolResponseLabel),
143+
propertyBase.formatted("medialabel", mediaLabel))
144+
.run(context -> {
145+
Neo4jChatMemory chatMemory = context.getBean(Neo4jChatMemory.class);
146+
Neo4jChatMemoryConfig config = chatMemory.getConfig();
147+
assertThat(config.getMessageLabel()).isEqualTo(messageLabel);
148+
assertThat(config.getMediaLabel()).isEqualTo(mediaLabel);
149+
assertThat(config.getMetadataLabel()).isEqualTo(metadataLabel);
150+
assertThat(config.getSessionLabel()).isEqualTo(sessionLabel);
151+
assertThat(config.getToolResponseLabel()).isEqualTo(toolResponseLabel);
152+
assertThat(config.getToolCallLabel()).isEqualTo(toolCallLabel);
153+
});
149154
}
150155

151-
152-
153156
}

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/chat/memory/neo4j/Neo4jChatMemoryPropertiesTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
package org.springframework.ai.autoconfigure.chat.memory.neo4j;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.springframework.ai.autoconfigure.chat.memory.cassandra.CassandraChatMemoryProperties;
21-
import org.springframework.ai.chat.memory.cassandra.CassandraChatMemoryConfig;
2220
import org.springframework.ai.chat.memory.neo4j.Neo4jChatMemoryConfig;
2321

24-
import java.time.Duration;
25-
2622
import static org.assertj.core.api.Assertions.assertThat;
2723

2824
/**
@@ -42,22 +38,4 @@ void defaultValues() {
4238
assertThat(props.getToolResponseLabel()).isEqualTo(Neo4jChatMemoryConfig.DEFAULT_TOOL_RESPONSE_LABEL);
4339
}
4440

45-
@Test
46-
void customValues() {
47-
var props = new CassandraChatMemoryProperties();
48-
props.setKeyspace("my_keyspace");
49-
props.setTable("my_table");
50-
props.setAssistantColumn("my_assistant_column");
51-
props.setUserColumn("my_user_column");
52-
props.setTimeToLive(Duration.ofDays(1));
53-
props.setInitializeSchema(false);
54-
55-
assertThat(props.getKeyspace()).isEqualTo("my_keyspace");
56-
assertThat(props.getTable()).isEqualTo("my_table");
57-
assertThat(props.getAssistantColumn()).isEqualTo("my_assistant_column");
58-
assertThat(props.getUserColumn()).isEqualTo("my_user_column");
59-
assertThat(props.getTimeToLive()).isEqualTo(Duration.ofDays(1));
60-
assertThat(props.isInitializeSchema()).isFalse();
61-
}
62-
6341
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package org.springframework.ai.chat.memory.neo4j;
22

33
public enum MediaAttributes {
4-
ID("id"), MIME_TYPE("mimeType"), DATA("data"), NAME("name"), URL("url"),
5-
IDX("idx");
4+
5+
ID("id"), MIME_TYPE("mimeType"), DATA("data"), NAME("name"), URL("url"), IDX("idx");
66

77
private final String value;
88

9-
MediaAttributes(String value){
9+
MediaAttributes(String value) {
1010
this.value = value;
1111
}
1212

13-
public String getValue(){
13+
public String getValue() {
1414
return value;
1515
}
16+
1617
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package org.springframework.ai.chat.memory.neo4j;
22

33
public enum MessageAttributes {
4+
45
TEXT_CONTENT("textContent"), MESSAGE_TYPE("messageType");
56

67
private final String value;
78

8-
public String getValue(){
9+
public String getValue() {
910
return value;
1011
}
12+
1113
MessageAttributes(String value) {
1214
this.value = value;
1315
}
16+
1417
}

0 commit comments

Comments
 (0)