Commit 18044d65 by zhangxingmin

push

parent 9574bb8d
......@@ -28,12 +28,17 @@ import java.util.Arrays;
@Service
public class ApiAiStreamServiceImpl implements ApiAiStreamService {
public static final String RESET = "\u001B[0m";
public static final String CYAN = "\u001B[36m";
public static final String GREEN = "\u001B[32m";
@Autowired
private ApiSensitiveWordDetailService apiSensitiveWordDetailService;
@Autowired
private ApiNotificationTaskFeignClient apiNotificationTaskFeignClient;
/**
* 流式对话(SSE),保留敏感词检测逻辑
*/
......@@ -98,6 +103,9 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
flowable.subscribe(
result -> {
String delta = result.getOutput().getChoices().get(0).getMessage().getContent();
// 实时着色并打印
printWithStyle(delta);
System.out.flush();
sink.next(delta);
},
error -> {
......@@ -108,4 +116,14 @@ public class ApiAiStreamServiceImpl implements ApiAiStreamService {
);
});
}
private static void printWithStyle(String text) {
for (char ch : text.toCharArray()) {
if (ch == '|' || ch == '-' || ch == '=') {
System.out.print(CYAN + ch + RESET);
} else {
System.out.print(GREEN + ch + RESET);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment