|
@@ -53,6 +53,9 @@ public class AiChatController {
|
|
|
@Value("${ai.historyLimit}")
|
|
|
private int Limit;
|
|
|
|
|
|
+ @Value("${ai.millis}")
|
|
|
+ private int millis;
|
|
|
+
|
|
|
@Resource
|
|
|
private Generation generation;
|
|
|
|
|
@@ -169,7 +172,7 @@ public class AiChatController {
|
|
|
.contentType(MediaType.TEXT_EVENT_STREAM)
|
|
|
.body(outputStream -> {
|
|
|
try {
|
|
|
- // 调用流式接口
|
|
|
+// 调用流式接口
|
|
|
generation.streamCall(param).blockingForEach(chunk -> {
|
|
|
try {
|
|
|
// 获取每次生成的内容
|
|
@@ -195,6 +198,14 @@ public class AiChatController {
|
|
|
// 累加到完整回答内容中
|
|
|
completeAnswer.append(partialAnswer);
|
|
|
|
|
|
+ // 添加延迟
|
|
|
+ try {
|
|
|
+ Thread.sleep(millis); // 延迟*毫秒
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ log.error("Thread interrupted", e);
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("Error processing chunk", e);
|
|
|
outputStream.write(("data: Error processing chunk\n\n").getBytes(StandardCharsets.UTF_8));
|
|
@@ -352,6 +363,14 @@ public class AiChatController {
|
|
|
// 累加到完整回答内容中
|
|
|
completeAnswer.append(partialAnswer);
|
|
|
|
|
|
+ // 添加延迟
|
|
|
+ try {
|
|
|
+ Thread.sleep(millis); // 延迟*毫秒
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ log.error("Thread interrupted", e);
|
|
|
+ }
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("Error processing chunk", e);
|
|
|
outputStream.write(("data: Error processing chunk\n\n").getBytes(StandardCharsets.UTF_8));
|