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;
|
||||
QJsonObject completionItem;
|
||||
|
||||
LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
|
||||
|
||||
QString processedCompletion
|
||||
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
||||
&& Settings::codeCompletionSettings().smartProcessInstuctText()
|
||||
|
@ -210,8 +210,7 @@ LLMCore::ContextData DocumentContextReader::prepareContext(int lineNumber, int c
|
||||
QString contextAfter = getContextAfter(lineNumber, cursorPosition);
|
||||
|
||||
QString fileContext;
|
||||
if (Settings::codeCompletionSettings().useFilePathInContext())
|
||||
fileContext.append("\n ").append(getLanguageAndFileInfo());
|
||||
fileContext.append("\n ").append(getLanguageAndFileInfo());
|
||||
|
||||
if (Settings::codeCompletionSettings().useProjectChangesCache())
|
||||
fileContext.append("\n ").append(
|
||||
|
@ -153,16 +153,24 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||
systemPrompt.setDefaultValue(
|
||||
"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 "
|
||||
"before or after <cursor>. You will receive a code context with specified insertion points. "
|
||||
"Your goal is to complete only one code block."
|
||||
"Here is the code context with insertion points:<code_context>Before: {{variable}}After: "
|
||||
"{{variable}}</code_context> Instructions: 1. Carefully analyze the provided code context. "
|
||||
"2. Consider the existing code and the specified insertion points.3. Generate a code "
|
||||
"suggestion that completes one logic expression between the 'Before' and 'After' points. "
|
||||
"4. Ensure your suggestion does not repeat any existing code. 5. Format your suggestion as "
|
||||
"a code block using triple backticks. 6. Do not include any comments or descriptions with "
|
||||
"your code suggestion.");
|
||||
"completion by continuing exactly from the cursor position, without repeating any "
|
||||
"characters that are already typed before the cursor. For example, if \"fo\" is typed and "
|
||||
"cursor is after \"fo\", suggest only \"r\" to complete \"for\", not the full word.\n\n"
|
||||
"Rules:\n"
|
||||
"1. Continue the code exactly from the cursor position\n"
|
||||
"2. Never repeat characters that appear before the cursor\n"
|
||||
"3. Complete up to the first unmatched closing parenthesis or semicolon\n"
|
||||
"4. Provide only the new characters needed to complete the code\n"
|
||||
"5. Format your suggestion as a code block\n\n"
|
||||
"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.setDefaultValue(true);
|
||||
@ -170,12 +178,9 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
|
||||
userMessageTemplateForCC.setSettingsKey(Constants::CC_USER_TEMPLATE);
|
||||
userMessageTemplateForCC.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||
userMessageTemplateForCC.setDefaultValue("Here is the code context with insertion points: <code_context>"
|
||||
"\nBefore: %1After: %2\n </code_context>");
|
||||
|
||||
useFilePathInContext.setSettingsKey(Constants::CC_USE_FILE_PATH_IN_CONTEXT);
|
||||
useFilePathInContext.setDefaultValue(true);
|
||||
useFilePathInContext.setLabelText(Tr::tr("Use File Path in Context"));
|
||||
userMessageTemplateForCC.setDefaultValue(
|
||||
"Here is the code context with insertion points: "
|
||||
"<code_context>\nBefore:%1\n<cursor>\nAfter:%2\n</code_context>\n\n");
|
||||
|
||||
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
|
||||
useProjectChangesCache.setDefaultValue(true);
|
||||
@ -239,7 +244,6 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
systemPrompt,
|
||||
Row{useUserMessageTemplateForCC, Stretch{1}},
|
||||
userMessageTemplateForCC,
|
||||
Row{useFilePathInContext, Stretch{1}},
|
||||
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
||||
|
||||
return Column{
|
||||
@ -327,11 +331,12 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
||||
resetAspect(readStringsAfterCursor);
|
||||
resetAspect(useSystemPrompt);
|
||||
resetAspect(systemPrompt);
|
||||
resetAspect(useFilePathInContext);
|
||||
resetAspect(useProjectChangesCache);
|
||||
resetAspect(maxChangesCacheSize);
|
||||
resetAspect(ollamaLivetime);
|
||||
resetAspect(contextWindow);
|
||||
resetAspect(useUserMessageTemplateForCC);
|
||||
resetAspect(userMessageTemplateForCC);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,6 @@ public:
|
||||
Utils::StringAspect systemPrompt{this};
|
||||
Utils::BoolAspect useUserMessageTemplateForCC{this};
|
||||
Utils::StringAspect userMessageTemplateForCC{this};
|
||||
Utils::BoolAspect useFilePathInContext{this};
|
||||
Utils::BoolAspect useProjectChangesCache{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_AFTER_CURSOR[] = "QodeAssist.ccReadStringsAfterCursor";
|
||||
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_USE_USER_TEMPLATE[] = "QodeAssist.ccUseUserTemplate";
|
||||
const char CC_USER_TEMPLATE[] = "QodeAssist.ccUserTemplate";
|
||||
|
Loading…
x
Reference in New Issue
Block a user