summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ChatResponse.java14
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/config/WebClientConfig.java4
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/ApplicationController.java2
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/ApplicationService.java3
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/BiShengApplicationService.java3
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/FastGptApplicationService.java3
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/ApplicationServiceImpl.java2
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/BiShengApplicationServiceImpl.java17
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/impl/FastGptApplicationServiceImpl.java20
-rw-r--r--llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/CommonUtil.java18
10 files changed, 69 insertions, 17 deletions
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ChatResponse.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ChatResponse.java
new file mode 100644
index 0000000..c7cdc2e
--- /dev/null
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/bean/ChatResponse.java
@@ -0,0 +1,14 @@
+package org.onap.usecaseui.llmadaptation.bean;
+
+import lombok.Data;
+
+@Data
+public class ChatResponse {
+ private ResultHeader result_header;
+
+ private String finished;
+
+ private String answer;
+
+ private String reference;
+}
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
index 8434b6b..234157f 100644
--- 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
@@ -31,8 +31,8 @@ public class WebClientConfig {
public WebClient getWebClient() {
HttpClient httpClient = HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 50000))
- .responseTimeout(Duration.ofSeconds(50));
+ .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 60000))
+ .responseTimeout(Duration.ofSeconds(60));
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient)).build();
}
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/ApplicationController.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/ApplicationController.java
index a6493de..796e59f 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/ApplicationController.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/controller/ApplicationController.java
@@ -29,7 +29,7 @@ public class ApplicationController {
}
@PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
- public Flux<String> streamData(@RequestBody JSONObject question) {
+ public Flux<ChatResponse> streamData(@RequestBody JSONObject question) {
return applicationService.chat(question);
}
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/ApplicationService.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/ApplicationService.java
index 636832e..bb61e19 100644
--- a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/ApplicationService.java
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/service/ApplicationService.java
@@ -2,6 +2,7 @@ package org.onap.usecaseui.llmadaptation.service;
import com.alibaba.fastjson2.JSONObject;
import org.onap.usecaseui.llmadaptation.bean.Application;
+import org.onap.usecaseui.llmadaptation.bean.ChatResponse;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -9,7 +10,7 @@ import reactor.core.publisher.Mono;
public interface ApplicationService {
Mono<ServiceResult> createApplication(Application application);
- Flux<String> chat(JSONObject question);
+ Flux<ChatResponse> chat(JSONObject question);
Mono<ServiceResult> removeApplication(String applicationId);
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 391a146..fddaf15 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
@@ -2,6 +2,7 @@ package org.onap.usecaseui.llmadaptation.service;
import com.alibaba.fastjson2.JSONObject;
import org.onap.usecaseui.llmadaptation.bean.Application;
+import org.onap.usecaseui.llmadaptation.bean.ChatResponse;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -9,7 +10,7 @@ import reactor.core.publisher.Mono;
public interface BiShengApplicationService {
Mono<ServiceResult> createApplication(Application application, String serverIp);
- Flux<String> chat(JSONObject question, String serverIp);
+ Flux<ChatResponse> chat(JSONObject question, String serverIp);
Mono<ServiceResult> removeApplication(String applicationId, String serverIp);
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 2d02778..89323f6 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
@@ -2,6 +2,7 @@ package org.onap.usecaseui.llmadaptation.service;
import com.alibaba.fastjson2.JSONObject;
import org.onap.usecaseui.llmadaptation.bean.Application;
+import org.onap.usecaseui.llmadaptation.bean.ChatResponse;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -9,7 +10,7 @@ import reactor.core.publisher.Mono;
public interface FastGptApplicationService {
Mono<ServiceResult> createApplication(Application application, String serverIp);
- Flux<String> chat(JSONObject question, String serverIp);
+ Flux<ChatResponse> chat(JSONObject question, String serverIp);
Mono<ServiceResult> removeApplication(String applicationId, 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 90de2c7..071edea 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
@@ -66,7 +66,7 @@ public class ApplicationServiceImpl implements ApplicationService {
}
@Override
- public Flux<String> chat(JSONObject question) {
+ public Flux<ChatResponse> chat(JSONObject question) {
String applicationId = question.getString("applicationId");
MaaSPlatform maaSPlatform = getMaaSPlatFormByAppId(applicationId);
if (FastGptConstant.FAST_GPT.equals(maaSPlatform.getMaaSType())) {
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 1486a99..8a138ba 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
@@ -5,6 +5,7 @@ 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.ChatResponse;
import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import org.onap.usecaseui.llmadaptation.bean.bisheng.BiShengCreateDatasetResponse;
@@ -12,6 +13,7 @@ import org.onap.usecaseui.llmadaptation.constant.BiShengConstant;
import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.service.BiShengApplicationService;
+import org.onap.usecaseui.llmadaptation.util.CommonUtil;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -86,7 +88,7 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
}
@Override
- public Flux<String> chat(JSONObject question, String serverIp) {
+ public Flux<ChatResponse> chat(JSONObject question, String serverIp) {
JSONObject param = new JSONObject();
param.put("model", question.getString("applicationId"));
param.put("temperature", 0);
@@ -103,18 +105,25 @@ public class BiShengApplicationServiceImpl implements BiShengApplicationService
.retrieve()
.bodyToFlux(String.class)
.flatMap(response -> {
+ ChatResponse result = new ChatResponse();
+ result.setReference("");
+ result.setFinished("stop");
+ ResultHeader resultHeader = new ResultHeader(200,"success");
+ result.setResult_header(resultHeader);
if ("[DONE]".equals(response)) {
- return Flux.just(response);
+ result.setAnswer("[DONE]");
+ return Flux.just(result);
}
JSONArray choices = JSONObject.parseObject(response).getJSONArray("choices");
String jsonString = JSONObject.toJSONString(choices.get(0));
JSONObject jsonObject = JSONObject.parseObject(jsonString);
String string = jsonObject.getJSONObject("delta").getString("content");
- return Flux.just(string);
+ result.setAnswer(string);
+ return Flux.just(result);
})
.onErrorResume(e -> {
log.error("An error occurred {}", e.getMessage());
- return Flux.just("Network Error");
+ return CommonUtil.chatFailed();
});
}
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 22a54a6..a488226 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
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.onap.usecaseui.llmadaptation.bean.Application;
+import org.onap.usecaseui.llmadaptation.bean.ChatResponse;
import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
import org.onap.usecaseui.llmadaptation.bean.ServiceResult;
import org.onap.usecaseui.llmadaptation.bean.fastgpt.dataset.CreateDataSetResponse;
@@ -13,6 +14,7 @@ import org.onap.usecaseui.llmadaptation.constant.CommonConstant;
import org.onap.usecaseui.llmadaptation.constant.FastGptConstant;
import org.onap.usecaseui.llmadaptation.mapper.ApplicationMapper;
import org.onap.usecaseui.llmadaptation.service.FastGptApplicationService;
+import org.onap.usecaseui.llmadaptation.util.CommonUtil;
import org.onap.usecaseui.llmadaptation.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
@@ -164,8 +166,7 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
});
}
- @Override
- public Flux<String> chat(JSONObject question, String serverIp) {
+ public Flux<ChatResponse> chat(JSONObject question, String serverIp) {
ChatParam chatParam = new ChatParam();
chatParam.setAppId(question.getString("applicationId"));
chatParam.setStream(true);
@@ -192,11 +193,11 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
.bodyToFlux(String.class).flatMap(response -> parseAndTransform(response, isDone))
.onErrorResume(throwable -> {
log.error("An error occurred {}", throwable.getMessage());
- return Flux.just("Network Error");
+ return CommonUtil.chatFailed();
});
}
- private Flux<String> parseAndTransform(String param, AtomicBoolean isDone) {
+ private Flux<ChatResponse> parseAndTransform(String param, AtomicBoolean isDone) {
if (isDone.get()) {
return Flux.empty();
}
@@ -206,14 +207,21 @@ public class FastGptApplicationServiceImpl implements FastGptApplicationService
}
JSONArray choices = jsonObject.getJSONArray("choices");
JSONObject choice = choices.getJSONObject(0);
+ ChatResponse response = new ChatResponse();
+ response.setReference("");
+ response.setFinished("stop");
+ ResultHeader resultHeader = new ResultHeader(200,"success");
+ response.setResult_header(resultHeader);
if ("stop".equals(choice.getString("finish_reason"))) {
isDone.set(true);
- return Flux.just("[DONE]");
+ response.setAnswer("[DONE]");
+ return Flux.just(response);
}
String string = choice.getJSONObject("delta").getString("content");
isDone.set(false);
string = string.replace(" ", "__SPACE__");
- return Flux.just(string);
+ response.setAnswer(string);
+ return Flux.just(response);
}
@Override
diff --git a/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/CommonUtil.java b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/CommonUtil.java
new file mode 100644
index 0000000..1392ab5
--- /dev/null
+++ b/llm-adaptation/src/main/java/org/onap/usecaseui/llmadaptation/util/CommonUtil.java
@@ -0,0 +1,18 @@
+package org.onap.usecaseui.llmadaptation.util;
+
+import org.onap.usecaseui.llmadaptation.bean.ChatResponse;
+import org.onap.usecaseui.llmadaptation.bean.ResultHeader;
+import reactor.core.publisher.Flux;
+
+public class CommonUtil {
+
+ public static Flux<ChatResponse> chatFailed() {
+ ChatResponse result = new ChatResponse();
+ result.setReference("");
+ result.setFinished("error");
+ ResultHeader resultHeader = new ResultHeader(500, "failure");
+ result.setResult_header(resultHeader);
+ result.setAnswer("Network Error");
+ return Flux.just(result);
+ }
+}