summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaixiliu <liukaixi@chinamobile.com>2025-01-15 10:26:15 +0800
committerKaixi LIU <liukaixi@chinamobile.com>2025-01-15 02:48:42 +0000
commit1e940360db0bcd69d0061f90da68999bb3d51b1a (patch)
tree0abe0f589cd5d1d7d3fb442e2a7ec0624776171e
parent73323cea663c51ede9ebbe005df10cda0f102f8f (diff)
Modify the knowledge base and application functions15.0.1
1. Add a file deletion interface 2. Add an upload file interface 3. Modify the editing interface Issue-ID: USECASEUI-844 Change-Id: Iaa4061fdcbddbeee3766e22d1ab0258a78657cfa Signed-off-by: kaixiliu <liukaixi@chinamobile.com>
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/File.java15
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/KnowledgeBase.java2
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/MaaSPlatform.java5
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/dataset/CreateDataSetParam.java4
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/BiShengConstant.java2
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/FastGptConstant.java8
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/ServerConstant.java28
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/DatasetController.java11
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/ApplicationMapper.java2
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/DatasetMapper.java9
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java8
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengDatasetService.java11
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/DatasetService.java4
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java8
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptDatasetService.java11
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java50
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java29
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengDatasetServiceImpl.java70
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/DatasetServiceImpl.java79
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java64
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptDatasetServiceImpl.java109
-rw-r--r--llm-adaptation/src/main/resources/application.yaml8
-rw-r--r--llm-adaptation/src/main/resources/llm-adaptation-init.sql4
-rw-r--r--llm-adaptation/src/main/resources/mapper/ApplicationMapper.xml52
-rw-r--r--llm-adaptation/src/main/resources/mapper/DatasetMapper.xml21
-rw-r--r--llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml14
26 files changed, 386 insertions, 242 deletions
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/File.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/File.java
new file mode 100644
index 0000000..2fb5574
--- /dev/null
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/File.java
@@ -0,0 +1,15 @@
+package org.onap.usecaseui.llmadaptation.bean;
+
+import lombok.Data;
+
+@Data
+public class File {
+ private String fileId;
+
+ private String fileName;
+
+ public File(String fileId, String fileName) {
+ this.fileId = fileId;
+ this.fileName = fileName;
+ }
+}
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
index 9181dbb..2eb6890 100644
--- 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
@@ -22,5 +22,5 @@ public class KnowledgeBase {
private String updateTime;
- private List<String> filesName;
+ private List<File> fileList;
}
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
index 156aa76..0ae83db 100644
--- 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
@@ -18,6 +18,9 @@ public class MaaSPlatform {
private String maaSType;
- private List<ModelInformation> modelList;
+ private String serverIp;
+
+ private String vectorModel;
+ private List<ModelInformation> modelList;
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/dataset/CreateDataSetParam.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/dataset/CreateDataSetParam.java
index b22b90a..39ef046 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/dataset/CreateDataSetParam.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/fastgpt/dataset/CreateDataSetParam.java
@@ -6,13 +6,9 @@ import lombok.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/constant/BiShengConstant.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/BiShengConstant.java
index 3a9a3bc..63d1202 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/BiShengConstant.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/BiShengConstant.java
@@ -18,4 +18,6 @@ public class BiShengConstant {
public static final String DELETE_APPLICATION = "/api/v1/assistant/delete?assistant_id=";
public static final String GET_APPLICATION_URL = "/api/v1/assistant/info/";
+
+ public static final String DELETE_FILE_URL = "/api/v1/knowledge/file/";
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/FastGptConstant.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/FastGptConstant.java
index a4fb335..8bdc77e 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/FastGptConstant.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/FastGptConstant.java
@@ -1,7 +1,7 @@
package org.onap.usecaseui.llmadaptation.constant;
public class FastGptConstant {
- public static final String COOKIE_VALUE = "fastgpt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NzFmNTQ2MGM4Zjc3YTFjMGYzZTUyYmEiLCJ0ZWFtSWQiOiI2NzFmNTQ2MGM4Zjc3YTFjMGYzZTUyYzAiLCJ0bWJJZCI6IjY3MWY1NDYwYzhmNzdhMWMwZjNlNTJjMiIsImlzUm9vdCI6dHJ1ZSwiZXhwIjoxNzM1NTIzMzY0LCJpYXQiOjE3MzQ5MTg1NjR9.GPomC4qSnz3ADnEIo4sgl8jROaCsomEh9J6kfVAZuBQ";
+ public static final String COOKIE_VALUE = "fastgpt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NzFmNTQ2MGM4Zjc3YTFjMGYzZTUyYmEiLCJ0ZWFtSWQiOiI2NzFmNTQ2MGM4Zjc3YTFjMGYzZTUyYzAiLCJ0bWJJZCI6IjY3MWY1NDYwYzhmNzdhMWMwZjNlNTJjMiIsImlzUm9vdCI6dHJ1ZSwiZXhwIjoxOTU2NTQyOTczLCJpYXQiOjE3MzU3OTA5NzN9.T0RPpbST7FuRTusBkd1HzolfqNsIu7ZzvcrZOmq-mN0";
public static final String CREATE_DATASET_URL = "/api/core/dataset/create";
@@ -26,4 +26,10 @@ public class FastGptConstant {
public static final String APPLICATION_CHAT_URL = "/api/v1/chat/completions";
public static final String DELETE_APPLICATION = "/api/core/app/del?appId=";
+
+ public static final String FAST_GPT = "fastGpt";
+
+ public static final String DELETE_FILE_URL = "/api/core/dataset/collection/delete?id=";
+
+ public static final String GET_COLLECTION_LIST_URL = "/api/core/dataset/collection/list";
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/ServerConstant.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/ServerConstant.java
deleted file mode 100644
index efc6012..0000000
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/constant/ServerConstant.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.onap.usecaseui.llmadaptation.constant;
-
-import lombok.Getter;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-@Component
-@Getter
-public class ServerConstant {
-
- @Value("${fastGpt.server}")
- private String fastGptServer;
-
- @Value("${biSheng.server}")
- private String biShengServer;
-
- @Value("${fastGpt.model}")
- private String fastGptModel;
-
- @Value("${biSheng.model}")
- private int biShengModel;
-
- @Value("${fastGpt.maaSType}")
- private String fastGptType;
-
- @Value("${biSheng.maaSType}")
- private String biShengType;
-}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/DatasetController.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/DatasetController.java
index af2a672..62ecf96 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/DatasetController.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/DatasetController.java
@@ -58,4 +58,15 @@ public class DatasetController {
public Mono<ServiceResult> editDataset(@RequestBody KnowledgeBase knowledgeBase) {
return datasetService.editDataset(knowledgeBase);
}
+
+ @PostMapping(value = "/file/upload", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono<ServiceResult> uploadFiles(@RequestPart("files") Flux<FilePart> fileParts,
+ @RequestPart("metaData") String metaData) {
+ return datasetService.uploadFiles(fileParts, metaData);
+ }
+
+ @DeleteMapping(value = "/file/delete/{fileId}", produces = MediaType.APPLICATION_JSON_VALUE)
+ public Mono<ServiceResult> deleteFile(@PathVariable("fileId") String fileId) {
+ return datasetService.deleteFile(fileId);
+ }
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/ApplicationMapper.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/ApplicationMapper.java
index 0937eed..22aeef2 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/ApplicationMapper.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/ApplicationMapper.java
@@ -17,4 +17,6 @@ public interface ApplicationMapper {
Application getApplicationById(@Param(value = "applicationId") String applicationId);
int updateApplication(@Param(value = "application") Application application);
+
+ List<Application> getApplicationByDatasetId(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/DatasetMapper.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/DatasetMapper.java
index 5882061..575bae9 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/DatasetMapper.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/mapper/DatasetMapper.java
@@ -2,6 +2,7 @@ package org.onap.usecaseui.llmadaptation.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
+import org.onap.usecaseui.llmadaptation.bean.File;
import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
import java.util.List;
@@ -10,11 +11,11 @@ import java.util.List;
public interface DatasetMapper {
int insertKnowledgeBaseRecord(@Param(value = "knowledgeBase") KnowledgeBase knowledgeBase);
- int insertFileName(@Param(value = "fileId") String fileId,@Param(value = "fileName") String fileName,@Param(value = "knowledgeBaseId") String knowledgeBaseId);
+ int insertFileName(@Param(value = "files") List<File> files, @Param(value = "knowledgeBaseId") String knowledgeBaseId);
List<KnowledgeBase> getKnowledgeBaseRecords();
- List<String> getFileNamesByKnowledgeBaseId(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
+ List<File> getFileNamesByKnowledgeBaseId(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
KnowledgeBase getKnowledgeBaseRecordById(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
@@ -25,4 +26,8 @@ public interface DatasetMapper {
int deleteFileById(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
int updateKnowledgeBase(@Param(value = "knowledgeBase") KnowledgeBase knowledgeBase);
+
+ int deleteFileByFileId(@Param(value = "fileId") String fileId);
+
+ String getKnowledgeIdByFileId(@Param(value = "fileId") String fileId);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java
index 8f600c4..391a146 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java
@@ -7,11 +7,11 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface BiShengApplicationService {
- Mono<ServiceResult> createApplication(Application application);
+ Mono<ServiceResult> createApplication(Application application, String serverIp);
- Flux<String> chat(JSONObject question);
+ Flux<String> chat(JSONObject question, String serverIp);
- Mono<ServiceResult> removeApplication(String applicationId);
+ Mono<ServiceResult> removeApplication(String applicationId, String serverIp);
- Mono<ServiceResult> editApplication(Application application);
+ Mono<ServiceResult> editApplication(Application application, String serverIp);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengDatasetService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengDatasetService.java
index 27716d7..445b6ea 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengDatasetService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengDatasetService.java
@@ -1,15 +1,20 @@
package org.onap.usecaseui.llmadaptation.service;
import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
+import org.onap.usecaseui.llmadaptation.bean.MaaSPlatform;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import org.springframework.http.codec.multipart.FilePart;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface BiShengDatasetService {
- Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData);
+ Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData, MaaSPlatform maaSPlatform);
- Mono<ServiceResult> removeDataset(String knowledgeBaseId);
+ Mono<ServiceResult> removeDataset(String knowledgeBaseId, String serverIp);
- Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase);
+ Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase, MaaSPlatform maaSPlatform);
+
+ Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts, String knowledgeBaseId, String serverIp);
+
+ Mono<ServiceResult> deleteFile(String fileId, String serverIp);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/DatasetService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/DatasetService.java
index f213362..0f7cbdf 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/DatasetService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/DatasetService.java
@@ -16,4 +16,8 @@ public interface DatasetService {
ServiceResult geDatasetById(String knowledgeBaseId);
Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase);
+
+ Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts, String metaData);
+
+ Mono<ServiceResult> deleteFile(String fileId);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java
index 6d09e6f..2d02778 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java
@@ -7,11 +7,11 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface FastGptApplicationService {
- Mono<ServiceResult> createApplication(Application application);
+ Mono<ServiceResult> createApplication(Application application, String serverIp);
- Flux<String> chat(JSONObject question);
+ Flux<String> chat(JSONObject question, String serverIp);
- Mono<ServiceResult> removeApplication(String applicationId);
+ Mono<ServiceResult> removeApplication(String applicationId, String serverIp);
- Mono<ServiceResult> editApplication(Application application);
+ Mono<ServiceResult> editApplication(Application application, String serverIp);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptDatasetService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptDatasetService.java
index 47356b8..cba4d5b 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptDatasetService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptDatasetService.java
@@ -1,15 +1,20 @@
package org.onap.usecaseui.llmadaptation.service;
import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
+import org.onap.usecaseui.llmadaptation.bean.MaaSPlatform;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import org.springframework.http.codec.multipart.FilePart;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface FastGptDatasetService {
- Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData);
+ Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData, MaaSPlatform maaSPlatform);
- Mono<ServiceResult> removeDataset(String knowledgeBaseId);
+ Mono<ServiceResult> removeDataset(String knowledgeBaseId, String serverIp);
- Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase);
+ Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase,MaaSPlatform maaSPlatform);
+
+ Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts,String knowledgeBaseId, String serverIp);
+
+ Mono<ServiceResult> deleteFile(String fileId, String serverIp);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java
index ae9a515..be3411a 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java
@@ -3,7 +3,7 @@ package org.onap.usecaseui.llmadaptation.service.impl;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.onap.usecaseui.llmadaptation.bean.*;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
+import org.onap.usecaseui.llmadaptation.constant.FastGptConstant;
import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.mapper.DatasetMapper;
import org.onap.usecaseui.llmadaptation.mapper.MaaSPlatformMapper;
@@ -36,9 +36,6 @@ public class ApplicationServiceImpl implements ApplicationService {
@Autowired
private MaaSPlatformMapper maaSPlatformMapper;
- @Autowired
- private ServerConstant serverConstant;
-
@Override
public Mono<ServiceResult> createApplication(Application application) {
List<Application> applications = applicationMapper.getAllApplication();
@@ -48,37 +45,34 @@ public class ApplicationServiceImpl implements ApplicationService {
return Mono.just(new ServiceResult(new ResultHeader(500, "name exists"), applications));
}
}
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(application.getMaaSPlatformId());
+ MaaSPlatform maaSPlatformById = getMaaSPlatFormById(application.getMaaSPlatformId());
if (maaSPlatformById == null) {
return Mono.just(new ServiceResult(new ResultHeader(500, "maas is not exist")));
}
String maaSType = maaSPlatformById.getMaaSType();
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptApplicationService.createApplication(application);
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptApplicationService.createApplication(application, maaSPlatformById.getServerIp());
}
- return biShengApplicationService.createApplication(application);
+ return biShengApplicationService.createApplication(application, maaSPlatformById.getServerIp());
}
@Override
public Mono<ServiceResult> removeApplication(String applicationId) {
- String maaSType = getMaaSType(applicationId);
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptApplicationService.removeApplication(applicationId);
+ MaaSPlatform maaSPlatform = getMaaSPlatFormByAppId(applicationId);
+ if (FastGptConstant.FAST_GPT.equals(maaSPlatform.getMaaSType())) {
+ return fastGptApplicationService.removeApplication(applicationId, maaSPlatform.getServerIp());
}
- return biShengApplicationService.removeApplication(applicationId);
+ return biShengApplicationService.removeApplication(applicationId, maaSPlatform.getServerIp());
}
@Override
public Flux<String> chat(JSONObject question) {
String applicationId = question.getString("applicationId");
- String maaSType = getMaaSType(applicationId);
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptApplicationService.chat(question);
+ MaaSPlatform maaSPlatform = getMaaSPlatFormByAppId(applicationId);
+ if (FastGptConstant.FAST_GPT.equals(maaSPlatform.getMaaSType())) {
+ return fastGptApplicationService.chat(question, maaSPlatform.getServerIp());
}
- return biShengApplicationService.chat(question);
+ return biShengApplicationService.chat(question, maaSPlatform.getServerIp());
}
@Override
@@ -117,22 +111,24 @@ public class ApplicationServiceImpl implements ApplicationService {
@Override
public Mono<ServiceResult> editApplication(Application application) {
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(application.getMaaSPlatformId());
+ MaaSPlatform maaSPlatformById = getMaaSPlatFormById(application.getMaaSPlatformId());
if (maaSPlatformById == null) {
return Mono.just(new ServiceResult(new ResultHeader(500, "maas is not exist")));
}
String maaSType = maaSPlatformById.getMaaSType();
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptApplicationService.editApplication(application);
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptApplicationService.editApplication(application, maaSPlatformById.getServerIp());
}
- return biShengApplicationService.editApplication(application);
+ return biShengApplicationService.editApplication(application, maaSPlatformById.getServerIp());
}
- private String getMaaSType(String applicationId) {
+ private MaaSPlatform getMaaSPlatFormByAppId(String applicationId) {
Application applicationById = applicationMapper.getApplicationById(applicationId);
KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(applicationById.getKnowledgeBaseId());
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(knowledgeBaseRecordById.getMaaSPlatformId());
- return maaSPlatformById.getMaaSType();
+ return getMaaSPlatFormById(knowledgeBaseRecordById.getMaaSPlatformId());
+ }
+
+ private MaaSPlatform getMaaSPlatFormById(String maaSPlatformId) {
+ return maaSPlatformMapper.getMaaSPlatformById(maaSPlatformId);
}
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java
index 737fc66..309e013 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java
@@ -9,7 +9,6 @@ import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import org.onap.usecaseui.llmadaptation.bean.bisheng.BiShengCreateDatasetResponse;
import org.onap.usecaseui.llmadaptation.constant.BiShengConstant;
import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.service.BiShengApplicationService;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
@@ -33,17 +32,14 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
@Autowired
private WebClient webClient;
- @Autowired
- private ServerConstant serverConstant;
-
@Override
- public Mono<ServiceResult> createApplication(Application application) {
+ public Mono<ServiceResult> createApplication(Application application, String serverIp) {
JSONObject createParam = new JSONObject();
createParam.put("logo", "");
createParam.put("name", application.getApplicationName());
createParam.put("prompt", application.getPrompt());
return webClient.post()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.APPLICATION_URL)
+ .uri(serverIp + BiShengConstant.APPLICATION_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.bodyValue(createParam)
@@ -55,6 +51,7 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
return Mono.just(new ServiceResult(new ResultHeader(createResponse.getStatus_code(), createResponse.getStatus_message())));
}
String applicationId = data.getString("id");
+ data.put("desc", application.getApplicationDescription());
data.put("model_name", application.getLargeModelId());
data.put("temperature", application.getTemperature() / 10);
List<Integer> list = new ArrayList<>();
@@ -63,7 +60,7 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
data.put("guide_word", application.getOpeningRemarks());
data.put("update_time", TimeUtil.getNowTime());
return webClient.put()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.APPLICATION_URL)
+ .uri(serverIp + BiShengConstant.APPLICATION_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.bodyValue(data)
@@ -81,7 +78,7 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
}
@Override
- public Flux<String> chat(JSONObject question) {
+ public Flux<String> chat(JSONObject question, String serverIp) {
JSONObject param = new JSONObject();
param.put("model", question.getString("applicationId"));
param.put("temperature", 0);
@@ -93,7 +90,7 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
jsonArray.add(message);
param.put("messages", jsonArray);
return webClient.post()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.APPLICATION_CHAT_URL)
+ .uri(serverIp + BiShengConstant.APPLICATION_CHAT_URL)
.bodyValue(param)
.retrieve()
.bodyToFlux(String.class)
@@ -114,8 +111,8 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
}
@Override
- public Mono<ServiceResult> removeApplication(String applicationId) {
- String url = serverConstant.getBiShengServer() + BiShengConstant.DELETE_APPLICATION + applicationId;
+ public Mono<ServiceResult> removeApplication(String applicationId, String serverIp) {
+ String url = serverIp + BiShengConstant.DELETE_APPLICATION + applicationId;
return webClient.post()
.uri(url)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
@@ -141,8 +138,8 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
}
@Override
- public Mono<ServiceResult> editApplication(Application application) {
- String url = serverConstant.getBiShengServer() + BiShengConstant.GET_APPLICATION_URL + application.getApplicationId();
+ public Mono<ServiceResult> editApplication(Application application, String serverIp) {
+ String url = serverIp + BiShengConstant.GET_APPLICATION_URL + application.getApplicationId();
return webClient.get()
.uri(url)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
@@ -159,8 +156,12 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
List<Integer> list = new ArrayList<>();
list.add(Integer.valueOf(application.getKnowledgeBaseId()));
data.put("knowledge_list", list);
+ data.put("model_name", application.getLargeModelId());
+ data.put("temperature", application.getTemperature() / 10);
+ data.put("prompt",application.getPrompt());
+ data.put("guide_word", application.getOpeningRemarks());
return webClient.put()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.APPLICATION_URL)
+ .uri(serverIp + BiShengConstant.APPLICATION_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.bodyValue(data)
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengDatasetServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengDatasetServiceImpl.java
index bc1cec0..f12be8d 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengDatasetServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengDatasetServiceImpl.java
@@ -3,14 +3,11 @@ package org.onap.usecaseui.llmadaptation.service.impl;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
-import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
-import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
-import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
+import org.onap.usecaseui.llmadaptation.bean.*;
import org.onap.usecaseui.llmadaptation.bean.bisheng.BiShengCreateDatasetResponse;
import org.onap.usecaseui.llmadaptation.bean.bisheng.ProcessFileResponse;
import org.onap.usecaseui.llmadaptation.constant.BiShengConstant;
import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
import org.onap.usecaseui.llmadaptation.mapper.DatasetMapper;
import org.onap.usecaseui.llmadaptation.service.BiShengDatasetService;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
@@ -26,7 +23,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import java.util.UUID;
+import java.util.List;
import static org.springframework.http.MediaType.APPLICATION_JSON;
@@ -40,19 +37,18 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
@Autowired
private DatasetMapper datasetMapper;
- @Autowired
- private ServerConstant serverConstant;
@Override
- public Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData) {
+ public Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData, MaaSPlatform maaSPlatform) {
+
KnowledgeBase knowledgeBase = JSONObject.parseObject(metaData, KnowledgeBase.class);
knowledgeBase.setUpdateTime(TimeUtil.getNowTime());
JSONObject createParam = new JSONObject();
createParam.put("description", knowledgeBase.getKnowledgeBaseDescription());
- createParam.put("model", serverConstant.getBiShengModel());
+ createParam.put("model", maaSPlatform.getVectorModel());
createParam.put("name", knowledgeBase.getKnowledgeBaseName());
return webClient.post()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.CREATE_DATASET_URL)
+ .uri(maaSPlatform.getServerIp() + BiShengConstant.CREATE_DATASET_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.bodyValue(createParam)
@@ -63,7 +59,7 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatus_message())));
}
int knowledgeBaseId = response.getData().getIntValue("id");
- return fileParts.flatMap(filePart -> processFile(filePart, knowledgeBaseId))
+ return fileParts.flatMap(filePart -> processFile(filePart, knowledgeBaseId, maaSPlatform.getServerIp()))
.then(Mono.defer(() -> {
knowledgeBase.setKnowledgeBaseId(String.valueOf(knowledgeBaseId));
datasetMapper.insertKnowledgeBaseRecord(knowledgeBase);
@@ -78,7 +74,7 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
});
}
- private Mono<Void> processFile(FilePart filePart, int knowledgeBaseId) {
+ private Mono<Void> processFile(FilePart filePart, int knowledgeBaseId, String serverIp) {
String filename = filePart.filename();
Flux<DataBuffer> content = filePart.content();
MultipartBodyBuilder builder = new MultipartBodyBuilder();
@@ -93,7 +89,7 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
headers.setContentType(MediaType.TEXT_PLAIN);
});
return webClient.post()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.UPLOAD_FILE_URL)
+ .uri(serverIp + BiShengConstant.UPLOAD_FILE_URL)
.contentType(MediaType.MULTIPART_FORM_DATA)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.body(BodyInserters.fromMultipartData(builder.build()))
@@ -113,15 +109,17 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
jsonArray.add(jsonObject);
processParam.put("file_list", jsonArray);
return webClient.post()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.PROCESS_FILE_URL)
+ .uri(serverIp + BiShengConstant.PROCESS_FILE_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.bodyValue(processParam)
.retrieve()
.bodyToMono(ProcessFileResponse.class).flatMap(lastResponse -> {
if (lastResponse.getStatus_code() == 200) {
- String fileId = UUID.randomUUID().toString();
- datasetMapper.insertFileName(fileId, filename, String.valueOf(knowledgeBaseId));
+ JSONObject data = lastResponse.getData().get(0);
+ int fileId = data.getIntValue("id");
+ File file = new File(String.valueOf(fileId), filename);
+ datasetMapper.insertFileName(List.of(file), String.valueOf(knowledgeBaseId));
}
return Mono.empty();
});
@@ -129,9 +127,9 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
}
@Override
- public Mono<ServiceResult> removeDataset(String knowledgeBaseId) {
+ public Mono<ServiceResult> removeDataset(String knowledgeBaseId, String serverIp) {
return webClient.delete()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.DATASET_V2_URL + knowledgeBaseId)
+ .uri(serverIp + BiShengConstant.DATASET_V2_URL + knowledgeBaseId)
.header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
.retrieve()
.bodyToMono(BiShengCreateDatasetResponse.class)
@@ -156,7 +154,7 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
}
@Override
- public Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase) {
+ public Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase, MaaSPlatform maaSPlatform) {
KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(knowledgeBase.getKnowledgeBaseId());
if (knowledgeBaseRecordById == null) {
return Mono.just(new ServiceResult(new ResultHeader(500, "dataset is not exist")));
@@ -165,10 +163,10 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
updateParam.put("knowledge_id", knowledgeBase.getKnowledgeBaseId());
updateParam.put("name", knowledgeBase.getKnowledgeBaseName());
updateParam.put("description", knowledgeBase.getKnowledgeBaseDescription());
- updateParam.put("model", serverConstant.getBiShengModel());
+ updateParam.put("model", maaSPlatform.getVectorModel());
return webClient.put()
- .uri(serverConstant.getBiShengServer() + BiShengConstant.DATASET_V2_URL)
+ .uri(maaSPlatform.getServerIp() + BiShengConstant.DATASET_V2_URL)
.contentType(APPLICATION_JSON)
.bodyValue(updateParam)
.retrieve()
@@ -188,4 +186,34 @@ public class BiShengDatasetServiceImpl implements BiShengDatasetService {
return Mono.just(new ServiceResult(new ResultHeader(500, "update failed")));
});
}
+
+ @Override
+ public Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts, String knowledgeBaseId, String serverIp) {
+ return fileParts.flatMap(filePart -> processFile(filePart, Integer.parseInt(knowledgeBaseId), serverIp))
+ .then(Mono.just(new ServiceResult(new ResultHeader(200, "upload success"))))
+ .onErrorResume(e -> {
+ log.error("Error occurred during file upload: {}", e.getMessage());
+ return Mono.just(new ServiceResult(new ResultHeader(500, "file upload failed")));
+ });
+ }
+
+ @Override
+ public Mono<ServiceResult> deleteFile(String fileId, String serverIp) {
+ return webClient.delete()
+ .uri(serverIp + BiShengConstant.DELETE_FILE_URL + fileId)
+ .header(CommonConstant.COOKIE, BiShengConstant.COOKIE_VALUE)
+ .retrieve()
+ .bodyToMono(BiShengCreateDatasetResponse.class)
+ .flatMap(response -> {
+ if (response.getStatus_code() == 200) {
+ return Mono.fromRunnable(() -> datasetMapper.deleteFileByFileId(fileId)).then(Mono.just(new ServiceResult(new ResultHeader(200, "delete file success"))));
+ } else {
+ return Mono.just(new ServiceResult(new ResultHeader(response.getStatus_code(), response.getStatus_message())));
+ }
+ })
+ .onErrorResume(e -> {
+ log.error("Error occurred while delete dataset: {}", e.getMessage());
+ return Mono.just(new ServiceResult(new ResultHeader(500, "delete file failed")));
+ });
+ }
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/DatasetServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/DatasetServiceImpl.java
index 0a6feb5..27967a9 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/DatasetServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/DatasetServiceImpl.java
@@ -2,11 +2,9 @@ package org.onap.usecaseui.llmadaptation.service.impl;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
-import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
-import org.onap.usecaseui.llmadaptation.bean.MaaSPlatform;
-import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
-import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
+import org.onap.usecaseui.llmadaptation.bean.*;
+import org.onap.usecaseui.llmadaptation.constant.FastGptConstant;
+import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.mapper.DatasetMapper;
import org.onap.usecaseui.llmadaptation.mapper.MaaSPlatformMapper;
import org.onap.usecaseui.llmadaptation.service.BiShengDatasetService;
@@ -38,7 +36,7 @@ public class DatasetServiceImpl implements DatasetService {
private MaaSPlatformMapper maaSPlatformMapper;
@Autowired
- private ServerConstant serverConstant;
+ private ApplicationMapper applicationMapper;
@Override
public Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData) {
@@ -52,23 +50,24 @@ public class DatasetServiceImpl implements DatasetService {
}
MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(knowledgeBase.getMaaSPlatformId());
String maaSType = maaSPlatformById.getMaaSType();
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptDatasetService.createDataset(fileParts, metaData);
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptDatasetService.createDataset(fileParts, metaData, maaSPlatformById);
}
- return biShengDatasetService.createDataset(fileParts, metaData);
+ return biShengDatasetService.createDataset(fileParts, metaData, maaSPlatformById);
}
@Override
public Mono<ServiceResult> removeDataset(String knowledgeBaseId) {
- KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(knowledgeBaseId);
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(knowledgeBaseRecordById.getMaaSPlatformId());
+ List<Application> applicationByDatasetId = applicationMapper.getApplicationByDatasetId(knowledgeBaseId);
+ if (!CollectionUtils.isEmpty(applicationByDatasetId)) {
+ return Mono.just(new ServiceResult(new ResultHeader(500, "This database is currently in use")));
+ }
+ MaaSPlatform maaSPlatformById = getMaaSPlatform(knowledgeBaseId);
String maaSType = maaSPlatformById.getMaaSType();
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptDatasetService.removeDataset(knowledgeBaseId);
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptDatasetService.removeDataset(knowledgeBaseId, maaSPlatformById.getServerIp());
}
- return biShengDatasetService.removeDataset(knowledgeBaseId);
+ return biShengDatasetService.removeDataset(knowledgeBaseId, maaSPlatformById.getServerIp());
}
@Override
@@ -79,8 +78,8 @@ public class DatasetServiceImpl implements DatasetService {
}
knowledgeBaseRecords.forEach(knowledgeBase -> {
- List<String> fileNamesByKnowledgeBaseId = datasetMapper.getFileNamesByKnowledgeBaseId(knowledgeBase.getKnowledgeBaseId());
- knowledgeBase.setFilesName(fileNamesByKnowledgeBaseId);
+ List<File> fileNamesByKnowledgeBaseId = datasetMapper.getFileNamesByKnowledgeBaseId(knowledgeBase.getKnowledgeBaseId());
+ knowledgeBase.setFileList(fileNamesByKnowledgeBaseId);
});
return new ServiceResult(new ResultHeader(200, "success"), knowledgeBaseRecords);
}
@@ -91,21 +90,47 @@ public class DatasetServiceImpl implements DatasetService {
if (knowledgeBase == null) {
return new ServiceResult(new ResultHeader(500, "get dataset failed"));
}
- List<String> fileNamesByKnowledgeBaseId = datasetMapper.getFileNamesByKnowledgeBaseId(knowledgeBase.getKnowledgeBaseId());
- knowledgeBase.setFilesName(fileNamesByKnowledgeBaseId);
-
+ List<File> fileNamesByKnowledgeBaseId = datasetMapper.getFileNamesByKnowledgeBaseId(knowledgeBase.getKnowledgeBaseId());
+ knowledgeBase.setFileList(fileNamesByKnowledgeBaseId);
return new ServiceResult(new ResultHeader(200, "success"), knowledgeBase);
}
@Override
public Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase) {
- KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(knowledgeBase.getKnowledgeBaseId());
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(knowledgeBaseRecordById.getMaaSPlatformId());
+ MaaSPlatform maaSPlatformById = getMaaSPlatform(knowledgeBase.getKnowledgeBaseId());
String maaSType = maaSPlatformById.getMaaSType();
- String fastGptType = serverConstant.getFastGptType();
- if (fastGptType.equals(maaSType)) {
- return fastGptDatasetService.editDataset(knowledgeBase);
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptDatasetService.editDataset(knowledgeBase, maaSPlatformById);
+ }
+ return biShengDatasetService.editDataset(knowledgeBase, maaSPlatformById);
+ }
+
+ @Override
+ public Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts, String metaData) {
+ KnowledgeBase knowledgeBase = JSONObject.parseObject(metaData, KnowledgeBase.class);
+ MaaSPlatform maaSPlatform = getMaaSPlatform(knowledgeBase.getKnowledgeBaseId());
+ String maaSType = maaSPlatform.getMaaSType();
+ String knowledgeBaseId = knowledgeBase.getKnowledgeBaseId();
+ String serverIp = maaSPlatform.getServerIp();
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptDatasetService.uploadFiles(fileParts,knowledgeBaseId, serverIp);
}
- return biShengDatasetService.editDataset(knowledgeBase);
+ return biShengDatasetService.uploadFiles(fileParts, knowledgeBaseId, serverIp);
+ }
+
+ @Override
+ public Mono<ServiceResult> deleteFile(String fileId) {
+ String knowledgeId = datasetMapper.getKnowledgeIdByFileId(fileId);
+ MaaSPlatform maaSPlatform = getMaaSPlatform(knowledgeId);
+ String maaSType = maaSPlatform.getMaaSType();
+ if (FastGptConstant.FAST_GPT.equals(maaSType)) {
+ return fastGptDatasetService.deleteFile(fileId, maaSPlatform.getServerIp());
+ }
+ return biShengDatasetService.deleteFile(fileId, maaSPlatform.getServerIp());
+ }
+
+ private MaaSPlatform getMaaSPlatform(String knowledgeBaseId) {
+ KnowledgeBase knowledgeBase = datasetMapper.getKnowledgeBaseRecordById(knowledgeBaseId);
+ return maaSPlatformMapper.getMaaSPlatformById(knowledgeBase.getMaaSPlatformId());
}
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java
index 14f30ad..5a3ab79 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java
@@ -11,7 +11,6 @@ import org.onap.usecaseui.llmadaptation.bean.fastgpt.dataset.CreateDataSetRespon
import org.onap.usecaseui.llmadaptation.bean.fastgpt.application.*;
import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
import org.onap.usecaseui.llmadaptation.constant.FastGptConstant;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.service.FastGptApplicationService;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
@@ -43,18 +42,15 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
@Autowired
private WebClient webClient;
- @Autowired
- private ServerConstant serverConstant;
-
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
- public Mono<ServiceResult> createApplication(Application application) {
+ public Mono<ServiceResult> createApplication(Application application, String serverIp) {
try (InputStream inputStream = resourceLoader.getResource(FastGptConstant.CREATE_APP_PARAM_FILE_URL).getInputStream()) {
CreateApplicationParam createApplicationParam = objectMapper.readValue(inputStream, CreateApplicationParam.class);
createApplicationParam.setName(application.getApplicationName());
- return createApplication(createApplicationParam, application)
+ return createApplication(createApplicationParam, application, serverIp)
.onErrorResume(e -> {
log.error("Error occurred while creating application: {}", e.getMessage());
return Mono.just(new ServiceResult(new ResultHeader(500, "Application creation failed")));
@@ -66,9 +62,9 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
}
}
- private Mono<ServiceResult> createApplication(CreateApplicationParam createApplicationParam, Application application) {
+ private Mono<ServiceResult> createApplication(CreateApplicationParam createApplicationParam, Application application, String serverIp) {
return webClient.post()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.CREATE_APPLICATION)
+ .uri(serverIp + FastGptConstant.CREATE_APPLICATION)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.bodyValue(createApplicationParam)
@@ -76,16 +72,15 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
.bodyToMono(CreateDataSetResponse.class)
.flatMap(response -> {
if (response.getCode() == 200) {
- return handleApplicationResponse(response, application);
+ return handleApplicationResponse(String.valueOf(response.getData()), application, serverIp);
}
return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
});
}
- private Mono<ServiceResult> handleApplicationResponse(CreateDataSetResponse createDataSetResponse, Application application) {
- String data = String.valueOf(createDataSetResponse.getData());
- application.setApplicationId(data);
- String url = serverConstant.getFastGptServer() + FastGptConstant.UPDATE_APPLICATION + data;
+ private Mono<ServiceResult> handleApplicationResponse(String dataId, Application application, String serverIp) {
+ application.setApplicationId(dataId);
+ String url = serverIp + FastGptConstant.UPDATE_APPLICATION + dataId;
UpdateApplicationParam updateApplicationParam = new UpdateApplicationParam();
updateApplicationParam.setAvatar("/imgs/app/avatar/simple.svg");
updateApplicationParam.setDefaultPermission(0);
@@ -101,19 +96,19 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
.bodyToMono(CreateDataSetResponse.class)
.flatMap(response -> {
if (response.getCode() == 200) {
- return publishApplication(application, data);
+ return publishApplication(application, dataId, serverIp);
}
return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
});
}
- private Mono<ServiceResult> publishApplication(Application application, String data) {
+ private Mono<ServiceResult> publishApplication(Application application, String data, String serverIp) {
try (InputStream inputStream = resourceLoader.getResource(FastGptConstant.PUBLISH_APP_PARAM_FILE_URL).getInputStream()) {
PublishApplicationParam publishApplicationParam = objectMapper.readValue(inputStream, PublishApplicationParam.class);
publishApplicationParam.setVersionName(TimeUtil.getNowTime());
publishApplicationParam.getChatConfig().setWelcomeText(application.getOpeningRemarks());
setApplicationParameters(application, publishApplicationParam);
- String publishUrl = serverConstant.getFastGptServer() + FastGptConstant.PUBLISH_APPLICATION + data;
+ String publishUrl = serverIp + FastGptConstant.PUBLISH_APPLICATION + data;
return webClient.post()
.uri(publishUrl)
@@ -167,7 +162,7 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
}
@Override
- public Flux<String> chat(JSONObject question) {
+ public Flux<String> chat(JSONObject question, String serverIp) {
ChatParam chatParam = new ChatParam();
chatParam.setAppId(question.getString("applicationId"));
chatParam.setStream(true);
@@ -186,7 +181,7 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
chatParam.setMessages(messages);
AtomicBoolean isDone = new AtomicBoolean(false);
return webClient.post()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.APPLICATION_CHAT_URL)
+ .uri(serverIp + FastGptConstant.APPLICATION_CHAT_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.bodyValue(chatParam)
@@ -219,8 +214,8 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
}
@Override
- public Mono<ServiceResult> removeApplication(String applicationId) {
- String url = serverConstant.getFastGptServer() + FastGptConstant.DELETE_APPLICATION + applicationId;
+ public Mono<ServiceResult> removeApplication(String applicationId, String serverIp) {
+ String url = serverIp + FastGptConstant.DELETE_APPLICATION + applicationId;
return webClient.delete()
.uri(url)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
@@ -246,33 +241,8 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
}
@Override
- public Mono<ServiceResult> editApplication(Application application) {
- String url = serverConstant.getFastGptServer() + FastGptConstant.UPDATE_APPLICATION + application.getApplicationId();
- UpdateApplicationParam updateApplicationParam = new UpdateApplicationParam();
- updateApplicationParam.setAvatar("/imgs/app/avatar/simple.svg");
- updateApplicationParam.setName(application.getApplicationName());
- updateApplicationParam.setIntro(application.getApplicationDescription());
-
- return webClient.put()
- .uri(url)
- .contentType(APPLICATION_JSON)
- .header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
- .bodyValue(updateApplicationParam)
- .retrieve()
- .bodyToMono(CreateDataSetResponse.class)
- .flatMap(response -> {
- if (response.getCode() == 200) {
- return Mono.fromRunnable(() -> {
- applicationMapper.updateApplication(application);
- }).then(Mono.just(new ServiceResult(new ResultHeader(200, "edit success"))));
- } else {
- return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
- }
- })
- .onErrorResume(e -> {
- log.error("Error occurred while delete dataset: {}", e.getMessage());
- return Mono.just(new ServiceResult(new ResultHeader(500, "edit failed")));
- });
+ public Mono<ServiceResult> editApplication(Application application, String serverIp) {
+ return handleApplicationResponse(application.getApplicationId(), application, serverIp);
}
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptDatasetServiceImpl.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptDatasetServiceImpl.java
index df8787d..8c81a7a 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptDatasetServiceImpl.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptDatasetServiceImpl.java
@@ -1,18 +1,16 @@
package org.onap.usecaseui.llmadaptation.service.impl;
import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
-import org.onap.usecaseui.llmadaptation.bean.KnowledgeBase;
-import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
-import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
+import org.onap.usecaseui.llmadaptation.bean.*;
import org.onap.usecaseui.llmadaptation.bean.fastgpt.dataset.CreateCollectionParam;
import org.onap.usecaseui.llmadaptation.bean.fastgpt.dataset.CreateDataSetParam;
import org.onap.usecaseui.llmadaptation.bean.fastgpt.dataset.CreateDataSetResponse;
import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
import org.onap.usecaseui.llmadaptation.constant.FastGptConstant;
-import org.onap.usecaseui.llmadaptation.constant.ServerConstant;
import org.onap.usecaseui.llmadaptation.mapper.DatasetMapper;
import org.onap.usecaseui.llmadaptation.service.FastGptDatasetService;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
@@ -29,6 +27,11 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
import static org.springframework.http.MediaType.APPLICATION_JSON;
@Slf4j
@@ -40,22 +43,17 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
@Autowired
private WebClient webClient;
- @Autowired
- private ServerConstant serverConstant;
-
@Override
- public Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData) {
+ public Mono<ServiceResult> createDataset(Flux<FilePart> fileParts, String metaData, MaaSPlatform maaSPlatform) {
KnowledgeBase knowledgeBase = JSONObject.parseObject(metaData, KnowledgeBase.class);
knowledgeBase.setUpdateTime(TimeUtil.getNowTime());
CreateDataSetParam dataSetParam = new CreateDataSetParam();
- dataSetParam.setAgentModel(serverConstant.getFastGptModel());
+ dataSetParam.setAgentModel(maaSPlatform.getVectorModel());
dataSetParam.setType("dataset");
- dataSetParam.setAvatar("core/dataset/commonDatasetColor");
- dataSetParam.setVectorModel("m3e");
dataSetParam.setIntro(knowledgeBase.getKnowledgeBaseDescription());
dataSetParam.setName(knowledgeBase.getKnowledgeBaseName());
return webClient.post()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.CREATE_DATASET_URL)
+ .uri(maaSPlatform.getServerIp() + FastGptConstant.CREATE_DATASET_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.bodyValue(dataSetParam)
@@ -64,11 +62,12 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
.flatMap(response -> {
if (response.getCode() == 200) {
String knowledgeBaseId = String.valueOf(response.getData());
- return fileParts.flatMap(filePart -> uploadFile(filePart, knowledgeBaseId))
+ return fileParts
+ .flatMap(filePart -> uploadFile(filePart, knowledgeBaseId, maaSPlatform.getServerIp()))
.then(Mono.defer(() -> {
knowledgeBase.setKnowledgeBaseId(knowledgeBaseId);
datasetMapper.insertKnowledgeBaseRecord(knowledgeBase);
- return Mono.just(new ServiceResult(new ResultHeader(200, "create success")));
+ return handleFileId(knowledgeBaseId, maaSPlatform.getServerIp());
}))
.onErrorResume(e -> {
log.error("Error occurred during file upload: {}", e.getMessage());
@@ -84,7 +83,37 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
});
}
- private Mono<Void> uploadFile(FilePart filePart, String knowledgeBaseId) {
+ private Mono<ServiceResult> handleFileId(String knowledgeBaseId, String serverIp) {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("datasetId", knowledgeBaseId);
+ return webClient.post()
+ .uri(serverIp + FastGptConstant.GET_COLLECTION_LIST_URL)
+ .header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
+ .bodyValue(jsonObject)
+ .retrieve()
+ .bodyToMono(CreateDataSetResponse.class)
+ .flatMap(response -> {
+ Object data = response.getData();
+ JSONArray jsonArray = JSONObject.parseObject(JSONObject.toJSONString(data)).getJSONArray("data");
+ Map<String, String> resultMap = IntStream.range(0, jsonArray.size())
+ .mapToObj(jsonArray::getJSONObject)
+ .collect(Collectors.toMap(
+ obj -> obj.getString("fileId"),
+ obj -> obj.getString("_id")
+ ));
+ List<File> fileList = datasetMapper.getFileNamesByKnowledgeBaseId(knowledgeBaseId);
+ List<File> updatedFileList = fileList.stream()
+ .map(file -> new File(
+ resultMap.getOrDefault(file.getFileId(), file.getFileId()),
+ file.getFileName()))
+ .toList();
+ datasetMapper.deleteFileById(knowledgeBaseId);
+ datasetMapper.insertFileName(updatedFileList, knowledgeBaseId);
+ return Mono.just(new ServiceResult(new ResultHeader(200, "create success")));
+ });
+ }
+
+ private Mono<Void> uploadFile(FilePart filePart, String knowledgeBaseId, String serverIp) {
String filename = filePart.filename();
Flux<DataBuffer> content = filePart.content();
@@ -103,7 +132,7 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
});
return webClient.post()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.UPLOAD_FILE_URL)
+ .uri(serverIp + FastGptConstant.UPLOAD_FILE_URL)
.contentType(MediaType.MULTIPART_FORM_DATA)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.body(BodyInserters.fromMultipartData(builder.build()))
@@ -117,10 +146,10 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
Object data = response.getData();
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(data));
String fileId = jsonObject.getString("fileId");
- CreateCollectionParam createCollectionParam = getCreateCollectionParam(knowledgeBaseId, fileId);
+ CreateCollectionParam createCollectionParam = getCreateCollectionParam(knowledgeBaseId, fileId, filename);
return webClient.post()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.CRATE_COLLECTION_URL)
+ .uri(serverIp + FastGptConstant.CRATE_COLLECTION_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.bodyValue(createCollectionParam)
@@ -128,7 +157,8 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
.bodyToMono(CreateDataSetResponse.class)
.flatMap(responseData -> {
if (responseData.getCode() == 200) {
- datasetMapper.insertFileName(fileId, filename, knowledgeBaseId);
+ File file = new File(String.valueOf(fileId), filename);
+ datasetMapper.insertFileName(List.of(file), String.valueOf(knowledgeBaseId));
}
return Mono.empty();
});
@@ -136,21 +166,21 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
}
@NotNull
- private static CreateCollectionParam getCreateCollectionParam(String knowledgeBaseId, String fileId) {
+ private static CreateCollectionParam getCreateCollectionParam(String knowledgeBaseId, String fileId, String fileName) {
CreateCollectionParam createCollectionParam = new CreateCollectionParam();
createCollectionParam.setTrainingType("chunk");
createCollectionParam.setDatasetId(knowledgeBaseId);
createCollectionParam.setChunkSize(700);
createCollectionParam.setChunkSplitter("");
createCollectionParam.setFileId(fileId);
- createCollectionParam.setName("");
+ createCollectionParam.setName(fileName);
createCollectionParam.setQaPrompt("");
return createCollectionParam;
}
@Override
- public Mono<ServiceResult> removeDataset(String knowledgeBaseId) {
- String url = serverConstant.getFastGptServer() + FastGptConstant.DELETE_DATASET_URL + knowledgeBaseId;
+ public Mono<ServiceResult> removeDataset(String knowledgeBaseId, String serverIp) {
+ String url = serverIp + FastGptConstant.DELETE_DATASET_URL + knowledgeBaseId;
return webClient.delete()
.uri(url)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
@@ -177,7 +207,7 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
}
@Override
- public Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase) {
+ public Mono<ServiceResult> editDataset(KnowledgeBase knowledgeBase, MaaSPlatform maaSPlatform) {
KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(knowledgeBase.getKnowledgeBaseId());
if (knowledgeBaseRecordById == null) {
return Mono.just(new ServiceResult(new ResultHeader(500, "dataset is not exist")));
@@ -189,7 +219,7 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
updateParam.put("avatar", "core/dataset/commonDatasetColor");
return webClient.put()
- .uri(serverConstant.getFastGptServer() + FastGptConstant.UPDATE_DATASET_URL)
+ .uri(maaSPlatform.getServerIp() + FastGptConstant.UPDATE_DATASET_URL)
.contentType(APPLICATION_JSON)
.header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
.bodyValue(updateParam)
@@ -210,4 +240,33 @@ public class FastGptDatasetServiceImpl implements FastGptDatasetService {
return Mono.just(new ServiceResult(new ResultHeader(500, "update failed")));
});
}
+
+ @Override
+ public Mono<ServiceResult> uploadFiles(Flux<FilePart> fileParts, String knowledgeBaseId, String serverIp) {
+ return fileParts.flatMap(filePart -> uploadFile(filePart, knowledgeBaseId, serverIp))
+ .then(Mono.defer(() -> handleFileId(knowledgeBaseId, serverIp)))
+ .onErrorResume(e -> {
+ log.error("Error occurred during file upload: {}", e.getMessage());
+ return Mono.just(new ServiceResult(new ResultHeader(500, "file upload failed")));
+ });
+ }
+
+ @Override
+ public Mono<ServiceResult> deleteFile(String fileId, String serverIp) {
+ return webClient.delete().uri(serverIp + FastGptConstant.DELETE_FILE_URL + fileId)
+ .header(CommonConstant.COOKIE, FastGptConstant.COOKIE_VALUE)
+ .retrieve()
+ .bodyToMono(CreateDataSetResponse.class)
+ .flatMap(response -> {
+ if (response.getCode() == 200) {
+ return Mono.fromRunnable(() -> datasetMapper.deleteFileByFileId(fileId)).then(Mono.just(new ServiceResult(new ResultHeader(200, "delete file success"))));
+ } else {
+ return Mono.just(new ServiceResult(new ResultHeader(response.getCode(), response.getStatusText())));
+ }
+ })
+ .onErrorResume(e -> {
+ log.error("Error occurred while delete dataset: {}", e.getMessage());
+ return Mono.just(new ServiceResult(new ResultHeader(500, "delete file failed")));
+ });
+ }
}
diff --git a/llm-adaptation/src/main/resources/application.yaml b/llm-adaptation/src/main/resources/application.yaml
index ec234d9..656f774 100644
--- a/llm-adaptation/src/main/resources/application.yaml
+++ b/llm-adaptation/src/main/resources/application.yaml
@@ -1,13 +1,5 @@
server:
port: 8084
-fastGpt:
- server: http://172.22.16.126:3000
- model: qwen2:7b
- maaSType: fastGpt
-biSheng:
- server: http://172.22.16.127:3001
- model: 3
- maaSType: biSheng
spring:
main:
allow-circular-references: true
diff --git a/llm-adaptation/src/main/resources/llm-adaptation-init.sql b/llm-adaptation/src/main/resources/llm-adaptation-init.sql
index f46a9eb..2ce4511 100644
--- a/llm-adaptation/src/main/resources/llm-adaptation-init.sql
+++ b/llm-adaptation/src/main/resources/llm-adaptation-init.sql
@@ -5,7 +5,9 @@ create table if not exists maas_platform(
maas_platform_name varchar(255),
operator_id varchar(255),
operator_name varchar(255),
- maas_type varchar(255)
+ maas_type varchar(255),
+ server_ip varchar(255),
+ vector_model varchar(255)
);
create table if not exists model_information(
diff --git a/llm-adaptation/src/main/resources/mapper/ApplicationMapper.xml b/llm-adaptation/src/main/resources/mapper/ApplicationMapper.xml
index ce0fcc4..08a4644 100644
--- a/llm-adaptation/src/main/resources/mapper/ApplicationMapper.xml
+++ b/llm-adaptation/src/main/resources/mapper/ApplicationMapper.xml
@@ -4,19 +4,18 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper">
<insert id="insertApplication">
- insert into application(application_id,
- application_name,
- application_description,
- application_type,
- knowledge_base_id,
- model_id,
- model_name,
- prompt,
- temperature,
- top_p,
- opening_remarks
- )
- values (#{application.applicationId},
+ INSERT INTO application (application_id,
+ application_name,
+ application_description,
+ application_type,
+ knowledge_base_id,
+ model_id,
+ model_name,
+ prompt,
+ temperature,
+ top_p,
+ opening_remarks)
+ VALUES (#{application.applicationId},
#{application.applicationName},
#{application.applicationDescription},
#{application.applicationType},
@@ -27,6 +26,17 @@
#{application.temperature},
#{application.top_p},
#{application.openingRemarks})
+ ON CONFLICT (application_id) DO UPDATE SET
+ application_name = EXCLUDED.application_name,
+ application_description = EXCLUDED.application_description,
+ application_type = EXCLUDED.application_type,
+ knowledge_base_id = EXCLUDED.knowledge_base_id,
+ model_id = EXCLUDED.model_id,
+ model_name = EXCLUDED.model_name,
+ prompt = EXCLUDED.prompt,
+ temperature = EXCLUDED.temperature,
+ top_p = EXCLUDED.top_p,
+ opening_remarks = EXCLUDED.opening_remarks
</insert>
<delete id="deleteApplicationById">
delete from application where application_id = #{applicationId}
@@ -72,4 +82,20 @@
</trim>
where application_id = #{application.applicationId}
</update>
+
+ <select id="getApplicationByDatasetId" resultType="org.onap.usecaseui.llmadaptation.bean.Application">
+ select application_id as applicationId,
+ application_name as applicationName,
+ application_description as applicationDescription,
+ application_type as applicationType,
+ knowledge_base_id as knowledgeBaseId,
+ model_id as largeModelId,
+ model_name as largeModelName,
+ prompt as prompt,
+ temperature as temperature,
+ top_p as top_p,
+ opening_remarks as openingRemarks
+ from application where knowledge_base_id = #{knowledgeBaseId}
+ </select>
+
</mapper> \ No newline at end of file
diff --git a/llm-adaptation/src/main/resources/mapper/DatasetMapper.xml b/llm-adaptation/src/main/resources/mapper/DatasetMapper.xml
index d6a89cd..35b2202 100644
--- a/llm-adaptation/src/main/resources/mapper/DatasetMapper.xml
+++ b/llm-adaptation/src/main/resources/mapper/DatasetMapper.xml
@@ -23,8 +23,12 @@
</insert>
<insert id="insertFileName">
insert into file(file_id,file_name,knowledge_base_id)
- values (#{fileId},#{fileName},#{knowledgeBaseId})
+ values
+ <foreach collection="files" index="index" item="item" separator=",">
+ (#{item.fileId}, #{item.fileName}, #{knowledgeBaseId})
+ </foreach>
</insert>
+
<select id="getKnowledgeBaseRecords" resultType="org.onap.usecaseui.llmadaptation.bean.KnowledgeBase">
select knowledge_base_id as knowledgeBaseId,
knowledge_base_name as knowledgeBaseName,
@@ -36,9 +40,7 @@
to_char(update_time,'yyyy-mm-dd HH24:mi:ss') as updateTime
from knowledge_base
</select>
- <select id="getFileNamesByKnowledgeBaseId" resultType="java.lang.String">
- select file_name from file where knowledge_base_id = #{knowledgeBaseId}
- </select>
+
<select id="getKnowledgeBaseRecordById" resultType="org.onap.usecaseui.llmadaptation.bean.KnowledgeBase">
select knowledge_base_id as knowledgeBaseId,
knowledge_base_name as knowledgeBaseName,
@@ -57,6 +59,9 @@
from knowledge_base
where maas_platform_id = #{maaSPlatformId}
</select>
+ <select id="getFileNamesByKnowledgeBaseId" resultType="org.onap.usecaseui.llmadaptation.bean.File">
+ select file_id as fileId,file_name as fileName from file where knowledge_base_id = #{knowledgeBaseId}
+ </select>
<delete id="deleteKnowledgeBaseByUuid">
delete from knowledge_base where knowledge_base_id = #{knowledgeBaseId}
@@ -74,4 +79,12 @@
</trim>
where knowledge_base_id = #{knowledgeBase.knowledgeBaseId}
</update>
+
+ <delete id="deleteFileByFileId">
+ delete from file where file_id = #{fileId}
+ </delete>
+
+ <select id="getKnowledgeIdByFileId" resultType="java.lang.String">
+ select knowledge_base_id from file where file_id = #{fileId}
+ </select>
</mapper> \ No newline at end of file
diff --git a/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml b/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml
index 69ce9e6..63b9c70 100644
--- a/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml
+++ b/llm-adaptation/src/main/resources/mapper/MaaSPlatformMapper.xml
@@ -4,12 +4,14 @@
"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,maas_type)
+ insert into maas_platform(maas_platform_id,maas_platform_name,operator_id,operator_name,maas_type,server_ip,vector_model)
values (#{maaSPlatform.maaSPlatformId},
#{maaSPlatform.maaSPlatformName},
#{maaSPlatform.operatorId},
#{maaSPlatform.operatorName},
- #{maaSPlatform.maaSType})
+ #{maaSPlatform.maaSType},
+ #{maaSPlatform.serverIp},
+ #{maaSPlatform.vectorModel})
</insert>
<insert id="insertModel">
insert into model_information(model_id,model_name,maas_platform_id)
@@ -25,7 +27,9 @@
maas_platform_name as maaSPlatformName,
operator_id as operatorId,
operator_name as operatorName,
- maas_type as maaSType
+ maas_type as maaSType,
+ server_ip as serverIp,
+ vector_model as vectorModel
from maas_platform
</select>
<select id="getModelList" resultType="org.onap.usecaseui.llmadaptation.bean.ModelInformation">
@@ -38,7 +42,9 @@
maas_platform_name as maaSPlatformName,
operator_id as operatorId,
operator_name as operatorName,
- maas_type as maaSType
+ maas_type as maaSType,
+ server_ip as serverIp,
+ vector_model as vectorModel
from maas_platform
where maas_platform_id = #{maaSPlatformId}
</select>