Skip to content

Commit

Permalink
[feature][chat]Support creation of chat memory via REST API.#1603
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryjzhang committed Oct 12, 2024
1 parent f7da6b8 commit aebb6b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.tencent.supersonic.chat.api.pojo.request;

import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
import com.tencent.supersonic.common.pojo.RecordInfo;
import lombok.Data;

@Data
public class ChatMemoryCreateReq extends RecordInfo {

private Integer agentId;

private String question;

private String dbSchema;

private String s2sql;

private MemoryStatus status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.github.pagehelper.PageInfo;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryCreateReq;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
Expand All @@ -17,13 +19,32 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping({"/api/chat/memory"})
public class MemoryController {

@Autowired
private MemoryService memoryService;

@PostMapping("/createMemory")
public Boolean createMemory(@RequestBody ChatMemoryCreateReq chatMemoryCreateReq,
HttpServletRequest request, HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
memoryService.createMemory(ChatMemoryDO.builder()
.agentId(chatMemoryCreateReq.getAgentId())
.s2sql(chatMemoryCreateReq.getS2sql())
.question(chatMemoryCreateReq.getQuestion())
.dbSchema(chatMemoryCreateReq.getDbSchema())
.status(chatMemoryCreateReq.getStatus())
.humanReviewRet(MemoryReviewResult.POSITIVE)
.createdBy(user.getName())
.createdAt(new Date())
.build());
return true;
}

@PostMapping("/updateMemory")
public Boolean updateMemory(@RequestBody ChatMemoryUpdateReq chatMemoryUpdateReq,
HttpServletRequest request, HttpServletResponse response) {
Expand Down

0 comments on commit aebb6b7

Please sign in to comment.