Skip to content

Commit

Permalink
fix postgre
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 20, 2024
1 parent 897d1ae commit 5b560e1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class PersistentChatMemoryStore implements ChatMemoryStore {
Expand Down Expand Up @@ -80,7 +81,10 @@ public List<ChatMessage> getMessages(Object threadId) {
if (chatMessages.isEmpty()) {
return new ArrayList<>();
} else {
return chatMessages.stream().map(this::convertToChatMessage).collect(Collectors.toList());
return chatMessages.stream()
.map(this::convertToChatMessage)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@

<insert id="saveWithThreadInfo" parameterType="org.apache.bigtop.manager.dao.po.ChatThreadPO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO llm_chat_thread (platform_id, user_id, model, thread_info)
VALUES (#{platformId}, #{userId}, #{model}, #{threadInfo, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler})
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
user_id = VALUES(user_id),
model = VALUES(model),
thread_info = VALUES(thread_info)
VALUES (#{platformId}, #{userId}, #{model}, #{threadInfo, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler}::json)
</insert>

<select id="findAllByPlatformId" resultType="org.apache.bigtop.manager.dao.po.ChatThreadPO">
SELECT *
FROM llm_chat_thread
WHERE platform_id = #{platformId} AND is_deleted = 0
WHERE platform_id = #{platformId} AND is_deleted = false
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@

<insert id="saveWithCredentials" parameterType="org.apache.bigtop.manager.dao.po.PlatformAuthorizedPO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO llm_platform_authorized (platform_id, credentials)
VALUES (#{platformId}, #{credentials, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler})
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
credentials = VALUES(credentials)
VALUES (#{platformId}, #{credentials, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler}::json)
</insert>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public boolean deleteAuthorizedPlatform(Long platformId) {
List<ChatThreadPO> chatThreadPOS = chatThreadDao.findAllByPlatformId(authorizedPlatformPO.getId());
chatThreadPOS.forEach(chatThread -> chatThread.setIsDeleted(true));
chatThreadDao.partialUpdateByIds(chatThreadPOS);
for (ChatThreadPO chatThreadPO : chatThreadPOS) {
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId(chatThreadPO.getId());
chatMessagePOS.forEach(chatMessage -> chatMessage.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);
}
return true;
}
}
Expand Down

0 comments on commit 5b560e1

Please sign in to comment.