BUGFIX:对话 控制台输出改为日志输出
This commit is contained in:
@@ -28,6 +28,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.text.StringEscapeUtils;
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
import org.checkerframework.checker.units.qual.C;
|
import org.checkerframework.checker.units.qual.C;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -49,6 +50,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class LLMServiceImpl implements LLMService {
|
public class LLMServiceImpl implements LLMService {
|
||||||
|
|
||||||
@@ -128,7 +130,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
chatMessageMapper.insert(userMessage);
|
chatMessageMapper.insert(userMessage);
|
||||||
|
|
||||||
try (OutputStream os = conn.getOutputStream()) {
|
try (OutputStream os = conn.getOutputStream()) {
|
||||||
System.out.println(jsonBodyObject.toJSONString());
|
log.info(jsonBodyObject.toJSONString());
|
||||||
byte[] input = jsonBodyObject.toJSONString().getBytes(StandardCharsets.UTF_8);
|
byte[] input = jsonBodyObject.toJSONString().getBytes(StandardCharsets.UTF_8);
|
||||||
os.write(input, 0, input.length);
|
os.write(input, 0, input.length);
|
||||||
}
|
}
|
||||||
@@ -150,7 +152,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (!line.isEmpty() && line.startsWith("data: ")) {
|
if (!line.isEmpty() && line.startsWith("data: ")) {
|
||||||
String jsonStr = line.substring(6);
|
String jsonStr = line.substring(6);
|
||||||
System.out.println(jsonStr);
|
log.info(jsonStr);
|
||||||
JSONObject json = JSON.parseObject(jsonStr);
|
JSONObject json = JSON.parseObject(jsonStr);
|
||||||
String status = json.getString("status");
|
String status = json.getString("status");
|
||||||
if (!StringUtils.isEmpty(status)) {
|
if (!StringUtils.isEmpty(status)) {
|
||||||
@@ -219,7 +221,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
|
|
||||||
emitter.complete();
|
emitter.complete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("走进异常");
|
log.info("走进异常");
|
||||||
emitter.completeWithError(e);
|
emitter.completeWithError(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -278,7 +280,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
chatMessageMapper.insert(userMessage);
|
chatMessageMapper.insert(userMessage);
|
||||||
|
|
||||||
try (OutputStream os = conn.getOutputStream()) {
|
try (OutputStream os = conn.getOutputStream()) {
|
||||||
System.out.println(jsonBodyObject.toJSONString());
|
log.info(jsonBodyObject.toJSONString());
|
||||||
byte[] input = jsonBodyObject.toJSONString().getBytes(StandardCharsets.UTF_8);
|
byte[] input = jsonBodyObject.toJSONString().getBytes(StandardCharsets.UTF_8);
|
||||||
os.write(input, 0, input.length);
|
os.write(input, 0, input.length);
|
||||||
}
|
}
|
||||||
@@ -298,7 +300,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (!line.isEmpty() && line.startsWith("data: ")) {
|
if (!line.isEmpty() && line.startsWith("data: ")) {
|
||||||
String jsonStr = line.substring(12);
|
String jsonStr = line.substring(12);
|
||||||
System.out.println(jsonStr);
|
log.info(jsonStr);
|
||||||
JSONObject json = JSON.parseObject(jsonStr);
|
JSONObject json = JSON.parseObject(jsonStr);
|
||||||
String type = json.getString("type");
|
String type = json.getString("type");
|
||||||
if (!StringUtils.isEmpty(type)) {
|
if (!StringUtils.isEmpty(type)) {
|
||||||
@@ -387,7 +389,7 @@ public class LLMServiceImpl implements LLMService {
|
|||||||
}
|
}
|
||||||
emitter.complete();
|
emitter.complete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("走进异常: " + e.getMessage());
|
log.info("走进异常: {}", e.getMessage());
|
||||||
e.printStackTrace(); // 详细栈信息
|
e.printStackTrace(); // 详细栈信息
|
||||||
emitter.completeWithError(e);
|
emitter.completeWithError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user