Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -41,6 +41,15 @@ public class AuthPlatformPO extends BasePO implements Serializable {
@Column(name = "platform_id", nullable = false)
private Long platformId;

@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 = "notes")
private String notes;
}
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,103 @@
/*
* 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);

if (authPlatformDTO.getIsActive() != null) {
return ResponseEntity.success(llmConfigService.switchAuthPlatform(authPlatformDTO));
}
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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 {
DELETED(-1),
NORMAL(0),
ACTIVE(1),
UNAVAILABLE(2),
;

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 NORMAL;
}

public static boolean isNormal(int code) {
return NORMAL.code.equals(code);
}

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

public static boolean isAvailable(int code) {
return isNormal(code) || isActive(code);
}

public static boolean isDeleted(int code) {
return DELETED.code.equals(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 All @@ -60,6 +59,19 @@ default Map<String, String> mapAuthCredentials(List<AuthCredentialReq> authCrede
@AfterMapping
default void afterMapping(@MappingTarget AuthPlatformDTO authPlatformDTO, AuthPlatformReq authPlatformReq) {
authPlatformDTO.setAuthCredentials(mapAuthCredentials(authPlatformReq.getAuthCredentials()));
if (authPlatformReq.isActive()) {
authPlatformDTO.setIsActive(true);
} else if (authPlatformReq.isInactive()) {
authPlatformDTO.setIsActive(false);
} else {
authPlatformDTO.setIsActive(null);
}

if (authPlatformReq.isTest()) {
authPlatformDTO.setIsTested(true);
} else {
authPlatformDTO.setIsTested(false);
}
}

@Mapping(source = "authCredentials", target = "credentials", qualifiedByName = "map2String")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ public class AuthPlatformDTO {
private Long platformId;

private Map<String, String> authCredentials;

private String name;

private String model;

private String notes;

private Boolean isTested;

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

@NotEmpty
private List<AuthCredentialReq> authCredentials;

private String name;

private String model;

private String notes;

private boolean isTest;

private boolean active;

private boolean inactive;
}
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,12 +28,18 @@ public class AuthPlatformVO {

private String platformName;

private String supportModels;
private String name;

private String model;

private String notes;

private Integer status;

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

public AuthPlatformVO() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class PlatformAuthCredentialVO {

private String displayName;

private String description;

public PlatformAuthCredentialVO(String name, String displayName) {
this.name = name;
this.displayName = displayName;
Expand Down
Loading