feat(prompt): enhance context and intent classification in templates
- Updated context template to include runtime metadata such as current time and week, improving contextual awareness in user queries. - Enhanced rewrite template with critical instructions for intent classification, ensuring that rewritten questions preserve essential entities and keywords. - Refined intent classification logic to prioritize user intents more effectively, improving the accuracy of responses based on user queries. - Added examples to clarify expected input and output formats for intent classification, enhancing usability for developers.
This commit is contained in:
@@ -1007,8 +1007,8 @@
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-wrapper">
|
||||
<t-slider v-model="formData.config.rerank_threshold" :min="0" :max="1" :step="0.01" />
|
||||
<span class="slider-value">{{ formData.config.rerank_threshold?.toFixed(2) }}</span>
|
||||
<t-slider v-model="formData.config.rerank_threshold" :min="-10" :max="10" :step="0.01" />
|
||||
<span class="slider-value">{{ formData.config.rerank_threshold?.toFixed(1) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -136,12 +136,10 @@ const closePreImg = () => {
|
||||
// 创建自定义渲染器实例
|
||||
const customRenderer = new marked.Renderer();
|
||||
// 覆盖图片渲染方法
|
||||
customRenderer.image = function({href, title, text}) {
|
||||
// 验证图片 URL 是否安全
|
||||
customRenderer.image = function(href, title, text) {
|
||||
if (!isValidImageURL(href)) {
|
||||
return `<p>${t('error.invalidImageLink')}</p>`;
|
||||
}
|
||||
// 使用安全的图片创建函数
|
||||
return createSafeImage(href, text || '', title || '');
|
||||
};
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div style="min-height: 115px; margin: 16px auto 4px;width: 100%;max-width: 800px;">
|
||||
<InputField
|
||||
@send-msg="(query, modelId, mentionedItems, imageFiles) => sendMsg(query, modelId, mentionedItems, imageFiles)"
|
||||
<InputField
|
||||
ref="inputFieldRef"
|
||||
@send-msg="(query, modelId, mentionedItems, imageFiles) => sendMsg(query, modelId, mentionedItems, imageFiles)"
|
||||
@stop-generation="handleStopGeneration"
|
||||
:isReplying="isReplying"
|
||||
:isReplying="isReplying"
|
||||
:sessionId="session_id"
|
||||
:assistantMessageId="currentAssistantMessageId"
|
||||
></InputField>
|
||||
@@ -87,6 +88,7 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const session_id = ref(route.params.chatid);
|
||||
const sessionData = ref(null);
|
||||
const inputFieldRef = ref();
|
||||
const created_at = ref('');
|
||||
const limit = ref(20);
|
||||
const messagesList = reactive([]);
|
||||
@@ -139,8 +141,11 @@ const fetchSuggestedQuestions = async () => {
|
||||
};
|
||||
|
||||
const handleSuggestedQuestionClick = (question) => {
|
||||
// 触发发送消息
|
||||
sendMsg(question);
|
||||
if (inputFieldRef.value?.triggerSend) {
|
||||
inputFieldRef.value.triggerSend(question);
|
||||
} else {
|
||||
sendMsg(question);
|
||||
}
|
||||
};
|
||||
|
||||
// 防抖包装,切换知识库/文件时300ms内不重复请求
|
||||
|
||||
@@ -5,16 +5,23 @@
|
||||
<span>{{ $t('createChat.title') }}</span>
|
||||
</div>
|
||||
<!-- 推荐问题 -->
|
||||
<div class="suggested-questions-container" :class="{ 'has-questions': suggestedQuestions.length > 0 }">
|
||||
<transition name="fade">
|
||||
<div v-if="suggestedQuestions.length > 0" class="suggested-questions-inner">
|
||||
<div ref="sqContainerRef" class="suggested-questions-container">
|
||||
<transition name="sq-slide-fade" mode="out-in"
|
||||
@before-leave="onBeforeLeave"
|
||||
@after-leave="onAfterLeave"
|
||||
@enter="onEnter"
|
||||
@after-enter="onQuestionsEntered"
|
||||
>
|
||||
<div v-if="suggestedQuestions.length > 0" :key="sqRenderKey" class="suggested-questions-inner">
|
||||
<div class="suggested-questions-title">{{ $t('chat.suggestedQuestions') }}</div>
|
||||
<div class="suggested-questions-grid">
|
||||
<div
|
||||
v-for="(item, index) in suggestedQuestions"
|
||||
:key="item.question"
|
||||
class="suggested-question-card"
|
||||
@click="sendMsg(item.question, '', [], [])"
|
||||
:class="{ 'sq-card-visible': sqCardsRevealed }"
|
||||
:style="{ transitionDelay: sqCardsRevealed ? `${index * 50}ms` : '0ms' }"
|
||||
@click="handleSuggestedQuestionClick(item.question)"
|
||||
>
|
||||
<span class="suggested-question-text">{{ item.question }}</span>
|
||||
<span v-if="item.source === 'faq'" class="suggested-question-badge faq">FAQ</span>
|
||||
@@ -23,7 +30,7 @@
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
<InputField @send-msg="sendMsg"></InputField>
|
||||
<InputField ref="inputFieldRef" @send-msg="sendMsg"></InputField>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -38,7 +45,7 @@
|
||||
/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted } from 'vue';
|
||||
import { ref, watch, onMounted, nextTick } from 'vue';
|
||||
import InputField from '@/components/Input-field.vue';
|
||||
import { createSessions } from "@/api/chat/index";
|
||||
import { getSuggestedQuestions } from "@/api/agent/index";
|
||||
@@ -62,9 +69,54 @@ const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||||
|
||||
// ===== 推荐问题 =====
|
||||
const suggestedQuestions = ref<SuggestedQuestion[]>([]);
|
||||
const sqCardsRevealed = ref(false);
|
||||
const sqRenderKey = ref(0);
|
||||
const sqContainerRef = ref<HTMLElement | null>(null);
|
||||
let suggestedQuestionsFetchId = 0;
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
// --- 高度平滑过渡钩子 ---
|
||||
const onBeforeLeave = () => {
|
||||
const c = sqContainerRef.value;
|
||||
if (!c) return;
|
||||
c.style.height = c.offsetHeight + 'px';
|
||||
c.style.overflow = 'hidden';
|
||||
};
|
||||
|
||||
const onAfterLeave = () => {
|
||||
const c = sqContainerRef.value;
|
||||
if (!c) return;
|
||||
if (suggestedQuestions.value.length === 0) {
|
||||
requestAnimationFrame(() => { c.style.height = '0px'; });
|
||||
c.addEventListener('transitionend', () => {
|
||||
c.style.height = '';
|
||||
c.style.overflow = '';
|
||||
}, { once: true });
|
||||
}
|
||||
};
|
||||
|
||||
const onEnter = (el: Element) => {
|
||||
const c = sqContainerRef.value;
|
||||
if (!c) return;
|
||||
const startHeight = c.offsetHeight;
|
||||
c.style.height = 'auto';
|
||||
c.style.overflow = 'hidden';
|
||||
const targetHeight = c.offsetHeight;
|
||||
c.style.height = startHeight + 'px';
|
||||
requestAnimationFrame(() => {
|
||||
c.style.height = targetHeight + 'px';
|
||||
});
|
||||
};
|
||||
|
||||
const onQuestionsEntered = () => {
|
||||
const c = sqContainerRef.value;
|
||||
if (c) {
|
||||
c.style.height = '';
|
||||
c.style.overflow = '';
|
||||
}
|
||||
nextTick(() => { sqCardsRevealed.value = true; });
|
||||
};
|
||||
|
||||
const fetchSuggestedQuestions = async () => {
|
||||
const fetchId = ++suggestedQuestionsFetchId;
|
||||
// 加载期间保留旧数据,不清空,避免布局抖动
|
||||
@@ -79,6 +131,8 @@ const fetchSuggestedQuestions = async () => {
|
||||
limit: 6,
|
||||
});
|
||||
if (fetchId === suggestedQuestionsFetchId) {
|
||||
sqCardsRevealed.value = false;
|
||||
sqRenderKey.value++;
|
||||
suggestedQuestions.value = res?.data?.questions || [];
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -102,6 +156,12 @@ watch(() => settingsStore.settings.selectedFiles, debouncedFetch, { deep: true }
|
||||
|
||||
onMounted(() => { fetchSuggestedQuestions(); });
|
||||
|
||||
const inputFieldRef = ref();
|
||||
|
||||
const handleSuggestedQuestionClick = (question: string) => {
|
||||
inputFieldRef.value?.triggerSend(question);
|
||||
};
|
||||
|
||||
const sendMsg = (value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
|
||||
createNewSession(value, modelId, mentionedItems, imageFiles);
|
||||
}
|
||||
@@ -214,12 +274,7 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
margin-bottom: 24px;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
min-height: 0;
|
||||
transition: min-height 0.3s ease;
|
||||
|
||||
&.has-questions {
|
||||
min-height: 80px; // 有内容时保持最小高度,避免加载新数据时塌缩
|
||||
}
|
||||
transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
.suggested-questions-inner {
|
||||
@@ -229,14 +284,22 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// 淡入淡出过渡
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.25s ease;
|
||||
// 容器整体过渡:淡入 + 轻微上滑
|
||||
.sq-slide-fade-enter-active {
|
||||
transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
.sq-slide-fade-leave-active {
|
||||
transition: opacity 0.15s cubic-bezier(0.4, 0, 1, 1),
|
||||
transform 0.15s cubic-bezier(0.4, 0, 1, 1);
|
||||
}
|
||||
.sq-slide-fade-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
.sq-slide-fade-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
.suggested-questions-title {
|
||||
@@ -263,8 +326,19 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
background: var(--td-bg-color-container);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
max-width: 100%;
|
||||
opacity: 0;
|
||||
transform: translateY(8px) scale(0.97);
|
||||
transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
border-color 0.2s ease,
|
||||
background 0.2s ease,
|
||||
box-shadow 0.2s ease;
|
||||
|
||||
&.sq-card-visible {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
|
||||
@@ -433,13 +433,13 @@
|
||||
<div class="setting-control slider-with-value">
|
||||
<t-slider
|
||||
v-model="localRerankThreshold"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
:min="-10"
|
||||
:max="10"
|
||||
:step="0.01"
|
||||
style="width: 240px;"
|
||||
@change="handleRerankThresholdChange"
|
||||
/>
|
||||
<span class="value-display">{{ localRerankThreshold.toFixed(2) }}</span>
|
||||
<span class="value-display">{{ localRerankThreshold.toFixed(1) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -92,9 +92,9 @@
|
||||
</div>
|
||||
<t-slider
|
||||
v-model="localConfig.rerank_threshold"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
:min="-10"
|
||||
:max="10"
|
||||
:step="0.1"
|
||||
@change="handleParamChange"
|
||||
/>
|
||||
</div>
|
||||
@@ -138,7 +138,7 @@ const loadConfig = async () => {
|
||||
vector_threshold: cfg.vector_threshold || defaultConfig.vector_threshold,
|
||||
keyword_threshold: cfg.keyword_threshold || defaultConfig.keyword_threshold,
|
||||
rerank_top_k: cfg.rerank_top_k || defaultConfig.rerank_top_k,
|
||||
rerank_threshold: cfg.rerank_threshold || defaultConfig.rerank_threshold,
|
||||
rerank_threshold: cfg.rerank_threshold ?? defaultConfig.rerank_threshold,
|
||||
rerank_model_id: cfg.rerank_model_id || '',
|
||||
})
|
||||
initialConfig = { ...localConfig }
|
||||
|
||||
Reference in New Issue
Block a user