Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -46,73 +46,73 @@
import jakarta.annotation.Resource;
import java.util.List;

@Tag(name = "AI Chat Controller")
@Tag(name = "Chatbot 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 @@ -61,7 +61,7 @@ public enum ApiExceptionEnum {
COMMAND_NOT_FOUND(18000, LocaleKeys.COMMAND_NOT_FOUND),
COMMAND_NOT_SUPPORTED(18000, LocaleKeys.COMMAND_NOT_SUPPORTED),

// AI Chat Exceptions -- 19000 ~ 19999
// Chatbot Exceptions -- 19000 ~ 19999
PLATFORM_NOT_FOUND(19000, LocaleKeys.PLATFORM_NOT_FOUND),
PLATFORM_NOT_AUTHORIZED(19001, LocaleKeys.PLATFORM_NOT_AUTHORIZED),
PERMISSION_DENIED(19002, LocaleKeys.PERMISSION_DENIED),
Expand Down
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 @@ -372,9 +372,9 @@ CREATE TABLE `llm_chat_message`
INSERT INTO bigtop_manager.user (id, create_time, update_time, nickname, password, status, username)
VALUES (1, now(), now(), 'Administrator', '21232f297a57a5a743894a0e4a801fc3', true, 'admin');

-- Adding default ai chat platform
INSERT INTO bigtop_manager.llm_platform (id,credential,NAME,support_models)
-- Adding default llm platform
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'),
(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');
(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'),
(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 @@ -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