perf: 优化AI消息

This commit is contained in:
kuaifan 2025-02-19 20:15:18 +08:00
parent 9e4beaa317
commit db6500369f
8 changed files with 58 additions and 14 deletions

View File

@ -1102,16 +1102,21 @@ class DialogController extends AbstractController
if (empty($size)) {
return Base::retError('消息发送保存失败');
}
$ext = $markdown ? 'md' : 'htm';
$text = MsgTool::truncateText($text, 500, $ext);
$desc = strip_tags($markdown ? Base::markdown2html($text) : $text);
$type = $markdown ? 'md' : 'htm';
$desc = $text;
if ($markdown) {
$desc = preg_replace("/:::\s*reasoning[\s\S]*?:::/", "", $desc);
$desc = Base::markdown2html($desc);
}
$desc = strip_tags($desc);
$desc = mb_substr(WebSocketDialogMsg::filterEscape($desc), 0, 200);
$text = MsgTool::truncateText($text, 500, $type);
$msgData = [
'type' => $type, // 内容类型
'desc' => $desc, // 描述内容
'text' => $text, // 简要内容
'type' => $ext, // 内容类型
'file' => [
'name' => "LongText-{$strlen}.{$ext}",
'name' => "LongText-{$strlen}.{$type}",
'size' => $size,
'file' => $file,
'path' => $path,
@ -1119,7 +1124,7 @@ class DialogController extends AbstractController
'thumb' => '',
'width' => -1,
'height' => -1,
'ext' => $ext,
'ext' => $type,
],
];
if (empty($key)) {

View File

@ -764,9 +764,15 @@ class WebSocketDialogMsg extends AbstractModel
$key = '';
switch ($this->type) {
case 'text':
if (!preg_match("/<span[^>]*?data-quick-key=([\"'])([^\"']+?)\\1[^>]*?>/is", $this->msg['text'])) {
$key = strip_tags($this->msg['text']);
if (preg_match("/<span[^>]*?data-quick-key=([\"'])([^\"']+?)\\1[^>]*?>/i", $this->msg['text'])) {
break;
}
$key = $this->msg['text'];
if ($this->msg['type'] === 'md') {
$key = preg_replace("/:::\s*reasoning[\s\S]*?:::/", "", $key);
$key = Base::markdown2html($key);
}
$key = strip_tags($key);
break;
case 'vote':
@ -1144,6 +1150,7 @@ class WebSocketDialogMsg extends AbstractModel
}
//
$updateData = [
'type' => $type,
'mtype' => $mtype,
'link' => $link,
'msg' => array_merge($oldMsg, $msg),

View File

@ -173,6 +173,7 @@ services:
environment:
REDIS_HOST: "${REDIS_HOST}"
REDIS_PORT: "${REDIS_PORT}"
TIMEOUT: 600
networks:
extnetwork:
ipv4_address: "${APP_IPPR}.12"

View File

@ -194,8 +194,9 @@ server {
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_connect_timeout 3600s;
proxy_set_header Scheme $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

View File

@ -32,28 +32,25 @@ if (languageName === "zh" || languageName === "zh-CHT") {
// Katex
import createKatexPlugin from '@kangc/v-md-editor/lib/plugins/katex/cdn';
VMdPreview.use(createKatexPlugin());
// Mermaid
import createMermaidPlugin from '@kangc/v-md-editor/lib/plugins/mermaid/cdn';
import '@kangc/v-md-editor/lib/plugins/mermaid/mermaid.css';
VMdPreview.use(createMermaidPlugin());
// TodoList
import createTodoListPlugin from '@kangc/v-md-editor/lib/plugins/todo-list/index';
import '@kangc/v-md-editor/lib/plugins/todo-list/todo-list.css';
VMdPreview.use(createTodoListPlugin());
// CopyCode
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
VMdPreview.use(createCopyCodePlugin());
import {previewMixin} from "../mixin";
import {MarkdownPluginUtils} from "../../../store/markdown";
export default {
mixins: [previewMixin],
@ -68,6 +65,7 @@ export default {
extend(md) {
// md markdown-it ,使 plugin
// md.set(option).use(plugin);
MarkdownPluginUtils.initReasoningPlugin(md);
},
});
},

View File

@ -248,6 +248,8 @@ const MarkdownPluginUtils = {
}
};
export {MarkdownPluginUtils}
export function MarkdownConver(text) {
if (text === '...') {
return '<div class="input-blink"></div>'

View File

@ -512,6 +512,35 @@ body {
padding-bottom: 0.8rem;
border-bottom: 1px solid #eaecef;
}
.apply-reasoning {
margin: 0 0 12px 0;
padding: 0 0 0 13px;
line-height: 26px;
position: relative;
&:before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 2px;
background-color: #e1e1e1;
}
.reasoning-label {
margin-bottom: 4px;
opacity: 0.9;
}
.reasoning-content {
opacity: 0.5;
> p:last-child {
margin-bottom: 0;
}
}
}
}
}

View File

@ -2083,6 +2083,7 @@
.reasoning-label {
margin-bottom: 4px;
opacity: 0.9;
}
.reasoning-content {