refactor(yudao-module-llm): 优化 ModelService 中的请求处理和响应处理

-移除了 setupRequest 方法中的 throws IOException 声明,因为异常已在方法内部处理
- 在处理响应行数据时,添加了对换行符的替换,避免产生冗余的空行
- 在 catch 块中添加了一个空行,提高代码可读性
This commit is contained in:
Liuyang 2025-03-02 11:29:43 +08:00
parent af97393316
commit d3bb3a2388

View File

@ -156,6 +156,7 @@ public class ModelService {
} catch (Exception e) {
emitter.completeWithError(e);
}
}
/**
@ -187,9 +188,8 @@ public class ModelService {
*
* @param httpPost HttpPost 请求对象
* @param requestBody 请求体内容
* @throws IOException 创建 StringEntity 时可能抛出的 IO 异常
*/
private void setupRequest (HttpPost httpPost, String requestBody) throws IOException {
private void setupRequest (HttpPost httpPost, String requestBody) {
// 创建 StringEntity 对象用于封装请求体
StringEntity entity = new StringEntity(
requestBody,
@ -223,7 +223,9 @@ public class ModelService {
if (StringUtils.isBlank(line)) {
continue;
}
line = line.replaceAll("\n", " ");
log.info("接收到的响应行数据: {}", line);
line = line.replaceAll("\n", " ");
String content = parseStreamLine(line);
if (content != null) {
emitter.send(SseEmitter.event()