diff options
author | 2024-11-26 11:16:11 +0800 | |
---|---|---|
committer | 2024-11-26 09:38:08 +0000 | |
commit | 283366ed9269957357b8abc55f6e66a35b0d6144 (patch) | |
tree | 9255ddb68f62a31210e0cb50fdbc9151bcaf1ebf | |
parent | 297f7870a370452b22803c6eb62da35f99775eef (diff) |
Add platform registration function
Issue-ID: USECASEUI-844
Change-Id: Ide8d2dbd784619f5f2f04e1affa37cd1aca2a52c
Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
32 files changed, 801 insertions, 12 deletions
diff --git a/llm-adaptation/pom.xml b/llm-adaptation/pom.xml index 5f0909d..2d1f9c0 100644 --- a/llm-adaptation/pom.xml +++ b/llm-adaptation/pom.xml @@ -76,6 +76,17 @@ <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> + <dependency> + <groupId>org.mybatis.spring.boot</groupId> + <artifactId>mybatis-spring-boot-starter</artifactId> + <version>3.0.1</version> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.7.3</version> + <scope>runtime</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Application.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Application.java new file mode 100644 index 0000000..41fe3d1 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Application.java @@ -0,0 +1,38 @@ +package org.onap.usecaseui.llmadaptation.bean; + +import lombok.Data; + +@Data +public class Application { + private String applicationId; + + private String applicationName; + + private String applicationDescription; + + private String applicationType; + + private String operatorId; + + private String operatorName; + + private String maaSPlatformId; + + private String maaSPlatformName; + + private String knowledgeBaseName; + + private String knowledgeBaseId; + + private String largeModelName; + + private String largeModelId; + + private String prompt; + + private float temperature; + + private float top_p; + + private String openingRemarks; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/KnowledgeBase.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/KnowledgeBase.java new file mode 100644 index 0000000..9181dbb --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/KnowledgeBase.java @@ -0,0 +1,26 @@ +package org.onap.usecaseui.llmadaptation.bean; + +import lombok.Data; + +import java.util.List; + +@Data +public class KnowledgeBase { + private String knowledgeBaseId; + + private String knowledgeBaseName; + + private String knowledgeBaseDescription; + + private String operatorId; + + private String operatorName; + + private String maaSPlatformId; + + private String maaSPlatformName; + + private String updateTime; + + private List<String> filesName; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/MaaSPlatform.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/MaaSPlatform.java new file mode 100644 index 0000000..20443e9 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/MaaSPlatform.java @@ -0,0 +1,21 @@ +package org.onap.usecaseui.llmadaptation.bean; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class MaaSPlatform { + private String maaSPlatformId; + + private String maaSPlatformName; + + private String operatorId; + + private String operatorName; + + private List<ModelInformation> modelList; + +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ModelInformation.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ModelInformation.java new file mode 100644 index 0000000..e4e717f --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ModelInformation.java @@ -0,0 +1,10 @@ +package org.onap.usecaseui.llmadaptation.bean; + +import lombok.Data; + +@Data +public class ModelInformation { + private String modelId; + + private String modelName; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Operator.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Operator.java new file mode 100644 index 0000000..81bce0a --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/Operator.java @@ -0,0 +1,14 @@ +package org.onap.usecaseui.llmadaptation.bean; + +import lombok.Data; + +import java.util.List; + +@Data +public class Operator { + private String operatorId; + + private String operatorName; + + private List<MaaSPlatform> maaSPlatformList; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ResultHeader.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ResultHeader.java new file mode 100644 index 0000000..02dbe1a --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ResultHeader.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed 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 + * + * http://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.onap.usecaseui.llmadaptation.bean; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ResultHeader { + private int result_code; + + private String result_message; + + public ResultHeader() { + } + + public ResultHeader(int result_code, String result_message) { + this.result_code = result_code; + this.result_message = result_message; + } +}
\ No newline at end of file diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ServiceResult.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ServiceResult.java new file mode 100644 index 0000000..81c8cbe --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ServiceResult.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed 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 + * + * http://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.onap.usecaseui.llmadaptation.bean; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ServiceResult { + + private ResultHeader result_header; + private Object result_body; + + public ServiceResult() { + } + + public ServiceResult(ResultHeader result_header, Object result_body) { + this.result_header = result_header; + this.result_body = result_body; + } + + public ServiceResult(ResultHeader result_header) { + this.result_header = result_header; + } +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateCollectionParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateCollectionParam.java new file mode 100644 index 0000000..33b40b2 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateCollectionParam.java @@ -0,0 +1,20 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt; + +import lombok.Data; + +@Data +public class CreateCollectionParam { + private String trainingType; + + private String datasetId; + + private int chunkSize; + + private String chunkSplitter; + + private String fileId; + + private String name; + + private String qaPrompt; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetParam.java new file mode 100644 index 0000000..481773c --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetParam.java @@ -0,0 +1,18 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt; + +import lombok.Data; + +@Data +public class CreateDataSetParam { + private String type; + + private String avatar; + + private String name; + + private String intro; + + private String agentModel; + + private String vectorModel; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetResponse.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetResponse.java new file mode 100644 index 0000000..444c81a --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/CreateDataSetResponse.java @@ -0,0 +1,14 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt; + +import lombok.Data; + +@Data +public class CreateDataSetResponse { + private int code; + + private String statusText; + + private String message; + + private Object data; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatConfig.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatConfig.java new file mode 100644 index 0000000..f9ae487 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatConfig.java @@ -0,0 +1,25 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class ChatConfig { + private boolean questionGuide; + + private Map<String, Object> ttsConfig; + + private Map<String, Object> whisperConfig; + + private Map<String, Object> scheduledTriggerConfig; + + private Map<String, Object> chatInputGuide; + + private String instruction; + + private List<String> variables; + + private String welcomeText; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatParam.java new file mode 100644 index 0000000..346ea4e --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/ChatParam.java @@ -0,0 +1,23 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; + +import java.util.List; + +@Data +public class ChatParam { + private String appId; + + private String chatId; + + private boolean detail; + + private boolean stream; + + private String responseChatItemId; + + private JSONObject variables; + + private List<Message> messages; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/CreateApplicationParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/CreateApplicationParam.java new file mode 100644 index 0000000..f969f2f --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/CreateApplicationParam.java @@ -0,0 +1,20 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +import java.util.List; + +@Data +public class CreateApplicationParam { + private String parentId; + + private String avatar; + + private String name; + + private String type; + + private List<Module> modules; + + private List<Edge> edges; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Edge.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Edge.java new file mode 100644 index 0000000..74a6a22 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Edge.java @@ -0,0 +1,14 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +@Data +public class Edge { + private String source; + + private String target; + + private String sourceHandle; + + private String targetHandle; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Input.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Input.java new file mode 100644 index 0000000..a7bb599 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Input.java @@ -0,0 +1,38 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Input { + private String key; + + private List<String> renderTypeList; + + private String valueType; + + private String label; + + private Object value; + + private String debugLabel; + + private String toolDescription; + + private boolean required; + + private String description; + + private String placeholder; + + private int min; + + private int max; + + private int step; + + private List<String> list; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Message.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Message.java new file mode 100644 index 0000000..9066dbd --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Message.java @@ -0,0 +1,12 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +@Data +public class Message { + private String content; + + private String dataId; + + private String role; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Module.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Module.java new file mode 100644 index 0000000..118cb1b --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Module.java @@ -0,0 +1,30 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Module { + private String nodeId; + + private String name; + + private String intro; + + private String avatar; + + private String flowNodeType; + + private boolean showStatus; + + private Position position; + + private String version; + + private List<Input> inputs; + + private List<Output> outputs; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Output.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Output.java new file mode 100644 index 0000000..4b0711e --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Output.java @@ -0,0 +1,24 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Output { + private String id; + + private String key; + + private String label; + + private String type; + + private String valueType; + + private String description; + + private String valueDesc; + + private boolean required; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Position.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Position.java new file mode 100644 index 0000000..573c3a5 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/Position.java @@ -0,0 +1,10 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +@Data +public class Position { + private String x; + + private String y; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/PublishApplicationParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/PublishApplicationParam.java new file mode 100644 index 0000000..1166ac0 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/PublishApplicationParam.java @@ -0,0 +1,28 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +import java.util.List; + +@Data +public class PublishApplicationParam { + private List<Module> nodes; + + private List<Edge> edges; + + private ChatConfig chatConfig; + + private String type; + + private boolean isPublish; + + private String versionName; + + public boolean isIsPublish() { + return isPublish; + } + + public void setIsPublish(boolean publish) { + isPublish = publish; + } +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/UpdateApplicationParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/UpdateApplicationParam.java new file mode 100644 index 0000000..c6ba5ec --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/application/UpdateApplicationParam.java @@ -0,0 +1,14 @@ +package org.onap.usecaseui.llmadaptation.bean.fastgpt.application; + +import lombok.Data; + +@Data +public class UpdateApplicationParam { + private String avatar; + + private int defaultPermission; + + private String intro; + + private String name; +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/config/WebClientConfig.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/config/WebClientConfig.java new file mode 100644 index 0000000..d0a6926 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/config/WebClientConfig.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved. + * + * Licensed 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 + * + * http://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.onap.usecaseui.llmadaptation.config; + +import io.netty.channel.ChannelOption; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.netty.http.client.HttpClient; + +import java.time.Duration; + +@Configuration +public class WebClientConfig { + @Bean + public WebClient getWebClient() { + HttpClient httpClient = HttpClient.create() + .tcpConfiguration(tcpClient -> tcpClient + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)) + .responseTimeout(Duration.ofSeconds(10)); + return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient)).build(); + } +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/MaaSController.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/MaaSController.java new file mode 100644 index 0000000..4418287 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/MaaSController.java @@ -0,0 +1,38 @@ +package org.onap.usecaseui.llmadaptation.controller; + +import lombok.extern.slf4j.Slf4j; +import org.onap.usecaseui.llmadaptation.bean.*; +import org.onap.usecaseui.llmadaptation.mapper.MaaSPlatformMapper; +import org.onap.usecaseui.llmadaptation.service.MaaSService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/api/usecaseui-llm-adaptation/v1/") +public class MaaSController { + + @Autowired + private MaaSPlatformMapper maaSPlatformMapper; + + @Autowired + private MaaSService maaSService; + + @GetMapping(value = {"/operator/maas/getAll"}, produces = MediaType.APPLICATION_JSON_VALUE) + public ServiceResult getKnowledgeBaseRecord() { + List<Operator> allMaaSPlatform = maaSService.getAllMaaSPlatform(); + return new ServiceResult(new ResultHeader(200, "success"), allMaaSPlatform); + } + + @PostMapping(value = "/maas/register", produces = MediaType.APPLICATION_JSON_VALUE) + public ServiceResult registerMaaSPlatform(@RequestBody MaaSPlatform maaSPlatform) { + maaSPlatformMapper.insertMaaSPlatform(maaSPlatform); + maaSPlatformMapper.insertModel(maaSPlatform.getMaaSPlatformId(), maaSPlatform.getModelList()); + return new ServiceResult(new ResultHeader(200, "success")); + } + +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/MaaSPlatformMapper.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/MaaSPlatformMapper.java new file mode 100644 index 0000000..bfe4089 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/MaaSPlatformMapper.java @@ -0,0 +1,21 @@ +package org.onap.usecaseui.llmadaptation.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.onap.usecaseui.llmadaptation.bean.MaaSPlatform; +import org.onap.usecaseui.llmadaptation.bean.ModelInformation; + +import java.util.List; + +@Mapper +public interface MaaSPlatformMapper { + + int insertMaaSPlatform(@Param(value = "maaSPlatform") MaaSPlatform maaSPlatform); + + int insertModel(@Param(value = "maaSPlatformId") String maaSPlatformId, + @Param(value = "modelInformationList") List<ModelInformation> modelInformationList); + + List<MaaSPlatform> getMaaSPlatforms(); + + List<ModelInformation> getModelList(@Param(value = "maaSPlatformId") String maaSPlatformId); +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/MaaSService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/MaaSService.java new file mode 100644 index 0000000..0517887 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/MaaSService.java @@ -0,0 +1,10 @@ +package org.onap.usecaseui.llmadaptation.service; + +import org.onap.usecaseui.llmadaptation.bean.Operator; +import reactor.core.publisher.Mono; + +import java.util.List; + +public interface MaaSService { + List<Operator> getAllMaaSPlatform(); +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/LlmServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/LlmServiceImpl.java index bf751e2..262ccae 100644 --- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/LlmServiceImpl.java +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/LlmServiceImpl.java @@ -19,18 +19,15 @@ package org.onap.usecaseui.llmadaptation.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.nimbusds.jose.JOSEException; -import io.netty.channel.ChannelOption; import lombok.extern.slf4j.Slf4j; import org.onap.usecaseui.llmadaptation.bean.LargeModelRequestParam; import org.onap.usecaseui.llmadaptation.service.LlmService; import org.onap.usecaseui.llmadaptation.util.TokenUtil; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; -import reactor.netty.http.client.HttpClient; -import java.time.Duration; import java.util.ArrayList; import java.util.Optional; @@ -41,6 +38,10 @@ import static org.onap.usecaseui.llmadaptation.constant.LLMConstant.LARGE_MODEL_ @Slf4j @Service public class LlmServiceImpl implements LlmService { + + @Autowired + private WebClient webClient; + @Override public Flux<String> getStream(String question) { LargeModelRequestParam helpRequest = new LargeModelRequestParam(); @@ -53,13 +54,6 @@ public class LlmServiceImpl implements LlmService { if (token.isEmpty()) { return Flux.just("Token Error"); } - HttpClient httpClient = HttpClient.create() - .tcpConfiguration(tcpClient -> tcpClient - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)) - .responseTimeout(Duration.ofSeconds(10)); - WebClient webClient = WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(httpClient)) - .build(); return webClient.post() .uri(LARGE_MODEL_UIL) .bodyValue(helpRequest) diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/MaaSServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/MaaSServiceImpl.java new file mode 100644 index 0000000..10ee028 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/MaaSServiceImpl.java @@ -0,0 +1,52 @@ +package org.onap.usecaseui.llmadaptation.service.impl; + +import com.alibaba.fastjson2.JSONObject; +import io.netty.util.internal.StringUtil; +import lombok.extern.slf4j.Slf4j; +import org.onap.usecaseui.llmadaptation.bean.MaaSPlatform; +import org.onap.usecaseui.llmadaptation.bean.ModelInformation; +import org.onap.usecaseui.llmadaptation.bean.Operator; +import org.onap.usecaseui.llmadaptation.bean.fastgpt.CreateDataSetResponse; +import org.onap.usecaseui.llmadaptation.mapper.MaaSPlatformMapper; +import org.onap.usecaseui.llmadaptation.service.MaaSService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class MaaSServiceImpl implements MaaSService { + @Autowired + private WebClient webClient; + + @Autowired + private MaaSPlatformMapper maaSPlatformMapper; + + public List<Operator> getAllMaaSPlatform() { + List<Operator> operatorList = new ArrayList<>(); + List<MaaSPlatform> maaSPlatforms = maaSPlatformMapper.getMaaSPlatforms(); + Map<String, List<MaaSPlatform>> collect = maaSPlatforms.stream().collect(Collectors.groupingBy(MaaSPlatform::getOperatorId)); + collect.forEach((id, maaSPlatformList) -> { + Operator operator = new Operator(); + operator.setOperatorId(id); + operator.setOperatorName(maaSPlatformList.get(0).getOperatorName()); + maaSPlatformList.forEach(maaSPlatform -> { + List<ModelInformation> modelList = maaSPlatformMapper.getModelList(maaSPlatform.getMaaSPlatformId()); + maaSPlatform.setModelList(modelList); + maaSPlatform.setOperatorName(null); + maaSPlatform.setOperatorId(null); + }); + operator.setMaaSPlatformList(maaSPlatformList); + operatorList.add(operator); + }); + return operatorList; + } +} diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/TimeUtil.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/TimeUtil.java new file mode 100644 index 0000000..7b4ea53 --- /dev/null +++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/TimeUtil.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 CMCC, Inc. and others. All rights reserved. + * + * Licensed 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 + * + * http://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.onap.usecaseui.llmadaptation.util; + +import java.time.DayOfWeek; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class TimeUtil { + + public static final String timeFormat = "yyyy-MM-dd HH:mm:ss"; + + public static String getFormattedDateTime() { + LocalDateTime now = LocalDateTime.now(); + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timeFormat); + String formattedDateTime = now.format(dateTimeFormatter); + + DayOfWeek dayOfWeek = now.getDayOfWeek(); + String dayOfWeekString = dayOfWeek.toString(); + return formattedDateTime + " " + dayOfWeekString.charAt(0) + dayOfWeekString.substring(1).toLowerCase(); + } + + public static String getNowTime() { + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timeFormat); + return now.format(dateTimeFormatter); + } +} diff --git a/llm-adaptation/src/main/resources/application.yaml b/llm-adaptation/src/main/resources/application.yaml index f0c46ab..1b19cc1 100644 --- a/llm-adaptation/src/main/resources/application.yaml +++ b/llm-adaptation/src/main/resources/application.yaml @@ -1,2 +1,24 @@ server: - port: 8084
\ No newline at end of file + port: 8084 + +spring: + main: + allow-circular-references: true + datasource: + url: jdbc:postgresql://${POSTGRES_IP:127.0.0.1}:${POSTGRES_PORT:5432}/${POSTGRES_DB_NAME:uui} + username: ${POSTGRES_USERNAME:uui} + password: ${POSTGRES_PASSWORD:uui} + driver-class-name: org.postgresql.Driver + sql: + init: + schema-locations: classpath*:llm-adaptation-init.sql + mode: always +mybatis: + configuration: + database-id: PostgreSQL + mapper-locations: classpath*:mapper/*.xml + +logging: + level: + org.springframework.web: DEBUG + com.yourpackage: TRACE
\ No newline at end of file diff --git a/llm-adaptation/src/main/resources/llm-adaptation-init.sql b/llm-adaptation/src/main/resources/llm-adaptation-init.sql new file mode 100644 index 0000000..58a98c0 --- /dev/null +++ b/llm-adaptation/src/main/resources/llm-adaptation-init.sql @@ -0,0 +1,51 @@ +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +create table if not exists maas_platform( + maas_platform_id varchar(255) primary key, + maas_platform_name varchar(255), + operator_id varchar(255), + operator_name varchar(255) +); + +create table if not exists model_information( + model_id varchar(255) primary key, + model_name varchar(255), + maas_platform_id varchar(255) +); + +create table if not exists knowledge_base( + knowledge_base_id varchar(255) primary key, + knowledge_base_name varchar(255), + knowledge_base_description VARCHAR (225), + operator_id varchar(255), + operator_name varchar(255), + maas_platform_id varchar(255), + maas_platform_name varchar(255), + update_time timestamptz +); + +create table if not exists file( + file_id varchar(255) primary key, + file_name varchar(255), + knowledge_base_id varchar(255) +); + +create table if not exists application( + application_id varchar(255) primary key, + application_name varchar(255), + application_description varchar(255), + application_type varchar(255), + knowledge_base_id varchar(255), + model_id varchar(255), + model_name varchar(255), + prompt varchar(255), + temperature float, + top_p float, + opening_remarks varchar(255) +); + +create table if not exists cookie( + maas_platform_name varchar(255) primary key, + cookie text +) + diff --git a/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml b/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml new file mode 100644 index 0000000..b8d8354 --- /dev/null +++ b/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.onap.usecaseui.llmadaptation.mapper.MaaSPlatformMapper"> + <insert id="insertMaaSPlatform"> + insert into maas_platform(maas_platform_id,maas_platform_name,operator_id,operator_name) + values (#{maaSPlatform.maaSPlatformId}, + #{maaSPlatform.maaSPlatformName}, + #{maaSPlatform.operatorId}, + #{maaSPlatform.operatorName}) + </insert> + <insert id="insertModel"> + insert into model_information(model_id,model_name,maas_platform_id) + values + <foreach collection="modelInformationList" index="index" item="item" separator=","> + (#{item.modelId}, + #{item.modelName}, + #{maaSPlatformId}) + </foreach> + </insert> + <select id="getMaaSPlatforms" resultType="org.onap.usecaseui.llmadaptation.bean.MaaSPlatform"> + select maas_platform_id as maaSPlatformId, + maas_platform_name as maaSPlatformName, + operator_id as operatorId, + operator_name as operatorName + from maas_platform + </select> + <select id="getModelList" resultType="org.onap.usecaseui.llmadaptation.bean.ModelInformation"> + select model_id as modelId, + model_name as modelName + from model_information where maas_platform_id = #{maaSPlatformId} + </select> +</mapper>
\ No newline at end of file |