Skip to content

Commit 02ca841

Browse files
authored
BIGTOP-4244: Separate LLM Config and refactor APIs (#85)
1 parent 8a8f7ec commit 02ca841

16 files changed

Lines changed: 623 additions & 254 deletions

File tree

bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/po/AuthPlatformPO.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public class AuthPlatformPO extends BasePO implements Serializable {
4343

4444
@Column(name = "is_deleted")
4545
private Boolean isDeleted;
46+
47+
@Column(name = "status")
48+
private Integer status;
49+
50+
@Column(name = "name")
51+
private String name;
52+
53+
@Column(name = "model")
54+
private String model;
55+
56+
@Column(name = "desc")
57+
private String desc;
4658
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/ChatbotController.java

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@
1818
*/
1919
package org.apache.bigtop.manager.server.controller;
2020

21-
import org.apache.bigtop.manager.server.model.converter.AuthPlatformConverter;
22-
import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
23-
import org.apache.bigtop.manager.server.model.req.AuthPlatformReq;
2421
import org.apache.bigtop.manager.server.model.req.ChatbotMessageReq;
25-
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
22+
import org.apache.bigtop.manager.server.model.req.ChatbotThreadReq;
2623
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
2724
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
28-
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
29-
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
3025
import org.apache.bigtop.manager.server.service.ChatbotService;
3126
import org.apache.bigtop.manager.server.utils.ResponseEntity;
3227

3328
import org.springframework.web.bind.annotation.DeleteMapping;
3429
import org.springframework.web.bind.annotation.GetMapping;
3530
import org.springframework.web.bind.annotation.PathVariable;
3631
import org.springframework.web.bind.annotation.PostMapping;
32+
import org.springframework.web.bind.annotation.PutMapping;
3733
import org.springframework.web.bind.annotation.RequestBody;
3834
import org.springframework.web.bind.annotation.RequestMapping;
39-
import org.springframework.web.bind.annotation.RequestParam;
4035
import org.springframework.web.bind.annotation.RestController;
4136
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
4237

@@ -48,47 +43,23 @@
4843

4944
@Tag(name = "Chatbot Controller")
5045
@RestController
51-
@RequestMapping("/chatbot/")
46+
@RequestMapping("/llm/chatbot/")
5247
public class ChatbotController {
5348

5449
@Resource
5550
private ChatbotService chatbotService;
5651

57-
@Operation(summary = "get platforms", description = "Get all platforms")
58-
@GetMapping("/platforms")
59-
public ResponseEntity<List<PlatformVO>> platforms() {
60-
return ResponseEntity.success(chatbotService.platforms());
61-
}
62-
63-
@Operation(summary = "platform credentials", description = "Get platform auth credentials")
64-
@GetMapping("/platforms/{platformId}/auth-credentials")
65-
public ResponseEntity<List<PlatformAuthCredentialVO>> platformsAuthCredential(@PathVariable Long platformId) {
66-
return ResponseEntity.success(chatbotService.platformsAuthCredentials(platformId));
67-
}
68-
69-
@Operation(summary = "get auth platforms", description = "Get authorized platforms")
70-
@GetMapping("/auth-platforms")
71-
public ResponseEntity<List<AuthPlatformVO>> authorizedPlatforms() {
72-
return ResponseEntity.success(chatbotService.authorizedPlatforms());
73-
}
74-
75-
@Operation(summary = "auth platform", description = "Add authorized platforms")
76-
@PostMapping("/auth-platforms")
77-
public ResponseEntity<AuthPlatformVO> addAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
78-
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
79-
return ResponseEntity.success(chatbotService.addAuthorizedPlatform(authPlatformDTO));
80-
}
81-
82-
@Operation(summary = "delete auth platform", description = "Delete authorized platforms")
83-
@DeleteMapping("/auth-platforms/{authId}")
84-
public ResponseEntity<Boolean> deleteAuthorizedPlatform(@PathVariable Long authId) {
85-
return ResponseEntity.success(chatbotService.deleteAuthorizedPlatform(authId));
86-
}
87-
8852
@Operation(summary = "new thread", description = "Create a chat threads")
8953
@PostMapping("/auth-platforms/{authId}/threads")
90-
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long authId, @RequestParam String model) {
91-
return ResponseEntity.success(chatbotService.createChatThreads(authId, model));
54+
public ResponseEntity<ChatThreadVO> createChatThreads(@PathVariable Long authId) {
55+
return ResponseEntity.success(chatbotService.createChatThreads(authId, ""));
56+
}
57+
58+
@Operation(summary = "update thread", description = "Update a chat threads")
59+
@PutMapping("/auth-platforms/{authId}/threads")
60+
public ResponseEntity<ChatThreadVO> updateChatThreads(
61+
@PathVariable Long authId, @RequestBody ChatbotThreadReq chatbotThreadReq) {
62+
return ResponseEntity.success(chatbotService.createChatThreads(authId, ""));
9263
}
9364

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

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

10677
@Operation(summary = "talk", description = "Talk with Chatbot")
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.server.controller;
20+
21+
import org.apache.bigtop.manager.server.model.converter.AuthPlatformConverter;
22+
import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
23+
import org.apache.bigtop.manager.server.model.req.AuthPlatformReq;
24+
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
25+
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
26+
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
27+
import org.apache.bigtop.manager.server.service.LLMConfigService;
28+
import org.apache.bigtop.manager.server.utils.ResponseEntity;
29+
30+
import org.springframework.web.bind.annotation.DeleteMapping;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.PathVariable;
33+
import org.springframework.web.bind.annotation.PostMapping;
34+
import org.springframework.web.bind.annotation.PutMapping;
35+
import org.springframework.web.bind.annotation.RequestBody;
36+
import org.springframework.web.bind.annotation.RequestMapping;
37+
import org.springframework.web.bind.annotation.RestController;
38+
39+
import io.swagger.v3.oas.annotations.Operation;
40+
import io.swagger.v3.oas.annotations.tags.Tag;
41+
42+
import jakarta.annotation.Resource;
43+
import java.util.List;
44+
45+
@Tag(name = "LLM Config Controller")
46+
@RestController
47+
@RequestMapping("/llm/config/")
48+
public class LLMConfigController {
49+
50+
@Resource
51+
private LLMConfigService llmConfigService;
52+
53+
@Operation(summary = "get platforms", description = "Get all platforms")
54+
@GetMapping("/platforms")
55+
public ResponseEntity<List<PlatformVO>> platforms() {
56+
return ResponseEntity.success(llmConfigService.platforms());
57+
}
58+
59+
@Operation(summary = "platform credentials", description = "Get platform auth credentials")
60+
@GetMapping("/platforms/{platformId}/auth-credentials")
61+
public ResponseEntity<List<PlatformAuthCredentialVO>> platformsAuthCredential(@PathVariable Long platformId) {
62+
return ResponseEntity.success(llmConfigService.platformsAuthCredentials(platformId));
63+
}
64+
65+
@Operation(summary = "get auth platforms", description = "Get authorized platforms")
66+
@GetMapping("/auth-platforms")
67+
public ResponseEntity<List<AuthPlatformVO>> authorizedPlatforms() {
68+
return ResponseEntity.success(llmConfigService.authorizedPlatforms());
69+
}
70+
71+
@Operation(summary = "test auth platform", description = "Test authorized platforms")
72+
@PostMapping("/auth-platforms/test")
73+
public ResponseEntity<Boolean> testAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
74+
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
75+
return ResponseEntity.success(llmConfigService.testAuthorizedPlatform(authPlatformDTO));
76+
}
77+
78+
@Operation(summary = "add auth platform", description = "Add authorized platforms")
79+
@PostMapping("/auth-platforms")
80+
public ResponseEntity<AuthPlatformVO> addAuthorizedPlatform(@RequestBody AuthPlatformReq authPlatformReq) {
81+
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
82+
return ResponseEntity.success(llmConfigService.addAuthorizedPlatform(authPlatformDTO));
83+
}
84+
85+
@Operation(summary = "update auth platform", description = "Update authorized platforms")
86+
@PutMapping("/auth-platforms/{authId}")
87+
public ResponseEntity<AuthPlatformVO> updateAuthorizedPlatform(
88+
@PathVariable Long authId, @RequestBody AuthPlatformReq authPlatformReq) {
89+
AuthPlatformDTO authPlatformDTO = AuthPlatformConverter.INSTANCE.fromReq2DTO(authPlatformReq);
90+
authPlatformDTO.setId(authId);
91+
return ResponseEntity.success(llmConfigService.updateAuthorizedPlatform(authPlatformDTO));
92+
}
93+
94+
@Operation(summary = "delete auth platform", description = "Delete authorized platforms")
95+
@DeleteMapping("/auth-platforms/{authId}")
96+
public ResponseEntity<Boolean> deleteAuthorizedPlatform(@PathVariable Long authId) {
97+
return ResponseEntity.success(llmConfigService.deleteAuthorizedPlatform(authId));
98+
}
99+
100+
@Operation(summary = "activate auth platform", description = "Activate authorized platforms")
101+
@PostMapping("/auth-platforms/{authId}/activate")
102+
public ResponseEntity<Boolean> activateAuthorizedPlatform(@PathVariable Long authId) {
103+
return ResponseEntity.success(llmConfigService.activateAuthorizedPlatform(authId));
104+
}
105+
106+
@Operation(summary = "deactivate auth platform", description = "Deactivate authorized platforms")
107+
@PostMapping("/auth-platforms/{authId}/deactivate")
108+
public ResponseEntity<Boolean> deactivateAuthorizedPlatform(@PathVariable Long authId) {
109+
return ResponseEntity.success(llmConfigService.deactivateAuthorizedPlatform(authId));
110+
}
111+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.server.enums;
20+
21+
import lombok.Getter;
22+
23+
@Getter
24+
public enum AuthPlatformStatus {
25+
ACTIVE(1),
26+
AVAILABLE(2),
27+
UNAVAILABLE(3),
28+
;
29+
30+
private final Integer code;
31+
32+
AuthPlatformStatus(Integer code) {
33+
this.code = code;
34+
}
35+
36+
public static AuthPlatformStatus fromCode(Integer code) {
37+
for (AuthPlatformStatus status : AuthPlatformStatus.values()) {
38+
if (status.code.equals(code)) {
39+
return status;
40+
}
41+
}
42+
return UNAVAILABLE;
43+
}
44+
45+
public static boolean isAvailable(int code) {
46+
return AVAILABLE.code.equals(code);
47+
}
48+
49+
public static boolean isActive(int code) {
50+
return ACTIVE.code.equals(code);
51+
}
52+
53+
public static boolean available(int code) {
54+
return isAvailable(code) || isActive(code);
55+
}
56+
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/converter/AuthPlatformConverter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
public interface AuthPlatformConverter {
4444
AuthPlatformConverter INSTANCE = Mappers.getMapper(AuthPlatformConverter.class);
4545

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

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/dto/AuthPlatformDTO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public class AuthPlatformDTO {
2929
private Long platformId;
3030

3131
private Map<String, String> authCredentials;
32+
33+
private String name;
34+
35+
private String model;
36+
37+
private String desc;
38+
39+
private Boolean testPassed;
3240
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/req/AuthPlatformReq.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public class AuthPlatformReq {
3232

3333
@NotEmpty
3434
private List<AuthCredentialReq> authCredentials;
35+
36+
private String name;
37+
38+
private String model;
39+
40+
private String desc;
41+
42+
private boolean testPassed;
3543
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.bigtop.manager.server.model.req;
20+
21+
import lombok.Data;
22+
23+
@Data
24+
public class ChatbotThreadReq {
25+
private Long id;
26+
27+
private String name;
28+
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/model/vo/AuthPlatformVO.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public class AuthPlatformVO {
2828

2929
private String platformName;
3030

31-
private String supportModels;
31+
private String name;
3232

33-
public AuthPlatformVO(long platformId, String name, String models) {
34-
this.platformId = platformId;
35-
this.platformName = name;
36-
this.supportModels = models;
37-
}
33+
private String model;
34+
35+
private String desc;
36+
37+
private Integer status;
3838

3939
public AuthPlatformVO() {}
4040
}

bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/ChatbotService.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,15 @@
1818
*/
1919
package org.apache.bigtop.manager.server.service;
2020

21-
import org.apache.bigtop.manager.server.model.dto.AuthPlatformDTO;
22-
import org.apache.bigtop.manager.server.model.vo.AuthPlatformVO;
2321
import org.apache.bigtop.manager.server.model.vo.ChatMessageVO;
2422
import org.apache.bigtop.manager.server.model.vo.ChatThreadVO;
25-
import org.apache.bigtop.manager.server.model.vo.PlatformAuthCredentialVO;
26-
import org.apache.bigtop.manager.server.model.vo.PlatformVO;
2723

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

3026
import java.util.List;
3127

3228
public interface ChatbotService {
3329

34-
List<PlatformVO> platforms();
35-
36-
List<PlatformAuthCredentialVO> platformsAuthCredentials(Long platformId);
37-
38-
List<AuthPlatformVO> authorizedPlatforms();
39-
40-
AuthPlatformVO addAuthorizedPlatform(AuthPlatformDTO authPlatformDTO);
41-
42-
boolean deleteAuthorizedPlatform(Long authId);
43-
4430
ChatThreadVO createChatThreads(Long authId, String model);
4531

4632
boolean deleteChatThreads(Long authId, Long threadId);

0 commit comments

Comments
 (0)