fix: memory 工具 required 数组添加 type — 解决模型持续不传 type 参数问题

Ollama function calling 依赖 JSON Schema 的 required 数组判断参数必要性,
type 不在 required 中导致模型认为它是可选的,即使 error 提示了也不传。
将其加入 required 数组后,模型将被强制要求每次调用都提供 type 参数。
This commit is contained in:
紫影233
2026-06-24 15:10:58 +08:00
parent e119ffbcf6
commit d3a28822b3
2 changed files with 23 additions and 2 deletions
+22 -1
View File
@@ -194,7 +194,7 @@ app.on('window-all-closed', () => {
} }
}); });
app.on('before-quit', () => { app.on('before-quit', async () => {
isQuitting = true; isQuitting = true;
// 清理浏览器 // 清理浏览器
browserClose(); browserClose();
@@ -204,4 +204,25 @@ app.on('before-quit', () => {
killAllProcesses(); killAllProcesses();
// 通知渲染进程释放显存 // 通知渲染进程释放显存
mainWindow?.webContents.send('app-quit'); mainWindow?.webContents.send('app-quit');
// 主进程直接调用 Ollama API 释放显存(更可靠,不依赖渲染进程)
try {
const OLlama_URL = 'http://127.0.0.1:11434';
const psResp = await fetch(`${OLlama_URL}/api/ps`);
if (psResp.ok) {
const psData = await psResp.json() as { models?: Array<{ name: string }> };
const models = psData.models || [];
for (const m of models) {
try {
await fetch(`${OLlama_URL}/api/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model: m.name, keep_alive: 0 }),
});
} catch { /* 忽略单个模型释放失败 */ }
}
if (models.length > 0) {
console.log(`[before-quit] 已释放 ${models.length} 个模型显存`);
}
}
} catch { /* 释放显存失败不影响退出 */ }
}); });
+1 -1
View File
@@ -367,7 +367,7 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [
CRITICAL: For add action, you MUST include both "type" (fact/preference/rule) and "content" fields. If you omit them, the call will fail.`, CRITICAL: For add action, you MUST include both "type" (fact/preference/rule) and "content" fields. If you omit them, the call will fail.`,
parameters: { parameters: {
type: 'object', type: 'object',
required: ['action'], required: ['action', 'type'],
properties: { properties: {
action: { type: 'string', enum: ['search', 'add', 'replace', 'remove', 'read_all'], description: 'Which operation to perform.' }, action: { type: 'string', enum: ['search', 'add', 'replace', 'remove', 'read_all'], description: 'Which operation to perform.' },
query: { type: 'string', description: '[search] Keywords to search for.' }, query: { type: 'string', description: '[search] Keywords to search for.' },