|
@@ -28,6 +28,7 @@ import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -62,9 +63,9 @@ public class AiChatController {
|
|
|
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
@PostMapping(value = "/aliTyqw", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
|
- public ResponseEntity<StreamingResponseBody> send1(@RequestBody JSONObject object )throws NoApiKeyException, InputRequiredException {
|
|
|
+ public ResponseEntity<StreamingResponseBody> send1(@RequestBody JSONObject object) throws NoApiKeyException, InputRequiredException {
|
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
String userName = SecurityUtils.getLoginUser().getSysUser().getNickName();
|
|
@@ -79,8 +80,7 @@ public class AiChatController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- String questionText;
|
|
|
- questionText = content;
|
|
|
+ String questionText = content;
|
|
|
|
|
|
|
|
|
boolean exists = aiSessionMapper.existsBySessionId(sessionId);
|
|
@@ -96,29 +96,15 @@ public class AiChatController {
|
|
|
aiSessionMapper.save(aiSession);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- List<AiQuestion> conversationHistory = aiQuestionMapper.findByUserIdAndSessionId(sessionId, userId);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- List<Message> messages = conversationHistory.stream()
|
|
|
- .map(q -> Message.builder()
|
|
|
- .role(q.getUserId().equals(userId) ? Role.USER.getValue() : Role.ASSISTANT.getValue())
|
|
|
- .content(q.getUserId().equals(userId) ? q.getQuestion() : q.getAnswer())
|
|
|
- .build())
|
|
|
- .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Message> messages = new ArrayList<>();
|
|
|
|
|
|
|
|
|
Message roleDefinition = Message.builder()
|
|
|
.role(Role.SYSTEM.getValue())
|
|
|
.content(aiRole)
|
|
|
.build();
|
|
|
- messages.add(0, roleDefinition);
|
|
|
+ messages.add(roleDefinition);
|
|
|
|
|
|
|
|
|
Message userMessage = Message.builder()
|
|
@@ -135,7 +121,7 @@ public class AiChatController {
|
|
|
.topP(0.8)
|
|
|
.apiKey(apiKey)
|
|
|
.incrementalOutput(true)
|
|
|
- .enableSearch(true)
|
|
|
+ .enableSearch(true)
|
|
|
.build();
|
|
|
|
|
|
String finalSessionId = sessionId;
|
|
@@ -165,7 +151,6 @@ public class AiChatController {
|
|
|
|
|
|
|
|
|
outputStream.write(("data: " + newString + "\n\n").getBytes(StandardCharsets.UTF_8));
|
|
|
-
|
|
|
outputStream.flush();
|
|
|
|
|
|
|