fix: 答案不再包括思考过程;思考气泡和消息气泡不同时显示
This commit is contained in:
1 parent
b0fda9f081
commit
9313ff769d
9 files changed
+74
-34
No files matched your search
@@ -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',
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Vendored
+20
-19
@@ -1,19 +1,20 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0284c7" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
<meta name="apple-mobile-web-app-title" content="hxai" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<title>hxai</title>
|
||||
<script type="module" crossorigin src="/assets/index-CevSaenJ.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-CqpZrvvZ.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0284c7" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
<meta name="apple-mobile-web-app-title" content="AI工作台" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<title>AI工作台</title>
|
||||
<script type="module" crossorigin src="/assets/index-CG0nSVgb.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-1T4nGTgS.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>␍
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -7,9 +7,9 @@
|
||||
<meta name="theme-color" content="#0284c7" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
<meta name="apple-mobile-web-app-title" content="hxai" />
|
||||
<meta name="apple-mobile-web-app-title" content="AI工作台" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<title>hxai</title>
|
||||
<title>AI工作台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const config = {
|
||||
appTitle: 'hxai',
|
||||
appTitle: 'AI工作台',
|
||||
auth: {
|
||||
wecom: {
|
||||
enabled: true,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(/<think[\s\S]*?<\/think>/gi, '')
|
||||
.replace(/<analysis[\s\S]*?<\/analysis>/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<SourceFileLink | null>(null);
|
||||
|
||||
@@ -642,9 +678,9 @@ const submitFeedback = async () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-for="(msg, index) in messages" :key="index">
|
||||
<div
|
||||
v-for="(msg, index) in messages"
|
||||
:key="index"
|
||||
v-if="shouldRenderMessage(msg)"
|
||||
class="group mx-auto flex max-w-5xl gap-0 animate-slide-up"
|
||||
:class="msg.role === 'user' ? 'justify-end' : ''"
|
||||
>
|
||||
@@ -770,6 +806,7 @@ const submitFeedback = async () => {
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="isThinking" class="mx-auto flex max-w-5xl gap-4">
|
||||
<div class="mt-1 flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-cyan-500 to-blue-600 shadow-md shadow-cyan-500/30">
|
||||
|
||||
Reference in new issue
Block a user