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();

View File

@ -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;

View File

@ -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",