From 4142d793703101fe0d187cc64882d9afe289f827 Mon Sep 17 00:00:00 2001 From: sunhao Date: Thu, 25 Dec 2025 13:07:10 +0800 Subject: [PATCH] * [misc] enhance AI prompt handling by incorporating knowledge libraries and refining message processing logic. --- www/js/zui3/ai.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/www/js/zui3/ai.js b/www/js/zui3/ai.js index b876fc4a4e..065cb3ed78 100644 --- a/www/js/zui3/ai.js +++ b/www/js/zui3/ai.js @@ -189,21 +189,24 @@ window.executeZentaoPrompt = async function(info, testingMode) }; }, }]; + const klibs = (info.knowledgeLib ? info.knowledgeLib.split(',') : []).filter(Boolean).map(x => `zentao:${x}`); const formConfig = getPromptFormConfig(info.fields, info.formConfig); - zaiPanel.openPopup({ + const popupOptions = { id : 'zentao-prompt-popoup', viewType : 'chat', width : info.content ? 800 : 600, - postMessage: formConfig ? undefined : {content: [{role: 'system', content: info.dataPrompt}]}, + postMessage: {content: [{role: 'system', content: [info.dataPrompt, info.purpose].join('\n\n')}]}, creatingChat: { title : info.name, type : 'agent', model : info.model, tools : tools, - prompt : [info.prompt, zui.formatString(langData.promptExtraLimit, {toolName: toolName})].join('\n\n'), + prompt : [info.role, zui.formatString(langData.promptExtraLimit, {toolName: toolName})].join('\n\n'), form : formConfig, + memories : klibs.length ? [{collections: klibs}] : undefined, }, - }); + } + zaiPanel.openPopup(popupOptions); }; function registerZentaoAIPlugin(lang) @@ -351,14 +354,14 @@ function registerZentaoAIPlugin(lang) }); } - plugin.defineCallback('onCreateChat', async function(info) + plugin.defineCallback('onCreateChat', function(info) { - if(info.isLocal || !info.userPrompt) return; + if(info.isLocal) return; const originMemories = info.options.memories; if(!originMemories || !originMemories.length) return; - const knowledgeLibs = {}; - const otherMemories = originMemories.reduce((others, memory) => + const knowledgeLibs = {}; + const otherMemories = originMemories.reduce((others, memory) => { const ohterCollections = []; for(const collection of memory.collections) @@ -367,12 +370,6 @@ function registerZentaoAIPlugin(lang) { const lib = collection.substr(7); const newFilter = $.extend(true, {}, memory.content_filter); - if(!Object.keys(newFilter).length) - { - knowledgeLibs[lib] = {}; - break;; - } - const oldFilter = knowledgeLibs[lib] ? knowledgeLibs[lib] : null; const finalFilter = $.extend(true, {}, oldFilter, newFilter); if(newFilter && newFilter.attrs && oldFilter && oldFilter.attrs) @@ -404,9 +401,9 @@ function registerZentaoAIPlugin(lang) plugin.defineCallback('onPostMessage', async function(info) { - if(!info.userMessages || !info.userMessages.length) return; + if(!info.postingMessages || !info.postingMessages.length) return; if(!info.chat.custom_data || !info.chat.custom_data.ztklibs) return; - const userPrompt = info.userMessages.map(x => x.content).filter(x => x && x.trim().length).join('\n\n'); + const userPrompt = info.postingMessages.map(x => x.content).filter(x => x && x.trim().length).join('\n'); if(!userPrompt.length) return; info.updateState(lang.searchingKLibs);