From 44add994b9a076919fe71cc867b52a13213793db Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:18:57 +0200 Subject: [PATCH] Optimize string --- LLMClientInterface.cpp | 14 ++++++-------- LLMClientInterface.hpp | 6 +++--- QodeAssist.json.in | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index 9bfbc62..f7d314d 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -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(); diff --git a/LLMClientInterface.hpp b/LLMClientInterface.hpp index 04ce29a..3de65d5 100644 --- a/LLMClientInterface.hpp +++ b/LLMClientInterface.hpp @@ -45,12 +45,12 @@ public: bool isComplete); void handleCompletion(const QJsonObject &request, - const QString &accumulatedCompletion = QString()); + const QStringView &accumulatedCompletion = QString()); void sendLLMRequest(const QJsonObject &request, const ContextData &prompt); void handleLLMResponse(QNetworkReply *reply, const QJsonObject &request); ContextData prepareContext(const QJsonObject &request, - const QString &accumulatedCompletion = QString{}); + const QStringView &accumulatedCompletion = QString{}); void updateProvider(); protected: @@ -71,7 +71,7 @@ private: QString сontextBefore(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition); QString сontextAfter(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition); - QString removeStopWords(const QString &completion); + QString removeStopWords(const QStringView &completion); QUrl m_serverUrl; QNetworkAccessManager *m_manager; diff --git a/QodeAssist.json.in b/QodeAssist.json.in index 9b060ef..d8b1f23 100644 --- a/QodeAssist.json.in +++ b/QodeAssist.json.in @@ -1,6 +1,6 @@ { "Name" : "QodeAssist", - "Version" : "0.0.8", + "Version" : "0.1.0", "CompatVersion" : "${IDE_VERSION_COMPAT}", "Vendor" : "Petr Mironychev", "Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} Petr Mironychev, (C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",