chore(addon/aikefu): 只允许info及error的日志输出
This commit is contained in:
@@ -358,6 +358,10 @@ class Kefu extends BaseApi
|
|||||||
*/
|
*/
|
||||||
private function log($message, $level = 'info')
|
private function log($message, $level = 'info')
|
||||||
{
|
{
|
||||||
|
// 只允许info、error级别
|
||||||
|
if (!in_array($level, ['info', 'error'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
log_write($message, $level, '', 2);
|
log_write($message, $level, '', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
@@ -12,20 +13,24 @@
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.method-selector {
|
.method-selector {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.method-btn {
|
.method-btn {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
@@ -36,9 +41,11 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.method-btn.active {
|
.method-btn.active {
|
||||||
background-color: #0056b3;
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chat-container {
|
#chat-container {
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@@ -48,27 +55,32 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message {
|
.message {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-message {
|
.user-message {
|
||||||
background-color: #007bff;
|
background-color: #007bff;
|
||||||
color: white;
|
color: white;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ai-message {
|
.ai-message {
|
||||||
background-color: #e9ecef;
|
background-color: #e9ecef;
|
||||||
color: #333;
|
color: #333;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-area {
|
.input-area {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#message-input {
|
#message-input {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
@@ -76,6 +88,7 @@
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#send-btn {
|
#send-btn {
|
||||||
padding: 12px 20px;
|
padding: 12px 20px;
|
||||||
background-color: #28a745;
|
background-color: #28a745;
|
||||||
@@ -85,10 +98,12 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#send-btn:disabled {
|
#send-btn:disabled {
|
||||||
background-color: #6c757d;
|
background-color: #6c757d;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status {
|
.status {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -97,6 +112,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>流式聊天测试 Demo</h1>
|
<h1>流式聊天测试 Demo</h1>
|
||||||
@@ -214,8 +230,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.event === 'message_end') {
|
if (data.event === 'message_end') {
|
||||||
statusText.textContent = '对话完成';
|
statusText.textContent = '对话完成';
|
||||||
sendBtn.disabled = false;
|
sendBtn.disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.conversation_id) {
|
if (data.conversation_id) {
|
||||||
@@ -244,10 +260,18 @@
|
|||||||
// 监听错误事件
|
// 监听错误事件
|
||||||
es.addEventListener('error', (error) => {
|
es.addEventListener('error', (error) => {
|
||||||
console.error('EventSource 错误:', error);
|
console.error('EventSource 错误:', error);
|
||||||
|
// 添加更详细的错误信息
|
||||||
|
if (es.readyState === EventSource.CLOSED) {
|
||||||
|
console.error('EventSource 连接已关闭');
|
||||||
|
} else if (es.readyState === EventSource.CONNECTING) {
|
||||||
|
console.error('EventSource 连接中出现错误');
|
||||||
|
}
|
||||||
statusText.textContent = '连接错误';
|
statusText.textContent = '连接错误';
|
||||||
sendBtn.disabled = false;
|
sendBtn.disabled = false;
|
||||||
es.close();
|
if (es) {
|
||||||
es = null;
|
es.close();
|
||||||
|
es = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听关闭事件
|
// 监听关闭事件
|
||||||
@@ -433,4 +457,5 @@
|
|||||||
statusText.textContent = '就绪,使用 EventSource 方式';
|
statusText.textContent = '就绪,使用 EventSource 方式';
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user