mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-22 02:22:44 -05:00
refactor: Add model output settings instead smartprocessing setting (#220)
This commit is contained in:
@ -99,6 +99,19 @@ const QVector<LanguageProperties> &getKnownLanguages()
|
|||||||
return knownLanguages;
|
return knownLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CodeHandler::hasCodeBlocks(const QString &text)
|
||||||
|
{
|
||||||
|
QStringList lines = text.split('\n');
|
||||||
|
|
||||||
|
for (const QString &line : lines) {
|
||||||
|
if (line.trimmed().startsWith("```")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static QHash<QString, QString> buildLanguageToCommentPrefixMap()
|
static QHash<QString, QString> buildLanguageToCommentPrefixMap()
|
||||||
{
|
{
|
||||||
QHash<QString, QString> result;
|
QHash<QString, QString> result;
|
||||||
|
|||||||
@ -40,6 +40,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
static QString detectLanguageFromExtension(const QString &extension);
|
static QString detectLanguageFromExtension(const QString &extension);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects if text contains code blocks, or returns false if this was not possible
|
||||||
|
*/
|
||||||
|
static bool hasCodeBlocks(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString getCommentPrefix(const QString &language);
|
static QString getCommentPrefix(const QString &language);
|
||||||
|
|
||||||
|
|||||||
@ -347,11 +347,21 @@ void LLMClientInterface::sendCompletionToClient(
|
|||||||
|
|
||||||
LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
|
LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
|
||||||
|
|
||||||
QString processedCompletion
|
QString outputHandler = m_completeSettings.modelOutputHandler.stringValue();
|
||||||
= promptTemplate->type() == LLMCore::TemplateType::Chat
|
QString processedCompletion;
|
||||||
&& m_completeSettings.smartProcessInstuctText()
|
|
||||||
? CodeHandler::processText(completion, Context::extractFilePathFromRequest(request))
|
if (outputHandler == "Raw text") {
|
||||||
|
processedCompletion = completion;
|
||||||
|
} else if (outputHandler == "Force processing") {
|
||||||
|
processedCompletion = CodeHandler::processText(completion,
|
||||||
|
Context::extractFilePathFromRequest(request));
|
||||||
|
} else { // "Auto"
|
||||||
|
processedCompletion = CodeHandler::hasCodeBlocks(completion)
|
||||||
|
? CodeHandler::processText(completion,
|
||||||
|
Context::extractFilePathFromRequest(
|
||||||
|
request))
|
||||||
: completion;
|
: completion;
|
||||||
|
}
|
||||||
|
|
||||||
completionItem[LanguageServerProtocol::textKey] = processedCompletion;
|
completionItem[LanguageServerProtocol::textKey] = processedCompletion;
|
||||||
QJsonObject range;
|
QJsonObject range;
|
||||||
|
|||||||
@ -55,9 +55,19 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
stream.setDefaultValue(true);
|
stream.setDefaultValue(true);
|
||||||
stream.setLabelText(Tr::tr("Enable stream option"));
|
stream.setLabelText(Tr::tr("Enable stream option"));
|
||||||
|
|
||||||
smartProcessInstuctText.setSettingsKey(Constants::CC_SMART_PROCESS_INSTRUCT_TEXT);
|
modelOutputHandler.setLabelText(Tr::tr("Text output proccessing mode:"));
|
||||||
smartProcessInstuctText.setDefaultValue(true);
|
modelOutputHandler.setSettingsKey(Constants::CC_MODEL_OUTPUT_HANDLER);
|
||||||
smartProcessInstuctText.setLabelText(Tr::tr("Enable smart process text from instruct model"));
|
modelOutputHandler.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
|
||||||
|
modelOutputHandler.addOption("Auto");
|
||||||
|
modelOutputHandler.addOption("Force processing");
|
||||||
|
modelOutputHandler.addOption("Raw text");
|
||||||
|
modelOutputHandler.setDefaultValue("Auto");
|
||||||
|
modelOutputHandler.setToolTip(
|
||||||
|
Tr::tr("Auto: Automatically detects codeblock and applies processing when found, other "
|
||||||
|
"text as comments\n"
|
||||||
|
"Force Processing: Always processes text with codeblock formatting and other text "
|
||||||
|
"as comments\n"
|
||||||
|
"Raw Text: Shows unprocessed text without any formatting"));
|
||||||
|
|
||||||
startSuggestionTimer.setSettingsKey(Constants::СС_START_SUGGESTION_TIMER);
|
startSuggestionTimer.setSettingsKey(Constants::СС_START_SUGGESTION_TIMER);
|
||||||
startSuggestionTimer.setLabelText(Tr::tr("with delay(ms)"));
|
startSuggestionTimer.setLabelText(Tr::tr("with delay(ms)"));
|
||||||
@ -287,17 +297,14 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
}},
|
}},
|
||||||
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
||||||
|
|
||||||
return Column{
|
return Column{Row{Stretch{1}, resetToDefaults},
|
||||||
Row{Stretch{1}, resetToDefaults},
|
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{
|
Group{title(TrConstants::AUTO_COMPLETION_SETTINGS),
|
||||||
title(TrConstants::AUTO_COMPLETION_SETTINGS),
|
Column{autoCompletion,
|
||||||
Column{
|
|
||||||
autoCompletion,
|
|
||||||
Space{8},
|
Space{8},
|
||||||
multiLineCompletion,
|
multiLineCompletion,
|
||||||
stream,
|
stream,
|
||||||
smartProcessInstuctText,
|
Row{modelOutputHandler, Stretch{1}},
|
||||||
Row{autoCompletionCharThreshold,
|
Row{autoCompletionCharThreshold,
|
||||||
autoCompletionTypingInterval,
|
autoCompletionTypingInterval,
|
||||||
startSuggestionTimer,
|
startSuggestionTimer,
|
||||||
@ -305,18 +312,17 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
showProgressWidget,
|
showProgressWidget,
|
||||||
useOpenFilesContext}},
|
useOpenFilesContext}},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{
|
Group{title(Tr::tr("General Parameters")),
|
||||||
title(Tr::tr("General Parameters")),
|
|
||||||
Column{
|
Column{
|
||||||
Row{genGrid, Stretch{1}},
|
Row{genGrid, Stretch{1}},
|
||||||
}},
|
}},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{title(Tr::tr("Advanced Parameters")), Column{Row{advancedGrid, Stretch{1}}}},
|
Group{title(Tr::tr("Advanced Parameters")),
|
||||||
|
Column{Row{advancedGrid, Stretch{1}}}},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{title(Tr::tr("Context Settings")), contextItem},
|
Group{title(Tr::tr("Context Settings")), contextItem},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{
|
Group{title(Tr::tr("Quick Refactor Settings")),
|
||||||
title(Tr::tr("Quick Refactor Settings")),
|
|
||||||
Column{useOpenFilesInQuickRefactor, quickRefactorSystemPrompt}},
|
Column{useOpenFilesInQuickRefactor, quickRefactorSystemPrompt}},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
||||||
@ -360,7 +366,6 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
|||||||
resetAspect(autoCompletion);
|
resetAspect(autoCompletion);
|
||||||
resetAspect(multiLineCompletion);
|
resetAspect(multiLineCompletion);
|
||||||
resetAspect(stream);
|
resetAspect(stream);
|
||||||
resetAspect(smartProcessInstuctText);
|
|
||||||
resetAspect(temperature);
|
resetAspect(temperature);
|
||||||
resetAspect(maxTokens);
|
resetAspect(maxTokens);
|
||||||
resetAspect(useTopP);
|
resetAspect(useTopP);
|
||||||
@ -389,6 +394,7 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
|||||||
resetAspect(useOpenFilesContext);
|
resetAspect(useOpenFilesContext);
|
||||||
resetAspect(useOpenFilesInQuickRefactor);
|
resetAspect(useOpenFilesInQuickRefactor);
|
||||||
resetAspect(quickRefactorSystemPrompt);
|
resetAspect(quickRefactorSystemPrompt);
|
||||||
|
resetAspect(modelOutputHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public:
|
|||||||
Utils::BoolAspect autoCompletion{this};
|
Utils::BoolAspect autoCompletion{this};
|
||||||
Utils::BoolAspect multiLineCompletion{this};
|
Utils::BoolAspect multiLineCompletion{this};
|
||||||
Utils::BoolAspect stream{this};
|
Utils::BoolAspect stream{this};
|
||||||
Utils::BoolAspect smartProcessInstuctText{this};
|
Utils::SelectionAspect modelOutputHandler{this};
|
||||||
|
|
||||||
Utils::IntegerAspect startSuggestionTimer{this};
|
Utils::IntegerAspect startSuggestionTimer{this};
|
||||||
Utils::IntegerAspect autoCompletionCharThreshold{this};
|
Utils::IntegerAspect autoCompletionCharThreshold{this};
|
||||||
|
|||||||
@ -76,7 +76,7 @@ const char СС_AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTy
|
|||||||
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
|
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
|
||||||
const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion";
|
const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion";
|
||||||
const char CC_STREAM[] = "QodeAssist.ccStream";
|
const char CC_STREAM[] = "QodeAssist.ccStream";
|
||||||
const char CC_SMART_PROCESS_INSTRUCT_TEXT[] = "QodeAssist.ccSmartProcessInstructText";
|
const char CC_MODEL_OUTPUT_HANDLER[] = "QodeAssist.ccModelOutputHandler";
|
||||||
const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate";
|
const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate";
|
||||||
const char CA_TOKENS_THRESHOLD[] = "QodeAssist.caTokensThreshold";
|
const char CA_TOKENS_THRESHOLD[] = "QodeAssist.caTokensThreshold";
|
||||||
const char CA_LINK_OPEN_FILES[] = "QodeAssist.caLinkOpenFiles";
|
const char CA_LINK_OPEN_FILES[] = "QodeAssist.caLinkOpenFiles";
|
||||||
|
|||||||
@ -278,7 +278,7 @@ if __name__ == "__main__":
|
|||||||
"/path/to/file.py",
|
"/path/to/file.py",
|
||||||
"text/python");
|
"text/python");
|
||||||
|
|
||||||
m_completeSettings.smartProcessInstuctText.setValue(true);
|
m_completeSettings.modelOutputHandler.setValue(0);
|
||||||
|
|
||||||
m_requestHandler->setFakeCompletion(
|
m_requestHandler->setFakeCompletion(
|
||||||
"Here's the code: ```cpp\nint main() {\n return 0;\n}\n```");
|
"Here's the code: ```cpp\nint main() {\n return 0;\n}\n```");
|
||||||
|
|||||||
Reference in New Issue
Block a user