mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
refactor: Optimize SystemPrompt for code completion
This commit is contained in:
parent
60936f6d84
commit
bd25736a55
@ -217,10 +217,8 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
||||
QString userMessage;
|
||||
if (completeSettings.useUserMessageTemplateForCC()
|
||||
&& promptTemplate->type() == LLMCore::TemplateType::Chat) {
|
||||
userMessage = processMessageToFIM(
|
||||
completeSettings.userMessageTemplateForCC(),
|
||||
updatedContext.prefix,
|
||||
updatedContext.suffix);
|
||||
userMessage
|
||||
= completeSettings.processMessageToFIM(updatedContext.prefix, updatedContext.suffix);
|
||||
} else {
|
||||
userMessage = updatedContext.prefix;
|
||||
}
|
||||
@ -246,15 +244,6 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
||||
m_requestHandler.sendLLMRequest(config, request);
|
||||
}
|
||||
|
||||
QString LLMClientInterface::processMessageToFIM(
|
||||
const QString &templateText, const QString &prefix, const QString &suffix)
|
||||
{
|
||||
QString result = templateText;
|
||||
result.replace("${prefix}", prefix);
|
||||
result.replace("${suffix}", suffix);
|
||||
return result;
|
||||
}
|
||||
|
||||
LLMCore::ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
|
||||
const QStringView &accumulatedCompletion)
|
||||
{
|
||||
|
@ -71,8 +71,6 @@ private:
|
||||
void startTimeMeasurement(const QString &requestId);
|
||||
void endTimeMeasurement(const QString &requestId);
|
||||
void logPerformance(const QString &requestId, const QString &operation, qint64 elapsedMs);
|
||||
QString processMessageToFIM(
|
||||
const QString &templateText, const QString &prefix, const QString &suffix);
|
||||
};
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
@ -152,25 +152,26 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
systemPrompt.setSettingsKey(Constants::CC_SYSTEM_PROMPT);
|
||||
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||
systemPrompt.setDefaultValue(
|
||||
"You are an expert in C++, Qt, and QML programming. Your task is to provide code "
|
||||
"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"
|
||||
"You are an expert C++, Qt, and QML code completion assistant. Your task is to provide "
|
||||
"precise and contextually appropriate code completions.\n\n"
|
||||
"Core Requirements:\n"
|
||||
"1. Continue code exactly from the cursor position, ensuring it properly connects with any "
|
||||
"existing code after the cursor\n"
|
||||
"2. Never repeat existing code before or after the cursor\n"
|
||||
"Specific Guidelines:\n"
|
||||
"- For function calls: Complete parameters with appropriate types and names\n"
|
||||
"- For class members: Respect access modifiers and class conventions\n"
|
||||
"- Respect existing indentation and formatting\n"
|
||||
"- Consider scope and visibility of referenced symbols\n"
|
||||
"- Ensure seamless integration with code both before and after the cursor\n\n"
|
||||
"Context Format:\n"
|
||||
"<code_context>\n"
|
||||
"Before:{{code before cursor}}\n"
|
||||
"<cursor>\n"
|
||||
"After:{{code after cursor}}\n"
|
||||
"{{code before cursor}}<cursor>{{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.");
|
||||
"Response Format:\n"
|
||||
"- No explanations or comments\n"
|
||||
"- Only include new characters needed to create valid code\n"
|
||||
"- Should be codeblock with language\n");
|
||||
|
||||
useUserMessageTemplateForCC.setSettingsKey(Constants::CC_USE_USER_TEMPLATE);
|
||||
useUserMessageTemplateForCC.setDefaultValue(true);
|
||||
@ -179,8 +180,8 @@ 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:${prefix}\n<cursor>\nAfter:${suffix}\n</code_context>\n\n");
|
||||
"Here is the code context with insertion points:\n"
|
||||
"<code_context>\n${prefix}<cursor>${suffix}\n</code_context>\n");
|
||||
|
||||
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
|
||||
useProjectChangesCache.setDefaultValue(true);
|
||||
@ -340,6 +341,14 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
QString CodeCompletionSettings::processMessageToFIM(const QString &prefix, const QString &suffix)
|
||||
{
|
||||
QString result = userMessageTemplateForCC();
|
||||
result.replace("${prefix}", prefix);
|
||||
result.replace("${suffix}", suffix);
|
||||
return result;
|
||||
}
|
||||
|
||||
class CodeCompletionSettingsPage : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
|
@ -78,6 +78,8 @@ public:
|
||||
// API Configuration Settings
|
||||
Utils::StringAspect apiKey{this};
|
||||
|
||||
QString processMessageToFIM(const QString &prefix, const QString &suffix);
|
||||
|
||||
private:
|
||||
void setupConnections();
|
||||
void resetSettingsToDefaults();
|
||||
|
Loading…
Reference in New Issue
Block a user