feat: 增强模型选择和错误处理机制
优化模型ID传递逻辑,支持请求级别的模型覆盖;完善流式响应的错误处理
This commit is contained in:
@@ -354,12 +354,14 @@ const loadConversationConfig = async () => {
|
||||
try {
|
||||
const response = await getConversationConfig();
|
||||
conversationConfig.value = response.data;
|
||||
const modelId = response.data?.summary_model_id || '';
|
||||
settingsStore.updateConversationModels({
|
||||
summaryModelId: response.data?.summary_model_id || '',
|
||||
summaryModelId: modelId,
|
||||
selectedChatModelId: modelId,
|
||||
rerankModelId: response.data?.rerank_model_id || '',
|
||||
});
|
||||
if (!selectedModelId.value) {
|
||||
selectedModelId.value = response.data?.summary_model_id || '';
|
||||
selectedModelId.value = modelId;
|
||||
}
|
||||
ensureModelSelection();
|
||||
} catch (error) {
|
||||
@@ -437,6 +439,7 @@ const handleModelChange = async (value: string | number | Array<string | number>
|
||||
// 同步到 store
|
||||
settingsStore.updateConversationModels({
|
||||
summaryModelId: val,
|
||||
selectedChatModelId: val,
|
||||
rerankModelId: conversationConfig.value?.rerank_model_id || '',
|
||||
});
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ export const useMenuStore = defineStore('menuStore', () => {
|
||||
const isFirstSession = ref(false)
|
||||
const firstQuery = ref('')
|
||||
const firstMentionedItems = ref<any[]>([])
|
||||
const firstModelId = ref('')
|
||||
|
||||
const applyMenuTranslations = () => {
|
||||
menuArr.forEach(item => {
|
||||
@@ -92,9 +93,10 @@ export const useMenuStore = defineStore('menuStore', () => {
|
||||
isFirstSession.value = payload
|
||||
}
|
||||
|
||||
const changeFirstQuery = (payload: string, mentionedItems: any[] = []) => {
|
||||
const changeFirstQuery = (payload: string, mentionedItems: any[] = [], modelId: string = '') => {
|
||||
firstQuery.value = payload
|
||||
firstMentionedItems.value = mentionedItems
|
||||
firstModelId.value = modelId
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -102,6 +104,7 @@ export const useMenuStore = defineStore('menuStore', () => {
|
||||
isFirstSession,
|
||||
firstQuery,
|
||||
firstMentionedItems,
|
||||
firstModelId,
|
||||
clearMenuArr,
|
||||
updatemenuArr,
|
||||
updataMenuChildren,
|
||||
|
||||
@@ -61,7 +61,7 @@ const useSettingsStoreInstance = useSettingsStore();
|
||||
const uiStore = useUIStore();
|
||||
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||||
const { t } = useI18n();
|
||||
const { menuArr, isFirstSession, firstQuery, firstMentionedItems } = storeToRefs(usemenuStore);
|
||||
const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId } = storeToRefs(usemenuStore);
|
||||
const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream } = useStream();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -672,13 +672,21 @@ const handleAgentChunk = (data) => {
|
||||
|
||||
// If this is an error response without tool data, handle it
|
||||
if (data.response_type === 'error' && !toolName) {
|
||||
message.content = data.content || t('chat.processError');
|
||||
const errorMsg = data.content || t('chat.processError');
|
||||
message.content = errorMsg;
|
||||
isReplying.value = false;
|
||||
loading.value = false;
|
||||
MessagePlugin.error(errorMsg);
|
||||
console.error('[Chat Error]', errorMsg);
|
||||
}
|
||||
} else if (data.response_type === 'error') {
|
||||
// Generic error without tool context
|
||||
message.content = data.content || t('chat.processError');
|
||||
const errorMsg = data.content || t('chat.processError');
|
||||
message.content = errorMsg;
|
||||
isReplying.value = false;
|
||||
loading.value = false;
|
||||
MessagePlugin.error(errorMsg);
|
||||
console.error('[Chat Error]', errorMsg);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -793,8 +801,8 @@ onMounted(async () => {
|
||||
checkmenuTitle(session_id.value)
|
||||
if (firstQuery.value) {
|
||||
scrollLock.value = true;
|
||||
sendMsg(firstQuery.value, '', firstMentionedItems.value || []);
|
||||
usemenuStore.changeFirstQuery('');
|
||||
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || []);
|
||||
usemenuStore.changeFirstQuery('', [], '');
|
||||
} else {
|
||||
scrollLock.value = false;
|
||||
let data = {
|
||||
|
||||
@@ -40,10 +40,10 @@ const { t } = useI18n();
|
||||
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||||
|
||||
const sendMsg = (value: string, modelId: string, mentionedItems: any[]) => {
|
||||
createNewSession(value, mentionedItems);
|
||||
createNewSession(value, modelId, mentionedItems);
|
||||
}
|
||||
|
||||
async function createNewSession(value: string, mentionedItems: any[] = []) {
|
||||
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = []) {
|
||||
const selectedKbs = settingsStore.settings.selectedKnowledgeBases || [];
|
||||
const selectedFiles = settingsStore.settings.selectedFiles || [];
|
||||
|
||||
@@ -63,7 +63,7 @@ async function createNewSession(value: string, mentionedItems: any[] = []) {
|
||||
try {
|
||||
const res = await createSessions(sessionData);
|
||||
if (res.data && res.data.id) {
|
||||
await navigateToSession(res.data.id, value, mentionedItems);
|
||||
await navigateToSession(res.data.id, value, modelId, mentionedItems);
|
||||
} else {
|
||||
console.error('[createChat] Failed to create session');
|
||||
MessagePlugin.error(t('createChat.messages.createFailed'));
|
||||
@@ -74,7 +74,7 @@ async function createNewSession(value: string, mentionedItems: any[] = []) {
|
||||
}
|
||||
}
|
||||
|
||||
const navigateToSession = async (sessionId: string, value: string, mentionedItems: any[]) => {
|
||||
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[]) => {
|
||||
const now = new Date().toISOString();
|
||||
let obj = {
|
||||
title: t('createChat.newSessionTitle'),
|
||||
@@ -87,7 +87,7 @@ const navigateToSession = async (sessionId: string, value: string, mentionedItem
|
||||
};
|
||||
usemenuStore.updataMenuChildren(obj);
|
||||
usemenuStore.changeIsFirstSession(true);
|
||||
usemenuStore.changeFirstQuery(value, mentionedItems);
|
||||
usemenuStore.changeFirstQuery(value, mentionedItems, modelId);
|
||||
router.push(`/platform/chat/${sessionId}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user