refactor(yudao-module-llm): 优化 ModelService 中的请求处理和响应处理
-移除了 setupRequest 方法中的 throws IOException 声明,因为异常已在方法内部处理 - 在处理响应行数据时,添加了对换行符的替换,避免产生冗余的空行 - 在 catch 块中添加了一个空行,提高代码可读性
This commit is contained in:
parent
af97393316
commit
d3bb3a2388
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user