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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -512,6 +512,35 @@ body {
padding-bottom: 0.8rem; padding-bottom: 0.8rem;
border-bottom: 1px solid #eaecef; 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 { .reasoning-label {
margin-bottom: 4px; margin-bottom: 4px;
opacity: 0.9;
} }
.reasoning-content { .reasoning-content {