[feature][chat]Add API to get ChatModelType list.#1739

This commit is contained in:
jerryjzhang
2024-10-09 14:56:34 +08:00
parent 485a4a19f3
commit 9ffe67c962
3 changed files with 36 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
package com.tencent.supersonic.chat.api.pojo.response;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChatModelTypeResp {
private String type;
private String name;
private String description;
}

View File

@@ -5,14 +5,18 @@ import javax.servlet.http.HttpServletResponse;
import com.tencent.supersonic.auth.api.authentication.pojo.User; import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder; import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.chat.api.pojo.response.ChatModelTypeResp;
import com.tencent.supersonic.chat.server.pojo.ChatModel; import com.tencent.supersonic.chat.server.pojo.ChatModel;
import com.tencent.supersonic.chat.server.service.ChatModelService; import com.tencent.supersonic.chat.server.service.ChatModelService;
import com.tencent.supersonic.chat.server.util.ModelConfigHelper; import com.tencent.supersonic.chat.server.util.ModelConfigHelper;
import com.tencent.supersonic.common.pojo.ChatModelConfig; import com.tencent.supersonic.common.pojo.ChatModelConfig;
import com.tencent.supersonic.common.pojo.enums.ChatModelType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping({"/api/chat/model", "/openapi/chat/model"}) @RequestMapping({"/api/chat/model", "/openapi/chat/model"})
@@ -45,6 +49,13 @@ public class ChatModelController {
return chatModelService.getChatModels(); return chatModelService.getChatModels();
} }
@RequestMapping("/getModelTypeList")
public List<ChatModelTypeResp> getModelTypeList() {
return Arrays.stream(ChatModelType.values()).map(t -> ChatModelTypeResp.builder()
.type(t.toString()).name(t.getName()).description(t.getDescription()).build())
.collect(Collectors.toList());
}
@PostMapping("/testConnection") @PostMapping("/testConnection")
public boolean testConnection(@RequestBody ChatModelConfig modelConfig) { public boolean testConnection(@RequestBody ChatModelConfig modelConfig) {
return ModelConfigHelper.testConnection(modelConfig); return ModelConfigHelper.testConnection(modelConfig);

View File

@@ -1,14 +1,19 @@
package com.tencent.supersonic.common.pojo.enums; package com.tencent.supersonic.common.pojo.enums;
import lombok.Getter;
@Getter
public enum ChatModelType { public enum ChatModelType {
TEXT_TO_SQL("Convert text query to SQL statement"), MULTI_TURN_REWRITE( TEXT_TO_SQL("SQL生成", "Convert text query to SQL statement"), MULTI_TURN_REWRITE("多轮改写",
"Rewrite text query for multi-turn conversation"), MEMORY_REVIEW( "Rewrite text query for multi-turn conversation"), MEMORY_REVIEW("记忆评估",
"Review memory in order to add few-shot examples"), RESPONSE_GENERATE( "Review memory in order to add few-shot examples"), RESPONSE_GENERATE("回复生成",
"Generate readable response to the end user"); "Generate readable response to the end user");
private String description; private String description;
private String name;
ChatModelType(String description) { ChatModelType(String name, String description) {
this.name = name;
this.description = description; this.description = description;
} }
} }