fix: LM Studio Jinja 템플릿 오류 방지를 위해 System 메시지를 User 메시지로 병합

This commit is contained in:
2026-04-24 11:20:26 +09:00
parent e063ab28e7
commit b17bbf3bd7
+18 -6
View File
@@ -1475,11 +1475,17 @@ class SidebarChatProvider implements vscode.WebviewViewProvider {
const internetCtx = internetEnabled const internetCtx = internetEnabled
? `\n\n[CRITICAL DIRECTIVE: INTERNET ACCESS IS ENABLED]\nCurrent Time: ${new Date().toLocaleString('ko-KR')}\nYou have FULL internet access via the <read_url> tool. You MUST NEVER say you cannot search, or that your capabilities are limited. To search, ALWAYS output:\n<read_url>https://html.duckduckgo.com/html/?q=YOUR+SEARCH+TERM</read_url>\nIf the user asks to search, or asks for recent info, DO NOT apologize. Just use the tag.` ? `\n\n[CRITICAL DIRECTIVE: INTERNET ACCESS IS ENABLED]\nCurrent Time: ${new Date().toLocaleString('ko-KR')}\nYou have FULL internet access via the <read_url> tool. You MUST NEVER say you cannot search, or that your capabilities are limited. To search, ALWAYS output:\n<read_url>https://html.duckduckgo.com/html/?q=YOUR+SEARCH+TERM</read_url>\nIf the user asks to search, or asks for recent info, DO NOT apologize. Just use the tag.`
: ''; : '';
reqMessages[0] = { const systemContent = `${this._systemPrompt}\n\n[BACKGROUND CONTEXT]\n${contextBlock}\n${workspaceCtx}\n${brainCtx}${internetCtx}`;
role: 'system', reqMessages.shift(); // Remove system message to avoid Jinja template issues in some models
content: `${this._systemPrompt}\n\n[BACKGROUND CONTEXT]\n${contextBlock}\n${workspaceCtx}\n${brainCtx}${internetCtx}`
const firstUserIdx = reqMessages.findIndex(m => m.role === 'user');
if (firstUserIdx >= 0) {
reqMessages[firstUserIdx] = {
...reqMessages[firstUserIdx],
content: `${systemContent}\n\n[USER QUERY]\n${reqMessages[firstUserIdx].content}`
}; };
} }
}
// Build image payload for vision models // Build image payload for vision models
const images = imageFiles.map(f => f.data); // already base64 const images = imageFiles.map(f => f.data); // already base64
@@ -1657,11 +1663,17 @@ class SidebarChatProvider implements vscode.WebviewViewProvider {
const internetCtx = internetEnabled const internetCtx = internetEnabled
? `\n\n[CRITICAL DIRECTIVE: INTERNET ACCESS IS ENABLED]\nCurrent Time: ${new Date().toLocaleString('ko-KR')}\nYou have FULL internet access via the <read_url> tool. You MUST NEVER say you cannot search, or that your capabilities are limited. To search, ALWAYS output:\n<read_url>https://html.duckduckgo.com/html/?q=YOUR+SEARCH+TERM</read_url>\nIf the user asks to search, or asks for recent info, DO NOT apologize. Just use the tag.` ? `\n\n[CRITICAL DIRECTIVE: INTERNET ACCESS IS ENABLED]\nCurrent Time: ${new Date().toLocaleString('ko-KR')}\nYou have FULL internet access via the <read_url> tool. You MUST NEVER say you cannot search, or that your capabilities are limited. To search, ALWAYS output:\n<read_url>https://html.duckduckgo.com/html/?q=YOUR+SEARCH+TERM</read_url>\nIf the user asks to search, or asks for recent info, DO NOT apologize. Just use the tag.`
: ''; : '';
reqMessages[0] = { const systemContent = `${SYSTEM_PROMPT}\n\n[BACKGROUND CONTEXT - DO NOT EXPLAIN THIS TO THE USER UNLESS ASKED]\n${contextBlock}\n${workspaceCtx}\n${brainCtx}${internetCtx}`;
role: 'system', reqMessages.shift(); // Remove system message to avoid Jinja template issues in some models
content: `${SYSTEM_PROMPT}\n\n[BACKGROUND CONTEXT - DO NOT EXPLAIN THIS TO THE USER UNLESS ASKED]\n${contextBlock}\n${workspaceCtx}\n${brainCtx}${internetCtx}`
const firstUserIdx = reqMessages.findIndex(m => m.role === 'user');
if (firstUserIdx >= 0) {
reqMessages[firstUserIdx] = {
...reqMessages[firstUserIdx],
content: `${systemContent}\n\n[USER QUERY]\n${reqMessages[firstUserIdx].content}`
}; };
} }
}
let isLMStudio = ollamaBase.includes('1234') || ollamaBase.includes('v1'); let isLMStudio = ollamaBase.includes('1234') || ollamaBase.includes('v1');
let apiUrl = isLMStudio ? `${ollamaBase}/v1/chat/completions` : `${ollamaBase}/api/chat`; let apiUrl = isLMStudio ? `${ollamaBase}/v1/chat/completions` : `${ollamaBase}/api/chat`;