* [misc] enhance AI prompt handling by incorporating knowledge libraries and refining message processing logic.

This commit is contained in:
sunhao
2025-12-25 14:52:46 +08:00
parent 2ee5b4ff18
commit 4142d79370
+13 -16
View File
@@ -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);