mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
refactor: Improve system prompt and message
This commit is contained in:
parent
1fa6a225a4
commit
7d23d0323f
@ -306,6 +306,8 @@ void LLMClientInterface::sendCompletionToClient(const QString &completion,
|
|||||||
QJsonArray completions;
|
QJsonArray completions;
|
||||||
QJsonObject completionItem;
|
QJsonObject completionItem;
|
||||||
|
|
||||||
|
LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
|
||||||
|
|
||||||
QString processedCompletion
|
QString processedCompletion
|
||||||
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
||||||
&& Settings::codeCompletionSettings().smartProcessInstuctText()
|
&& Settings::codeCompletionSettings().smartProcessInstuctText()
|
||||||
|
@ -210,7 +210,6 @@ LLMCore::ContextData DocumentContextReader::prepareContext(int lineNumber, int c
|
|||||||
QString contextAfter = getContextAfter(lineNumber, cursorPosition);
|
QString contextAfter = getContextAfter(lineNumber, cursorPosition);
|
||||||
|
|
||||||
QString fileContext;
|
QString fileContext;
|
||||||
if (Settings::codeCompletionSettings().useFilePathInContext())
|
|
||||||
fileContext.append("\n ").append(getLanguageAndFileInfo());
|
fileContext.append("\n ").append(getLanguageAndFileInfo());
|
||||||
|
|
||||||
if (Settings::codeCompletionSettings().useProjectChangesCache())
|
if (Settings::codeCompletionSettings().useProjectChangesCache())
|
||||||
|
@ -153,16 +153,24 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||||
systemPrompt.setDefaultValue(
|
systemPrompt.setDefaultValue(
|
||||||
"You are an expert in C++, Qt, and QML programming. Your task is to provide code "
|
"You are an expert in C++, Qt, and QML programming. Your task is to provide code "
|
||||||
"suggestions that seamlessly integrate with existing code. Do not repeat code from position "
|
"completion by continuing exactly from the cursor position, without repeating any "
|
||||||
"before or after <cursor>. You will receive a code context with specified insertion points. "
|
"characters that are already typed before the cursor. For example, if \"fo\" is typed and "
|
||||||
"Your goal is to complete only one code block."
|
"cursor is after \"fo\", suggest only \"r\" to complete \"for\", not the full word.\n\n"
|
||||||
"Here is the code context with insertion points:<code_context>Before: {{variable}}After: "
|
"Rules:\n"
|
||||||
"{{variable}}</code_context> Instructions: 1. Carefully analyze the provided code context. "
|
"1. Continue the code exactly from the cursor position\n"
|
||||||
"2. Consider the existing code and the specified insertion points.3. Generate a code "
|
"2. Never repeat characters that appear before the cursor\n"
|
||||||
"suggestion that completes one logic expression between the 'Before' and 'After' points. "
|
"3. Complete up to the first unmatched closing parenthesis or semicolon\n"
|
||||||
"4. Ensure your suggestion does not repeat any existing code. 5. Format your suggestion as "
|
"4. Provide only the new characters needed to complete the code\n"
|
||||||
"a code block using triple backticks. 6. Do not include any comments or descriptions with "
|
"5. Format your suggestion as a code block\n\n"
|
||||||
"your code suggestion.");
|
"Context format:\n"
|
||||||
|
"<code_context>\n"
|
||||||
|
"Before:{{code before cursor}}\n"
|
||||||
|
"<cursor>\n"
|
||||||
|
"After:{{code after cursor}}\n"
|
||||||
|
"</code_context>\n\n"
|
||||||
|
"Output format: Format your suggestion as a code block with language. Do not include any "
|
||||||
|
"comments or "
|
||||||
|
"descriptions with your code suggestion.");
|
||||||
|
|
||||||
useUserMessageTemplateForCC.setSettingsKey(Constants::CC_USE_USER_TEMPLATE);
|
useUserMessageTemplateForCC.setSettingsKey(Constants::CC_USE_USER_TEMPLATE);
|
||||||
useUserMessageTemplateForCC.setDefaultValue(true);
|
useUserMessageTemplateForCC.setDefaultValue(true);
|
||||||
@ -170,12 +178,9 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
|
|
||||||
userMessageTemplateForCC.setSettingsKey(Constants::CC_USER_TEMPLATE);
|
userMessageTemplateForCC.setSettingsKey(Constants::CC_USER_TEMPLATE);
|
||||||
userMessageTemplateForCC.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
userMessageTemplateForCC.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||||
userMessageTemplateForCC.setDefaultValue("Here is the code context with insertion points: <code_context>"
|
userMessageTemplateForCC.setDefaultValue(
|
||||||
"\nBefore: %1After: %2\n </code_context>");
|
"Here is the code context with insertion points: "
|
||||||
|
"<code_context>\nBefore:%1\n<cursor>\nAfter:%2\n</code_context>\n\n");
|
||||||
useFilePathInContext.setSettingsKey(Constants::CC_USE_FILE_PATH_IN_CONTEXT);
|
|
||||||
useFilePathInContext.setDefaultValue(true);
|
|
||||||
useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context"));
|
|
||||||
|
|
||||||
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
|
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
|
||||||
useProjectChangesCache.setDefaultValue(true);
|
useProjectChangesCache.setDefaultValue(true);
|
||||||
@ -239,7 +244,6 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
systemPrompt,
|
systemPrompt,
|
||||||
Row{useUserMessageTemplateForCC, Stretch{1}},
|
Row{useUserMessageTemplateForCC, Stretch{1}},
|
||||||
userMessageTemplateForCC,
|
userMessageTemplateForCC,
|
||||||
Row{useFilePathInContext, Stretch{1}},
|
|
||||||
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
||||||
|
|
||||||
return Column{
|
return Column{
|
||||||
@ -327,11 +331,12 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
|||||||
resetAspect(readStringsAfterCursor);
|
resetAspect(readStringsAfterCursor);
|
||||||
resetAspect(useSystemPrompt);
|
resetAspect(useSystemPrompt);
|
||||||
resetAspect(systemPrompt);
|
resetAspect(systemPrompt);
|
||||||
resetAspect(useFilePathInContext);
|
|
||||||
resetAspect(useProjectChangesCache);
|
resetAspect(useProjectChangesCache);
|
||||||
resetAspect(maxChangesCacheSize);
|
resetAspect(maxChangesCacheSize);
|
||||||
resetAspect(ollamaLivetime);
|
resetAspect(ollamaLivetime);
|
||||||
resetAspect(contextWindow);
|
resetAspect(contextWindow);
|
||||||
|
resetAspect(useUserMessageTemplateForCC);
|
||||||
|
resetAspect(userMessageTemplateForCC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ public:
|
|||||||
Utils::StringAspect systemPrompt{this};
|
Utils::StringAspect systemPrompt{this};
|
||||||
Utils::BoolAspect useUserMessageTemplateForCC{this};
|
Utils::BoolAspect useUserMessageTemplateForCC{this};
|
||||||
Utils::StringAspect userMessageTemplateForCC{this};
|
Utils::StringAspect userMessageTemplateForCC{this};
|
||||||
Utils::BoolAspect useFilePathInContext{this};
|
|
||||||
Utils::BoolAspect useProjectChangesCache{this};
|
Utils::BoolAspect useProjectChangesCache{this};
|
||||||
Utils::IntegerAspect maxChangesCacheSize{this};
|
Utils::IntegerAspect maxChangesCacheSize{this};
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ const char CC_READ_FULL_FILE[] = "QodeAssist.ccReadFullFile";
|
|||||||
const char CC_READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.ccReadStringsBeforeCursor";
|
const char CC_READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.ccReadStringsBeforeCursor";
|
||||||
const char CC_READ_STRINGS_AFTER_CURSOR[] = "QodeAssist.ccReadStringsAfterCursor";
|
const char CC_READ_STRINGS_AFTER_CURSOR[] = "QodeAssist.ccReadStringsAfterCursor";
|
||||||
const char CC_USE_SYSTEM_PROMPT[] = "QodeAssist.ccUseSystemPrompt";
|
const char CC_USE_SYSTEM_PROMPT[] = "QodeAssist.ccUseSystemPrompt";
|
||||||
const char CC_USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.ccUseFilePathInContext";
|
|
||||||
const char CC_SYSTEM_PROMPT[] = "QodeAssist.ccSystemPrompt";
|
const char CC_SYSTEM_PROMPT[] = "QodeAssist.ccSystemPrompt";
|
||||||
const char CC_USE_USER_TEMPLATE[] = "QodeAssist.ccUseUserTemplate";
|
const char CC_USE_USER_TEMPLATE[] = "QodeAssist.ccUseUserTemplate";
|
||||||
const char CC_USER_TEMPLATE[] = "QodeAssist.ccUserTemplate";
|
const char CC_USER_TEMPLATE[] = "QodeAssist.ccUserTemplate";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user