Skip to content

Commit

Permalink
add soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 14, 2024
1 parent 8be1500 commit b7153da
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.bigtop.manager.dao.annotations.CreateTime;
import org.apache.bigtop.manager.dao.annotations.UpdateBy;
import org.apache.bigtop.manager.dao.annotations.UpdateTime;
import org.apache.bigtop.manager.dao.po.BasePO;

import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.executor.Executor;
Expand Down Expand Up @@ -81,7 +82,9 @@ public Object intercept(Invocation invocation) throws Throwable {
}

for (Object o : objects) {
setAuditFields(o, sqlCommandType);
if (o instanceof BasePO) {
setAuditFields(o, sqlCommandType);
}
}

return invocation.proceed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ public class ChatMessagePO extends BasePO implements Serializable {
private Long threadId;

@Column(name = "is_deleted")
private Integer isDeleted;
private Boolean isDeleted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public class ChatThreadPO extends BasePO implements Serializable {
private Long platformId;

@Column(name = "is_deleted")
private Integer isDeleted;
private Boolean isDeleted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ public class PlatformAuthorizedPO extends BasePO implements Serializable {
private Long platformId;

@Column(name = "is_deleted")
private Integer isDeleted;
private Boolean isDeleted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
public interface ChatThreadDao extends BaseDao<ChatThreadPO> {
List<ChatThreadPO> findAllByUserId(@Param("userId") Long userId);

ChatThreadPO findById(Long id);

ChatThreadPO findByThreadId(@Param("id") Long id);

List<ChatThreadPO> findAllByPlatformAuthorizedIdAndUserId(
@Param("platformId") Long platformAuthorizedId, @Param("userId") Long userId);

void saveWithThreadInfo(ChatThreadPO chatThreadPO);

void deleteByThreadId(@Param("id") Long threadId);
void deleteByThreadId(@Param("id") Long theadId);

void deleteByPlatformId(@Param("platformId") Long platformId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
AND is_deleted = 0
</select>

<update id="deleteByThreadId" parameterType="int">
<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_message
SET is_deleted = 1
WHERE thread_id = #{threadId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
thread_info = VALUES(thread_info)
</insert>

<update id="deleteByPlatformId" parameterType="int">
<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = 1
WHERE platformId = #{platformId}
WHERE platform_id = #{platformId}
</update>

<update id="deleteByThreadId" parameterType="int">
<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = 1
WHERE id = #{id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
credentials = VALUES(credentials)
</insert>

<update id="deleteByPlatformId" parameterType="int">
<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_platform_authorized
SET is_deleted = 1
WHERE id = #{id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.server.model.converter.PlatformConverter;
import org.apache.bigtop.manager.server.model.dto.PlatformDTO;
import org.apache.bigtop.manager.server.model.req.ChatbotMessageReq;
import org.apache.bigtop.manager.server.model.req.PlatformReq;
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
Expand Down Expand Up @@ -66,7 +67,7 @@ public ResponseEntity<List<PlatformAuthorizedVO>> authorizedPlatforms() {
return ResponseEntity.success(chatbotService.authorizedPlatforms());
}

@Operation(summary = "platforms", description = "Get authorized platforms")
@Operation(summary = "platforms", description = "Get platform auth credentials")
@GetMapping("/platforms/{platformId}/auth/credential")
public ResponseEntity<List<PlatformAuthCredentialVO>> platformsAuthCredential(@PathVariable Long platformId) {
return ResponseEntity.success(chatbotService.platformsAuthCredential(platformId));
Expand Down Expand Up @@ -106,8 +107,9 @@ public ResponseEntity<List<ChatThreadVO>> getAllChatThreads(

@Operation(summary = "talk", description = "Talk with Chatbot")
@PostMapping("platforms/{platformId}/threads/{threadId}/talk")
public SseEmitter talk(@PathVariable Long platformId, @PathVariable Long threadId, @RequestParam String message) {
return chatbotService.talk(platformId, threadId, message);
public SseEmitter talk(
@PathVariable Long platformId, @PathVariable Long threadId, @RequestBody ChatbotMessageReq messageReq) {
return chatbotService.talk(platformId, threadId, messageReq.getMessage());
}

@Operation(summary = "history", description = "Get chat records")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.model.req;

import lombok.Data;

import jakarta.validation.constraints.NotEmpty;

@Data
public class ChatbotMessageReq {
@NotEmpty
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ CREATE TABLE `llm_platform_authorized`
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`platform_id` BIGINT(20) UNSIGNED NOT NULL,
`credentials` JSON NOT NULL,
`is_deleted` TINYINT DEFAULT 0,
`is_deleted` TINYINT(1) DEFAULT 0 NULL,
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_by` BIGINT DEFAULT NULL,
Expand All @@ -343,7 +343,7 @@ CREATE TABLE `llm_chat_thread`
`platform_id` BIGINT(20) UNSIGNED NOT NULL,
`user_id` BIGINT(20) UNSIGNED NOT NULL,
`model` VARCHAR(255) NOT NULL,
`is_deleted` TINYINT DEFAULT 0,
`is_deleted` TINYINT(1) DEFAULT 0 NULL,
`thread_info` JSON DEFAULT NULL,
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
Expand All @@ -361,7 +361,7 @@ CREATE TABLE `llm_chat_message`
`user_id` BIGINT(20) UNSIGNED NOT NULL,
`message` TEXT NOT NULL,
`sender` VARCHAR(50) NOT NULL,
`is_deleted` TINYINT DEFAULT 0,
`is_deleted` TINYINT(1) DEFAULT 0 NULL,
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_by` BIGINT DEFAULT NULL,
Expand All @@ -379,5 +379,5 @@ VALUES (1, now(), now(), 'Administrator', '21232f297a57a5a743894a0e4a801fc3', tr
INSERT INTO bigtop_manager.llm_platform (id, credential, name, support_models)
VALUES
(1, '{"apiKey": "API Key"}', 'OpenAI', 'gpt-3.5-turbo,gpt-4,gpt-4o,gpt-3.5-turbo-16k,gpt-4-turbo-preview,gpt-4-32k,gpt-4o-mini'),
(2, '{"apiKey": "API Key"}', 'DashScope', 'qwen-max,qwen-plus,qwen-turbo'),
(2, '{"apiKey": "API Key"}', 'DashScope', 'qwen-1.8b-chat,qwen-max,qwen-plus,qwen-turbo'),
(3, '{"apiKey": "API Key", "secretKey": "Secret Key"}', 'QianFan','Yi-34B-Chat,ERNIE-4.0-8K,ERNIE-3.5-128K,ERNIE-Speed-8K,Llama-2-7B-Chat,Fuyu-8B');
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.bigtop.manager.server.controller;

import org.apache.bigtop.manager.server.model.dto.PlatformDTO;
import org.apache.bigtop.manager.server.model.req.ChatbotMessageReq;
import org.apache.bigtop.manager.server.model.req.PlatformReq;
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
Expand Down Expand Up @@ -174,12 +175,14 @@ void getAllChatThreads() {
void talk() {
Long platformId = 1L;
Long threadId = 1L;
String message = "Hello";
ChatbotMessageReq messageReq = new ChatbotMessageReq();
messageReq.setMessage("Hello");

SseEmitter emitter = new SseEmitter();
when(chatbotService.talk(eq(platformId), eq(threadId), eq(message))).thenReturn(emitter);
when(chatbotService.talk(eq(platformId), eq(threadId), eq(messageReq.getMessage())))
.thenReturn(emitter);

SseEmitter result = chatbotController.talk(platformId, threadId, message);
SseEmitter result = chatbotController.talk(platformId, threadId, messageReq);

assertEquals(emitter, result);
}
Expand Down

0 comments on commit b7153da

Please sign in to comment.