From 9313ff769df521bb74c7176224650449dd394b31 Mon Sep 17 00:00:00 2001 From: sophie <16087569+sophie_liang@user.noreply.gitee.com> Date: Fri, 17 Apr 2026 10:58:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AD=94=E6=A1=88=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E6=80=9D=E8=80=83=E8=BF=87=E7=A8=8B=EF=BC=9B?= =?UTF-8?q?=E6=80=9D=E8=80=83=E6=B0=94=E6=B3=A1=E5=92=8C=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=B0=94=E6=B3=A1=E4=B8=8D=E5=90=8C=E6=97=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/config.py | 4 +-- backend/app/services/dify.py | 4 ++- frontend/dist/index.html | 39 +++++++++++++------------ frontend/index.html | 4 +-- frontend/src/composables/useChat.ts | 6 ++-- frontend/src/config.ts | 2 +- frontend/src/main.ts | 2 +- frontend/src/router/index.ts | 2 +- frontend/src/views/ChatView.vue | 45 ++++++++++++++++++++++++++--- 9 files changed, 74 insertions(+), 34 deletions(-) diff --git a/backend/app/config.py b/backend/app/config.py index 4cfcebc3..3132f780 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -53,7 +53,7 @@ class DevelopmentConfig(Config): DEBUG = True SQLALCHEMY_DATABASE_URI = os.getenv( 'DATABASE_URL', - 'postgresql://postgres:difyai123456@localhost:5432/hxops_db', + 'postgresql://postgres:123456@8.152.207.171:5432/hxops_db', ) @@ -61,7 +61,7 @@ class ProductionConfig(Config): DEBUG = False SQLALCHEMY_DATABASE_URI = os.getenv( 'DATABASE_URL', - 'postgresql://postgres:difyai123456@localhost:5432/hxops_prod', + 'postgresql://postgres:123456@8.152.207.171:5432/hxops_prod', ) diff --git a/backend/app/services/dify.py b/backend/app/services/dify.py index 879ea889..1930f323 100644 --- a/backend/app/services/dify.py +++ b/backend/app/services/dify.py @@ -129,7 +129,9 @@ class DifyService: DifyService._collect_metadata(retriever_resources, attribution_parts, data) elif event in ('message_end', 'agent_message', 'workflow_finished'): - if data.get('answer'): + # Keep metadata from non-message events, but avoid appending + # intermediate workflow/agent outputs into final user answer. + if event == 'message_end' and data.get('answer'): full_answer.append(data.get('answer', '')) DifyService._collect_metadata(retriever_resources, attribution_parts, data) diff --git a/frontend/dist/index.html b/frontend/dist/index.html index afffdd82..20ade220 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -1,19 +1,20 @@ - - - - - - - - - - - - hxai - - - - -
- - + + + + + + + + + + + + AI工作台 + + + + +
+ + + diff --git a/frontend/index.html b/frontend/index.html index 92532730..7bc203dd 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,9 +7,9 @@ - + - hxai + AI工作台
diff --git a/frontend/src/composables/useChat.ts b/frontend/src/composables/useChat.ts index 1446f9e7..e0f55b23 100644 --- a/frontend/src/composables/useChat.ts +++ b/frontend/src/composables/useChat.ts @@ -241,7 +241,7 @@ export function useChat() { conversationId: data?.conversation_id || conversationId.value, }); - if (data.event === 'message' || data.event === 'agent_message') { + if (data.event === 'message') { // event: message LLM 返回文本块事件,即:完整的文本以分块的方式输出。 if (typeof data.answer === 'string' && data.answer.length > 0) { // answer: LLM 返回文本块内容 @@ -253,11 +253,11 @@ export function useChat() { }); } applyEventMetadata(botMsg, data); - } else if (data.event === 'message_end' || data.event === 'workflow_finished') { + } else if (data.event === 'message_end') { if (data.conversation_id) { conversationId.value = data.conversation_id; } - // Some providers may put final answer on message_end/workflow events. + // Some providers may put final answer on message_end event. if (typeof data.answer === 'string' && data.answer.length > 0) { botMsg.content += data.answer; console.debug('[chat][sse] append final answer', { diff --git a/frontend/src/config.ts b/frontend/src/config.ts index e639083a..65868f70 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,5 +1,5 @@ export const config = { - appTitle: 'hxai', + appTitle: 'AI工作台', auth: { wecom: { enabled: true, diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 610a0081..5b48f038 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -7,7 +7,7 @@ import i18n from './i18n' import { config } from './config' // Set document title from config -document.title = config.appTitle || 'hxai'; +document.title = config.appTitle || 'AI工作台'; createApp(App) .use(router) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 804f508d..0123f2c9 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -48,7 +48,7 @@ const router = createRouter({ }); router.afterEach((to) => { - const baseTitle = config.appTitle || 'hxai'; + const baseTitle = config.appTitle || 'AI工作台'; if (to.meta.title) { document.title = `${to.meta.title} - ${baseTitle}`; } else { diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 51b6bacc..c7403440 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -24,13 +24,40 @@ import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog'; const { t, locale } = useI18n(); const { showMessageDialog } = useGlobalMessageDialog(); +const stripReasoningPrelude = (text: string) => { + if (!text) return ''; + let cleaned = text + .replace(//gi, '') + .replace(//gi, '') + .trim(); + + const reasoningMarkers = [ + '让我分析', + '根据应答生成规则', + '分析知识库返回的内容', + '我需要直接给出答案', + '思考过程', + '推理过程', + ]; + const hasReasoningMarker = reasoningMarkers.some((marker) => cleaned.includes(marker)); + if (!hasReasoningMarker) return cleaned; + + const headingMatch = cleaned.match(/(^|\n)\s{0,3}#{1,6}\s+/); + if (headingMatch && typeof headingMatch.index === 'number') { + const start = headingMatch.index + (headingMatch[1] ? headingMatch[1].length : 0); + cleaned = cleaned.slice(start).trim(); + } + return cleaned; +}; + const renderMarkdown = (text: string) => { if (!text) return ''; + const displayText = stripReasoningPrelude(text); try { // 把 # 标题、代码块、[链接](url) 等 Markdown 解析成 HTML - return marked.parse(text); + return marked.parse(displayText); } catch (e) { - return text; + return displayText; } }; @@ -302,6 +329,15 @@ const shouldExpandSourceDetails = (msg: any): boolean => { return getMessageLinks(msg).some((link) => isMarkdownFileName(link.name) || isMarkdownByUrl(link.url)); }; +const shouldRenderMessage = (msg: any): boolean => { + if (msg?.role === 'user') return true; + const content = (msg?.content || '').trim(); + if (content) return true; + if (getMessageLinks(msg).length > 0) return true; + if (getDisplayRetrieverResources(msg).length > 0) return true; + return Array.isArray(msg?.attribution_parts) && msg.attribution_parts.length > 0; +}; + const filePreviewVisible = ref(false); const previewFile = ref(null); @@ -642,9 +678,9 @@ const submitFeedback = async () => { +