Skip to content

Commit

Permalink
BIGTOP-4221: Update AIChat to Chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 13, 2024
1 parent 89ceffb commit 4dbc357
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthorizedVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
import org.apache.bigtop.manager.server.service.AIChatService;
import org.apache.bigtop.manager.server.service.ChatbotService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -48,71 +48,71 @@

@Tag(name = "AI Chat Controller")
@RestController
@RequestMapping("/ai/chat/")
public class AIChatController {
@RequestMapping("/chatbot/")
public class ChatbotController {

@Resource
private AIChatService chatService;
private ChatbotService chatbotService;

@Operation(summary = "platforms", description = "Get all platforms")
@GetMapping("/platforms")
public ResponseEntity<List<PlatformVO>> platforms() {
return ResponseEntity.success(chatService.platforms());
return ResponseEntity.success(chatbotService.platforms());
}

@Operation(summary = "platforms", description = "Get authorized platforms")
@GetMapping("/platforms/authorized")
public ResponseEntity<List<PlatformAuthorizedVO>> authorizedPlatforms() {
return ResponseEntity.success(chatService.authorizedPlatforms());
return ResponseEntity.success(chatbotService.authorizedPlatforms());
}

@Operation(summary = "platforms", description = "Get authorized platforms")
@GetMapping("/platforms/{platformId}/auth/credential")
public ResponseEntity<List<PlatformAuthCredentialVO>> platformsAuthCredential(@PathVariable Long platformId) {
return ResponseEntity.success(chatService.platformsAuthCredential(platformId));
return ResponseEntity.success(chatbotService.platformsAuthCredential(platformId));
}

@Operation(summary = "platforms", description = "Add authorized platforms")
@PutMapping("/platforms")
public ResponseEntity<PlatformAuthorizedVO> addAuthorizedPlatform(@RequestBody PlatformReq platformReq) {
PlatformDTO platformDTO = PlatformConverter.INSTANCE.fromReq2DTO(platformReq);
return ResponseEntity.success(chatService.addAuthorizedPlatform(platformDTO));
return ResponseEntity.success(chatbotService.addAuthorizedPlatform(platformDTO));
}

@Operation(summary = "platforms", description = "Delete authorized platforms")
@DeleteMapping("/platforms/{platformId}")
public ResponseEntity<Boolean> deleteAuthorizedPlatform(@PathVariable Long platformId) {
return ResponseEntity.success(chatService.deleteAuthorizedPlatform(platformId));
return ResponseEntity.success(chatbotService.deleteAuthorizedPlatform(platformId));
}

@Operation(summary = "new threads", description = "Create a chat threads")
@PutMapping("/platforms/{platformId}/threads")
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long platformId, @RequestParam String model) {
return ResponseEntity.success(chatService.createChatThreads(platformId, model));
return ResponseEntity.success(chatbotService.createChatThreads(platformId, model));
}

@Operation(summary = "delete threads", description = "Delete a chat threads")
@DeleteMapping("platforms/{platformId}/threads/{threadId}")
public ResponseEntity<Boolean> deleteChatThreads(@PathVariable Long platformId, @PathVariable Long threadId) {
return ResponseEntity.success(chatService.deleteChatThreads(platformId, threadId));
return ResponseEntity.success(chatbotService.deleteChatThreads(platformId, threadId));
}

@Operation(summary = "get", description = "Get all threads of a platform")
@GetMapping("platforms/{platformId}/threads")
public ResponseEntity<List<ChatThreadVO>> getAllChatThreads(
@PathVariable Long platformId, @RequestParam String model) {
return ResponseEntity.success(chatService.getAllChatThreads(platformId, model));
return ResponseEntity.success(chatbotService.getAllChatThreads(platformId, model));
}

@Operation(summary = "talk", description = "Talk with AI")
@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 chatService.talk(platformId, threadId, message);
return chatbotService.talk(platformId, threadId, message);
}

