Optimize string

This commit is contained in:
Petr Mironychev
2024-09-05 22:18:57 +02:00
parent 99136d7b76
commit 44add994b9
3 changed files with 10 additions and 12 deletions

View File

@ -244,14 +244,14 @@ void LLMClientInterface::handleLLMResponse(QNetworkReply *reply, const QJsonObje
}
void LLMClientInterface::handleCompletion(const QJsonObject &request,
const QString &accumulatedCompletion)
const QStringView &accumulatedCompletion)
{
auto updatedContext = prepareContext(request, accumulatedCompletion);
sendLLMRequest(request, updatedContext);
}
ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
const QString &accumulatedCompletion)
const QStringView &accumulatedCompletion)
{
QJsonObject params = request["params"].toObject();
QJsonObject doc = params["doc"].toObject();
@ -264,7 +264,7 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
if (!textDocument) {
logMessage("Error: Document is not available for" + filePath.toString());
return {"", ""};
return ContextData{};
}
int cursorPosition = position["character"].toInt();
@ -284,9 +284,7 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
? reader.getLanguageAndFileInfo()
: QString());
QString updatedContextBefore = contextBefore + accumulatedCompletion;
return {updatedContextBefore, contextAfter, instructions};
return {QString("%1%2").arg(contextBefore, accumulatedCompletion), contextAfter, instructions};
}
void LLMClientInterface::updateProvider()
@ -378,9 +376,9 @@ void LLMClientInterface::sendLLMRequest(const QJsonObject &request, const Contex
});
}
QString LLMClientInterface::removeStopWords(const QString &completion)
QString LLMClientInterface::removeStopWords(const QStringView &completion)
{
QString filteredCompletion = completion;
QString filteredCompletion = completion.toString();
auto currentTemplate = PromptTemplateManager::instance().getCurrentTemplate();
QStringList stopWords = currentTemplate->stopWords();