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 @@ -43,4 +43,16 @@ public class AuthPlatformPO extends BasePO implements Serializable {

@Column(name = "is_deleted")
private Boolean isDeleted;

@Column(name = "status")
private Integer status;

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

@Column(name = "model")
private String model;

@Column(name = "desc")
private String desc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@
*/
package org.apache.bigtop.manager.server.controller;

import org.apache.bigtop.manager.server.model.converter.AuthPlatformConverter;
import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
import org.apache.bigtop.manager.server.model.req.AuthPlatformReq;
import org.apache.bigtop.manager.server.model.req.ChatbotMessageReq;
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
import org.apache.bigtop.manager.server.model.req.ChatbotThreadReq;
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
import org.apache.bigtop.manager.server.service.ChatbotService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

Expand All @@ -48,47 +43,23 @@

@Tag(name = "Chatbot Controller")
@RestController
@RequestMapping("/chatbot/")
@RequestMapping("/llm/chatbot/")
public class ChatbotController {

@Resource
private ChatbotService chatbotService;

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

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

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

@Operation(summary = "auth platform", description = "Add authorized platforms")
@PostMapping("/auth-platforms")
public ResponseEntity<AuthPlatformVO> addAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
return ResponseEntity.success(chatbotService.addAuthorizedPlatform(authPlatformDTO));
}

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

@Operation(summary = "new thread", description = "Create a chat threads")
@PostMapping("/auth-platforms/{authId}/threads")
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long authId, @RequestParam String model) {
return ResponseEntity.success(chatbotService.createChatThreads(authId, model));
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long 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, ""));
}

@Operation(summary = "delete thread", description = "Delete a chat threads")
Expand All @@ -99,8 +70,8 @@ public ResponseEntity<Boolean> deleteChatThreads(@PathVariable Long authId, @Pat

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

@Operation(summary = "talk", description = "Talk with Chatbot")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.controller;

import org.apache.bigtop.manager.server.model.converter.AuthPlatformConverter;
import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
import org.apache.bigtop.manager.server.model.req.AuthPlatformReq;
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
import org.apache.bigtop.manager.server.service.LLMConfigService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.annotation.Resource;
import java.util.List;

@Tag(name = "LLM Config Controller")
@RestController
@RequestMapping("/llm/config/")
public class LLMConfigController {

@Resource
private LLMConfigService llmConfigService;

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

@Operation(summary = "platform credentials", description = "Get platform auth credentials")
@GetMapping("/platforms/{platformId}/auth-credentials")
public ResponseEntity<List<PlatformAuthCredentialVO>> platformsAuthCredential(@PathVariable Long platformId) {
return ResponseEntity.success(llmConfigService.platformsAuthCredentials(platformId));
}

@Operation(summary = "get auth platforms", description = "Get authorized platforms")
@GetMapping("/auth-platforms")
public ResponseEntity<List<AuthPlatformVO>> authorizedPlatforms() {
return ResponseEntity.success(llmConfigService.authorizedPlatforms());
}

@Operation(summary = "test auth platform", description = "Test authorized platforms")
@PostMapping("/auth-platforms/test")
public ResponseEntity<Boolean> testAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
return ResponseEntity.success(llmConfigService.testAuthorizedPlatform(authPlatformDTO));
}

@Operation(summary = "add auth platform", description = "Add authorized platforms")
@PostMapping("/auth-platforms")
public ResponseEntity<AuthPlatformVO> addAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
return ResponseEntity.success(llmConfigService.addAuthorizedPlatform(authPlatformDTO));
}

@Operation(summary = "update auth platform", description = "Update authorized platforms")
@PutMapping("/auth-platforms/{authId}")
public ResponseEntity<AuthPlatformVO> updateAuthorizedPlatform(
@PathVariable Long authId, @RequestBody AuthPlatformReq authPlatformReq) {
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
authPlatformDTO.setId(authId);
return ResponseEntity.success(llmConfigService.updateAuthorizedPlatform(authPlatformDTO));
}

@Operation(summary = "delete auth platform", description = "Delete authorized platforms")
@DeleteMapping("/auth-platforms/{authId}")
public ResponseEntity<Boolean> deleteAuthorizedPlatform(@PathVariable Long authId) {
return ResponseEntity.success(llmConfigService.deleteAuthorizedPlatform(authId));
}

@Operation(summary = "activate auth platform", description = "Activate authorized platforms")
@PostMapping("/auth-platforms/{authId}/activate")
public ResponseEntity<Boolean> activateAuthorizedPlatform(@PathVariable Long authId) {
return ResponseEntity.success(llmConfigService.activateAuthorizedPlatform(authId));
}

@Operation(summary = "deactivate auth platform", description = "Deactivate authorized platforms")
@PostMapping("/auth-platforms/{authId}/deactivate")
public ResponseEntity<Boolean> deactivateAuthorizedPlatform(@PathVariable Long authId) {
return ResponseEntity.success(llmConfigService.deactivateAuthorizedPlatform(authId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.enums;

import lombok.Getter;

@Getter
public enum AuthPlatformStatus {
ACTIVE(1),
AVAILABLE(2),
UNAVAILABLE(3),
;

private final Integer code;

AuthPlatformStatus(Integer code) {
this.code = code;
}

public static AuthPlatformStatus fromCode(Integer code) {
for (AuthPlatformStatus status : AuthPlatformStatus.values()) {
if (status.code.equals(code)) {
return status;
}
}
return UNAVAILABLE;
}

public static boolean isAvailable(int code) {
return AVAILABLE.code.equals(code);
}

public static boolean isActive(int code) {
return ACTIVE.code.equals(code);
}

public static boolean available(int code) {
return isAvailable(code) || isActive(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
public interface AuthPlatformConverter {
AuthPlatformConverter INSTANCE = Mappers.getMapper(AuthPlatformConverter.class);

@Mapping(target = "supportModels", expression = "java(platformPO.getSupportModels())")
@Mapping(target = "platformName", expression = "java(platformPO.getName())")
AuthPlatformVO fromPO2VO(AuthPlatformPO authPlatformPO, @Context PlatformPO platformPO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public class AuthPlatformDTO {
private Long platformId;

private Map<String, String> authCredentials;

private String name;

private String model;

private String desc;

private Boolean testPassed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public class AuthPlatformReq {

@NotEmpty
private List<AuthCredentialReq> authCredentials;

private String name;

private String model;

private String desc;

private boolean testPassed;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

@Data
public class ChatbotThreadReq {
private Long id;

private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public class AuthPlatformVO {

private String platformName;

private String supportModels;
private String name;

public AuthPlatformVO(long platformId, String name, String models) {
this.platformId = platformId;
this.platformName = name;
this.supportModels = models;
}
private String model;

private String desc;

private Integer status;

public AuthPlatformVO() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,15 @@
*/
package org.apache.bigtop.manager.server.service;

import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
import org.apache.bigtop.manager.server.model.vo.PlatformVO;

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.List;

public interface ChatbotService {

List<PlatformVO> platforms();

List<PlatformAuthCredentialVO> platformsAuthCredentials(Long platformId);

List<AuthPlatformVO> authorizedPlatforms();

AuthPlatformVO addAuthorizedPlatform(AuthPlatformDTO authPlatformDTO);

boolean deleteAuthorizedPlatform(Long authId);

ChatThreadVO createChatThreads(Long authId, String model);

boolean deleteChatThreads(Long authId, Long threadId);
Expand Down
Loading