Skip to content

Commit

Permalink
remove model in chatthread
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Oct 16, 2024
1 parent f9bee53 commit f46da9a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public class ChatThreadPO extends BasePO implements Serializable {
@Column(name = "id")
private Long id;

@Column(name = "model", nullable = false, length = 255)
private String model;

@Column(name = "thread_info")
private String threadInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public class ChatbotController {
@Operation(summary = "new thread", description = "Create a chat threads")
@PostMapping("/auth-platforms/{authId}/threads")
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long authId) {
return ResponseEntity.success(chatbotService.createChatThreads(authId, ""));
return ResponseEntity.success(chatbotService.createChatThreads(authId));
}

@Operation(summary = "update thread", description = "Update a chat threads")
@PutMapping("/auth-platforms/{authId}/threads")
public ResponseEntity<ChatThreadVO> updateChatThreads(
@PathVariable Long authId, @RequestBody ChatbotThreadReq chatbotThreadReq) {
return ResponseEntity.success(chatbotService.createChatThreads(authId, ""));
return ResponseEntity.success(chatbotService.createChatThreads(authId));
}

@Operation(summary = "delete thread", description = "Delete a chat threads")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public interface ChatbotService {

ChatThreadVO createChatThreads(Long authId, String model);
ChatThreadVO createChatThreads(Long authId);

boolean deleteChatThreads(Long authId, Long threadId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,24 @@ private AIAssistant buildAIAssistant(
}

@Override
public ChatThreadVO createChatThreads(Long authId, String model) {
public ChatThreadVO createChatThreads(Long authId) {
AuthPlatformPO authPlatformPO = authPlatformDao.findById(authId);
if (authPlatformPO == null || AuthPlatformStatus.isDeleted(authPlatformPO.getStatus())) {
throw new ApiException(ApiExceptionEnum.PLATFORM_NOT_AUTHORIZED);
}
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromPO2DTO(authPlatformPO);
Long userId = SessionUserHolder.getUserId();
PlatformPO platformPO = platformDao.findById(authPlatformPO.getPlatformId());
List<String> supportModels = List.of(platformPO.getSupportModels().split(","));
if (!supportModels.contains(model)) {
throw new ApiException(ApiExceptionEnum.MODEL_NOT_SUPPORTED);
}
ChatThreadDTO chatThreadDTO = new ChatThreadDTO();
chatThreadDTO.setPlatformId(platformPO.getId());
chatThreadDTO.setAuthId(authPlatformPO.getId());

AIAssistant aiAssistant =
buildAIAssistant(platformPO.getName(), model, authPlatformDTO.getAuthCredentials(), null, null);
AIAssistant aiAssistant = buildAIAssistant(
platformPO.getName(), authPlatformDTO.getModel(), authPlatformDTO.getAuthCredentials(), null, null);
Map<String, String> threadInfo = aiAssistant.createThread();
chatThreadDTO.setThreadInfo(threadInfo);
ChatThreadPO chatThreadPO = ChatThreadConverter.INSTANCE.fromDTO2PO(chatThreadDTO);
chatThreadPO.setUserId(userId);
chatThreadPO.setModel(model);
chatThreadDao.save(chatThreadPO);
return ChatThreadConverter.INSTANCE.fromPO2VO(chatThreadPO);
}
Expand Down Expand Up @@ -184,7 +179,7 @@ public SseEmitter talk(Long authId, Long threadId, String message) {
PlatformPO platformPO = platformDao.findById(authPlatformPO.getPlatformId());
AIAssistant aiAssistant = buildAIAssistant(
platformPO.getName(),
chatThreadPO.getModel(),
authPlatformDTO.getModel(),
authPlatformDTO.getAuthCredentials(),
chatThreadPO.getId(),
chatThreadDTO.getThreadInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ CREATE TABLE `llm_chat_thread`
`auth_id` BIGINT(20) UNSIGNED NOT NULL,
`platform_id` BIGINT(20) UNSIGNED NOT NULL,
`user_id` BIGINT(20) UNSIGNED NOT NULL,
`model` VARCHAR(255) NOT NULL,
`is_deleted` TINYINT(1) DEFAULT 0 NULL,
`thread_info` TEXT DEFAULT NULL,
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ CREATE TABLE llm_chat_thread
auth_id BIGINT CHECK (auth_id > 0) NOT NULL,
platform_id BIGINT CHECK (platform_id > 0) NOT NULL,
user_id BIGINT CHECK (user_id > 0) NOT NULL,
model VARCHAR(255) NOT NULL,
thread_info TEXT DEFAULT NULL,
is_deleted BOOLEAN DEFAULT FALSE,
create_time TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void createChatThreads() {
String model = "";
ChatThreadVO chatThread = new ChatThreadVO();

when(chatbotService.createChatThreads(eq(platformId), eq(model))).thenReturn(chatThread);
when(chatbotService.createChatThreads(eq(platformId))).thenReturn(chatThread);

ResponseEntity<ChatThreadVO> response = chatbotController.createChatThreads(platformId);

Expand Down

0 comments on commit f46da9a

Please sign in to comment.