Skip to content

Commit

Permalink
new api
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Oct 9, 2024
1 parent 59e833b commit b977230
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 114 deletions.
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,90 @@
/*
* 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.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.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 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 = "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(chatbotService.addAuthorizedPlatform(authPlatformDTO));
}

@Operation(summary = "update auth platform", description = "Update authorized platforms")
@PutMapping("/auth-platforms")
public ResponseEntity<AuthPlatformVO> updateAuthorizedPlatform(@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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public interface AuthPlatformConverter {
AuthPlatformConverter INSTANCE = Mappers.getMapper(AuthPlatformConverter.class);

@Mapping(target = "supportModels", expression = "java(platformPO.getSupportModels())")
@Mapping(target = "model", 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 @@ -32,4 +32,10 @@ public class AuthPlatformReq {

@NotEmpty
private List<AuthCredentialReq> authCredentials;

private String name;

private String model;

private String notes;
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.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 LLMConfigService {

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);

List<ChatThreadVO> getAllChatThreads(Long platformId, String model);

SseEmitter talk(Long authId, Long threadId, String message);

List<ChatMessageVO> history(Long platformId, Long threadId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public AuthPlatformVO addAuthorizedPlatform(AuthPlatformDTO authPlatformDTO) {
AuthPlatformPO authPlatformPO = AuthPlatformConverter.INSTANCE.fromDTO2PO(authPlatformDTO);
authPlatformDao.save(authPlatformPO);
AuthPlatformVO authPlatformVO = AuthPlatformConverter.INSTANCE.fromPO2VO(authPlatformPO, platformPO);
authPlatformVO.setSupportModels(platformPO.getSupportModels());
authPlatformVO.setModel(platformPO.getSupportModels());
authPlatformVO.setPlatformName(platformPO.getName());
return authPlatformVO;
}
Expand Down
Loading

0 comments on commit b977230

Please sign in to comment.