@Operation(summary = "history", description = "Get chat records")
@GetMapping("platforms/{platformId}/threads/{threadId}/history")
public ResponseEntity<List<ChatMessageVO>> history(@PathVariable Long platformId, @PathVariable Long threadId) {
return ResponseEntity.success(chatService.history(platformId, threadId));
return ResponseEntity.success(chatbotService.history(platformId, threadId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import java.util.List;

public interface AIChatService {
public interface ChatbotService {

List<PlatformVO> platforms();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthorizedVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
import org.apache.bigtop.manager.server.service.AIChatService;
import org.apache.bigtop.manager.server.service.ChatbotService;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.i18n.LocaleContextHolder;
Expand All @@ -66,7 +66,7 @@

@Service
@Slf4j
public class AIChatServiceImpl implements AIChatService {
public class ChatbotServiceImpl implements ChatbotService {
@Resource
private PlatformDao platformDao;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthorizedVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
import org.apache.bigtop.manager.server.service.AIChatService;
import org.apache.bigtop.manager.server.service.ChatbotService;
import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

Expand All @@ -50,13 +50,13 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class AIChatControllerTest {
class ChatbotControllerTest {

@Mock
private AIChatService chatService;
private ChatbotService chatbotService;

@InjectMocks
private AIChatController chatController;
private ChatbotController chatbotController;

private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;

Expand All @@ -74,9 +74,9 @@ void tearDown() {
@Test
void getAllPlatforms() {
List<PlatformVO> platforms = new ArrayList<>();
when(chatService.platforms()).thenReturn(platforms);
when(chatbotService.platforms()).thenReturn(platforms);

ResponseEntity<List<PlatformVO>> response = chatController.platforms();
ResponseEntity<List<PlatformVO>> response = chatbotController.platforms();

assertTrue(response.isSuccess());
assertEquals(platforms, response.getData());
Expand All @@ -85,9 +85,9 @@ void getAllPlatforms() {
@Test
void getAuthorizedPlatforms() {
List<PlatformAuthorizedVO> authorizedPlatforms = new ArrayList<>();
when(chatService.authorizedPlatforms()).thenReturn(authorizedPlatforms);
when(chatbotService.authorizedPlatforms()).thenReturn(authorizedPlatforms);

ResponseEntity<List<PlatformAuthorizedVO>> response = chatController.authorizedPlatforms();
ResponseEntity<List<PlatformAuthorizedVO>> response = chatbotController.authorizedPlatforms();

assertTrue(response.isSuccess());
assertEquals(authorizedPlatforms, response.getData());
Expand All @@ -97,9 +97,9 @@ void getAuthorizedPlatforms() {
void platformsAuthCredential() {
Long platformId = 1L;
List<PlatformAuthCredentialVO> credentials = new ArrayList<>();
when(chatService.platformsAuthCredential(platformId)).thenReturn(credentials);
when(chatbotService.platformsAuthCredential(platformId)).thenReturn(credentials);

ResponseEntity<List<PlatformAuthCredentialVO>> response = chatController.platformsAuthCredential(platformId);
ResponseEntity<List<PlatformAuthCredentialVO>> response = chatbotController.platformsAuthCredential(platformId);

assertTrue(response.isSuccess());
assertEquals(credentials, response.getData());
Expand All @@ -110,9 +110,9 @@ void addAuthorizedPlatform() {
PlatformReq platformReq = new PlatformReq();
PlatformAuthorizedVO authorizedVO = new PlatformAuthorizedVO();

when(chatService.addAuthorizedPlatform(any(PlatformDTO.class))).thenReturn(authorizedVO);
when(chatbotService.addAuthorizedPlatform(any(PlatformDTO.class))).thenReturn(authorizedVO);

ResponseEntity<PlatformAuthorizedVO> response = chatController.addAuthorizedPlatform(platformReq);
ResponseEntity<PlatformAuthorizedVO> response = chatbotController.addAuthorizedPlatform(platformReq);

assertTrue(response.isSuccess());
assertEquals(authorizedVO, response.getData());
Expand All @@ -121,9 +121,9 @@ void addAuthorizedPlatform() {
@Test
void deleteAuthorizedPlatform() {
Long platformId = 1L;
when(chatService.deleteAuthorizedPlatform(platformId)).thenReturn(true);
when(chatbotService.deleteAuthorizedPlatform(platformId)).thenReturn(true);

ResponseEntity<Boolean> response = chatController.deleteAuthorizedPlatform(platformId);
ResponseEntity<Boolean> response = chatbotController.deleteAuthorizedPlatform(platformId);

assertTrue(response.isSuccess());
assertEquals(true, response.getData());
Expand All @@ -135,9 +135,9 @@ void createChatThreads() {
String model = "model1";
ChatThreadVO chatThread = new ChatThreadVO();

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

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

assertTrue(response.isSuccess());
assertEquals(chatThread, response.getData());
Expand All @@ -148,9 +148,9 @@ void deleteChatThreads() {
Long platformId = 1L;
Long threadId = 1L;

when(chatService.deleteChatThreads(platformId, threadId)).thenReturn(true);
when(chatbotService.deleteChatThreads(platformId, threadId)).thenReturn(true);

ResponseEntity<Boolean> response = chatController.deleteChatThreads(platformId, threadId);
ResponseEntity<Boolean> response = chatbotController.deleteChatThreads(platformId, threadId);

assertTrue(response.isSuccess());
assertEquals(true, response.getData());
Expand All @@ -162,9 +162,9 @@ void getAllChatThreads() {
String model = "model1";
List<ChatThreadVO> chatThreads = new ArrayList<>();

when(chatService.getAllChatThreads(eq(platformId), eq(model))).thenReturn(chatThreads);
when(chatbotService.getAllChatThreads(eq(platformId), eq(model))).thenReturn(chatThreads);

ResponseEntity<List<ChatThreadVO>> response = chatController.getAllChatThreads(platformId, model);
ResponseEntity<List<ChatThreadVO>> response = chatbotController.getAllChatThreads(platformId, model);

assertTrue(response.isSuccess());
assertEquals(chatThreads, response.getData());
Expand All @@ -177,9 +177,9 @@ void talk() {
String message = "Hello";

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

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

assertEquals(emitter, result);
}
Expand All @@ -190,9 +190,9 @@ void history() {
Long threadId = 1L;
List<ChatMessageVO> history = new ArrayList<>();

when(chatService.history(platformId, threadId)).thenReturn(history);
when(chatbotService.history(platformId, threadId)).thenReturn(history);

ResponseEntity<List<ChatMessageVO>> response = chatController.history(platformId, threadId);
ResponseEntity<List<ChatMessageVO>> response = chatbotController.history(platformId, threadId);

assertTrue(response.isSuccess());
assertEquals(history, response.getData());
Expand Down

0 comments on commit 4dbc357

Please sign in to comment.