@Data
public class BiShengCreateDatasetResponse extends ResponseStatus {
private JSONObject data;
+
+ @Override
+ public String toString() {
+ return "BiShengCreateDatasetResponse{" +
+ "data=" + data +
+ "} " + super.toString();
+ }
}
@Data
public class ProcessFileResponse extends ResponseStatus{
private List<JSONObject> data;
+
+ @Override
+ public String toString() {
+ return "ProcessFileResponse{" +
+ "data=" + data +
+ "} " + super.toString();
+ }
}
public ServiceResult registerMaaSPlatform(@RequestBody MaaSPlatform maaSPlatform) {
return maaSService.registerMaaSPlatform(maaSPlatform);
}
+
+ @DeleteMapping(value = "/maas/delete/{maaSPlatformId}", produces = MediaType.APPLICATION_JSON_VALUE)
+ public ServiceResult registerMaaSPlatform(@PathVariable("maaSPlatformId") String maaSPlatformId) {
+ return maaSService.deleteMaaSPlatform(maaSPlatformId);
+ }
}
Application getApplicationById(@Param(value = "applicationId") String applicationId);
- int updateApplication(@Param(value = "application") Application application);
-
List<Application> getApplicationByDatasetId(@Param(value = "knowledgeBaseId") String knowledgeBaseId);
}
int deleteFileByFileId(@Param(value = "fileId") String fileId);
String getKnowledgeIdByFileId(@Param(value = "fileId") String fileId);
+
+ File getFileMessageByName(@Param(value = "fileName") String fileName, @Param(value = "knowledgeBaseId") String knowledgeBaseId);
}
MaaSPlatform getMaaSPlatformById(@Param(value = "maaSPlatformId") String maaSPlatformId);
- ModelInformation getModelById(@Param(value = "modelId") String modelId);
+ ModelInformation getModelById(@Param(value = "modelId") String modelId, @Param(value = "maaSPlatformId") String maaSPlatformId);
+
+ int deleteMaaSPlatformById(@Param(value = "maaSPlatformId") String maaSPlatformId);
+
+ int deleteModelByMaaSPlatformId(@Param(value = "maaSPlatformId") String maaSPlatformId);
}
List<Operator> getAllMaaSPlatform();
ServiceResult registerMaaSPlatform(MaaSPlatform maaSPlatform);
+
+ ServiceResult deleteMaaSPlatform(String maaSPlatformId);
}
public ServiceResult getApplications() {
List<Application> allApplication = applicationMapper.getAllApplication();
if (CollectionUtils.isEmpty(allApplication)) {
- return new ServiceResult(new ResultHeader(500, "no application"), allApplication);
+ return new ServiceResult(new ResultHeader(200, "no application"), allApplication);
}
allApplication.forEach(application -> {
KnowledgeBase knowledgeBaseRecordById = datasetMapper.getKnowledgeBaseRecordById(application.getKnowledgeBaseId());
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
+import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.onap.usecaseui.llmadaptation.bean.Application;
import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
private WebClient webClient;
@Override
- public Mono<ServiceResult> createApplication(Application application, String serverIp) {
+ public Mono<ServiceResult> createApplication(Application application, String serverIp) {
JSONObject createParam = new JSONObject();
createParam.put("logo", "");
createParam.put("name", application.getApplicationName());
return Mono.just(new ServiceResult(new ResultHeader(createResponse.getStatus_code(), createResponse.getStatus_message())));
}
String applicationId = data.getString("id");
- data.put("desc", application.getApplicationDescription());
+ String applicationDescription = application.getApplicationDescription();
+ if (!StringUtil.isNullOrEmpty(applicationDescription)) {
+ data.put("desc", applicationDescription);
+ }
data.put("model_name", application.getLargeModelId());
data.put("temperature", application.getTemperature() / 10);
List<Integer> list = new ArrayList<>();
.retrieve()
.bodyToMono(BiShengCreateDatasetResponse.class)
.flatMap(updateResponse -> {
- application.setApplicationId(applicationId);
- applicationMapper.insertApplication(application);
- return Mono.just(new ServiceResult(new ResultHeader(200, "Application created successfully")));
+ if (updateResponse.getStatus_code() == 200) {
+ application.setApplicationId(applicationId);
+ applicationMapper.insertApplication(application);
+ return Mono.just(new ServiceResult(new ResultHeader(200, "Application created successfully")));
+ }
+ log.error("error is {}",updateResponse.getStatus_message());
+ return Mono.just(new ServiceResult(new ResultHeader(updateResponse.getStatus_code(), "Application created failed")));
});
}).onErrorResume(e -> {
log.error("Error occurred while creating application: {}", e.getMessage());
- return Mono.just(new ServiceResult(new ResultHeader(500, "Application creation failed")));
+ return Mono.just(new ServiceResult(new ResultHeader(500, "Application created failed")));
});
}
.retrieve()
.bodyToFlux(String.class)
.flatMap(response -> {
- if("[DONE]".equals(response)){
+ if ("[DONE]".equals(response)) {
return Flux.just(response);
}
JSONArray choices = JSONObject.parseObject(response).getJSONArray("choices");
.retrieve()
.bodyToMono(BiShengCreateDatasetResponse.class)
.flatMap(response -> {
- if (response.getStatus_code() == 200) {
+ if (response.getStatus_code() == 200 || response.getStatus_code() == 10400) {
return Mono.fromRunnable(() -> {
try {
applicationMapper.deleteApplicationById(applicationId);
data.put("knowledge_list", list);
data.put("model_name", application.getLargeModelId());
data.put("temperature", application.getTemperature() / 10);
- data.put("prompt",application.getPrompt());
+ data.put("prompt", application.getPrompt());
data.put("guide_word", application.getOpeningRemarks());
return webClient.put()
.uri(serverIp + BiShengConstant.APPLICATION_URL)
.retrieve()
.bodyToMono(BiShengCreateDatasetResponse.class)
.flatMap(updateResponse -> {
- applicationMapper.updateApplication(application);
- return Mono.just(new ServiceResult(new ResultHeader(200, "Application update successfully")));
+ if (updateResponse.getStatus_code() == 200) {
+ applicationMapper.insertApplication(application);
+ return Mono.just(new ServiceResult(new ResultHeader(200, "Application update successfully")));
+ }
+ log.error("error is {}", updateResponse.getStatus_message());
+ return Mono.just(new ServiceResult(new ResultHeader(updateResponse.getStatus_code(), "Application update failed")));
});
}).onErrorResume(e -> {
log.error("Error occurred while update application: {}", e.getMessage());
if (lastResponse.getStatus_code() == 200) {
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));
+ File fileMessageByName = datasetMapper.getFileMessageByName(filename, String.valueOf(knowledgeBaseId));
+ if (fileMessageByName == null) {
+ File file = new File(String.valueOf(fileId), filename);
+ datasetMapper.insertFileName(List.of(file), String.valueOf(knowledgeBaseId));
+ }
}
return Mono.empty();
});
.retrieve()
.bodyToMono(BiShengCreateDatasetResponse.class)
.flatMap(response -> {
- if (response.getStatus_code() == 200) {
+ if (response.getStatus_code() == 200 || response.getStatus_code() == 404) {
return Mono.fromRunnable(() -> {
try {
datasetMapper.deleteKnowledgeBaseByUuid(knowledgeBaseId);
knowledgeBase.setUpdateTime(TimeUtil.getNowTime());
datasetMapper.updateKnowledgeBase(knowledgeBase);
}).then(Mono.just(new ServiceResult(new ResultHeader(200, "update success"))));
+ } else if (response.getStatus_code() == 404) {
+ return Mono.just(new ServiceResult(new ResultHeader(404, "The resource does not exist,please delete")));
} else {
return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatus_message())));
}
if (!CollectionUtils.isEmpty(knowledgeBaseRecords)) {
List<KnowledgeBase> collect = knowledgeBaseRecords.stream().filter(base -> base.getKnowledgeBaseName().equals(knowledgeBase.getKnowledgeBaseName())).toList();
if (!collect.isEmpty()) {
- return Mono.just(new ServiceResult(new ResultHeader(200, "name exists"), knowledgeBaseRecords));
+ return Mono.just(new ServiceResult(new ResultHeader(500, "name exists"), knowledgeBaseRecords));
}
}
MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(knowledgeBase.getMaaSPlatformId());
public ServiceResult getDataSetRecord() {
List<KnowledgeBase> knowledgeBaseRecords = datasetMapper.getKnowledgeBaseRecords();
if (CollectionUtils.isEmpty(knowledgeBaseRecords)) {
- return new ServiceResult(new ResultHeader(500, "get datasets failed"), knowledgeBaseRecords);
+ return new ServiceResult(new ResultHeader(200, "no dataset"), knowledgeBaseRecords);
}
knowledgeBaseRecords.forEach(knowledgeBase -> {
.flatMap(response -> {
if (response.getCode() == 200) {
return publishApplication(application, dataId, serverIp);
+ } else if (response.getCode() == 502000) {
+ return Mono.just(new ServiceResult(new ResultHeader(404, "The resource does not exist,please delete")));
+ } else {
+ return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
}
- return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
});
}
.retrieve()
.bodyToMono(CreateDataSetResponse.class)
.flatMap(response -> {
- if (response.getCode() == 200) {
+ if (response.getCode() == 200 || response.getCode() == 502000) {
return Mono.fromRunnable(() -> {
try {
applicationMapper.deleteApplicationById(applicationId);
.bodyToMono(CreateDataSetResponse.class)
.flatMap(responseData -> {
if (responseData.getCode() == 200) {
- File file = new File(String.valueOf(fileId), filename);
- datasetMapper.insertFileName(List.of(file), String.valueOf(knowledgeBaseId));
+ File fileMessageByName = datasetMapper.getFileMessageByName(filename, knowledgeBaseId);
+ if (fileMessageByName == null) {
+ File file = new File(fileId, filename);
+ datasetMapper.insertFileName(List.of(file), knowledgeBaseId);
+ }
}
return Mono.empty();
});
.retrieve()
.bodyToMono(CreateDataSetResponse.class)
.flatMap(response -> {
- if (response.getCode() == 200) {
+ if (response.getCode() == 200 || response.getCode() == 501000) {
return Mono.fromRunnable(() -> {
try {
datasetMapper.deleteKnowledgeBaseByUuid(knowledgeBaseId);
knowledgeBase.setUpdateTime(TimeUtil.getNowTime());
datasetMapper.updateKnowledgeBase(knowledgeBase);
}).then(Mono.just(new ServiceResult(new ResultHeader(200, "update success"))));
+ } else if (response.getCode() == 501000) {
+ return Mono.just(new ServiceResult(new ResultHeader(404, "The resource does not exist,please delete")));
} else {
return Mono.just(new ServiceResult(new ResultHeader(500, response.getStatusText())));
}
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 java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class MaaSServiceImpl implements MaaSService {
- @Autowired
- private WebClient webClient;
@Autowired
private MaaSPlatformMapper maaSPlatformMapper;
@Override
public ServiceResult registerMaaSPlatform(MaaSPlatform maaSPlatform) {
- MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(maaSPlatform.getMaaSPlatformId());
+ String maaSPlatformId = maaSPlatform.getMaaSPlatformId();
+ MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(maaSPlatformId);
if (maaSPlatformById != null) {
return new ServiceResult(new ResultHeader(500, maaSPlatform.getMaaSPlatformName() + "already exists"));
}
List<ModelInformation> modelList = maaSPlatform.getModelList();
for (ModelInformation model : modelList) {
- ModelInformation modelById = maaSPlatformMapper.getModelById(model.getModelId());
+ ModelInformation modelById = maaSPlatformMapper.getModelById(model.getModelId(), maaSPlatformId);
if (modelById != null) {
return new ServiceResult(new ResultHeader(500, model.getModelName() + " already exists"));
}
maaSPlatformMapper.insertModel(maaSPlatform.getMaaSPlatformId(), maaSPlatform.getModelList());
return new ServiceResult(new ResultHeader(200, "register success"));
}
+
+ @Override
+ public ServiceResult deleteMaaSPlatform(String maaSPlatformId) {
+ MaaSPlatform maaSPlatformById = maaSPlatformMapper.getMaaSPlatformById(maaSPlatformId);
+ if (maaSPlatformById == null) {
+ return new ServiceResult(new ResultHeader(500, maaSPlatformId + "does not exist"));
+ }
+ if (maaSPlatformMapper.deleteMaaSPlatformById(maaSPlatformId) < 1) {
+ return new ServiceResult(new ResultHeader(500, " delete failed"));
+ }
+ if (maaSPlatformMapper.deleteModelByMaaSPlatformId(maaSPlatformId) < 1) {
+ return new ServiceResult(new ResultHeader(500, " delete failed"));
+ }
+ return new ServiceResult(new ResultHeader(200, " delete success"));
+ }
}
create table if not exists knowledge_base(
knowledge_base_id varchar(255) primary key,
knowledge_base_name varchar(255),
- knowledge_base_description VARCHAR (225),
+ knowledge_base_description VARCHAR (255),
operator_id varchar(255),
operator_name varchar(255),
maas_platform_id varchar(255),
knowledge_base_id varchar(255),
model_id varchar(255),
model_name varchar(255),
- prompt varchar(255),
+ prompt varchar(1000),
temperature float,
top_p float,
- opening_remarks varchar(255)
+ opening_remarks varchar(500)
)
from application where application_id = #{applicationId}
</select>
- <update id="updateApplication">
- update application
- <trim prefix="set" suffixOverrides=",">
- <if test="application.applicationName != null">application_name = #{application.applicationName},</if>
- <if test="application.applicationDescription != null">application_description = #{application.applicationDescription},</if>
- </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,
<select id="getKnowledgeIdByFileId" resultType="java.lang.String">
select knowledge_base_id from file where file_id = #{fileId}
</select>
+ <select id="getFileMessageByName" resultType="org.onap.usecaseui.llmadaptation.bean.File">
+ select file_id as fileId,file_name as fileName
+ from file where file_name = #{fileName} and knowledge_base_id = #{knowledgeBaseId}
+ </select>
</mapper>
\ No newline at end of file
<select id="getModelById" resultType="org.onap.usecaseui.llmadaptation.bean.ModelInformation">
select model_id as modelId,
model_name as modelName
- from model_information where model_id = #{modelId}
+ from model_information where model_id = #{modelId} and maas_platform_id = #{maaSPlatformId}
</select>
+ <delete id="deleteMaaSPlatformById">
+ delete from maas_platform where maas_platform_id = #{maaSPlatformId}
+ </delete>
+ <delete id="deleteModelByMaaSPlatformId">
+ delete from model_information where maas_platform_id = #{maaSPlatformId}
+ </delete>
</mapper>
\ No newline at end of file