From ef3f2486d56d1c0b65bf7a21d80cb5561790d318 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:45:39 +0100 Subject: [PATCH] Fix embeddings --- chatview/ChatRootView.cpp | 6 +----- llmcore/EmbeddingsGenerator.h | 6 +++--- llmcore/EmbeddingsManager.cpp | 8 +------- llmcore/EmbeddingsManager.h | 4 ++-- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/chatview/ChatRootView.cpp b/chatview/ChatRootView.cpp index f4911b3..3a4d51f 100644 --- a/chatview/ChatRootView.cpp +++ b/chatview/ChatRootView.cpp @@ -91,10 +91,8 @@ void ChatRootView::sendEmbeddings(const QString &query) { auto &manager = LLMCore::EmbeddingManager::instance(); - // Отключаем предыдущие соединения disconnect(&manager, nullptr, this, nullptr); - // Подключаем обработчики результатов connect(&manager, &LLMCore::EmbeddingManager::searchCompleted, this, @@ -105,13 +103,11 @@ void ChatRootView::sendEmbeddings(const QString &query) }); connect(&manager, &LLMCore::EmbeddingManager::searchError, this, [this](const QString &error) { - // Обработка ошибки поиска qDebug() << "Search error:" << error; }); - // Запускаем поиск auto project = ProjectExplorer::ProjectManager::startupProject(); - manager.findSimilarCode(query, project); + manager.findSimilarCode(query, project, 0.55f, 5); } void ChatRootView::generateColors() diff --git a/llmcore/EmbeddingsGenerator.h b/llmcore/EmbeddingsGenerator.h index 9f40c5d..f8ceec6 100644 --- a/llmcore/EmbeddingsGenerator.h +++ b/llmcore/EmbeddingsGenerator.h @@ -52,9 +52,9 @@ class EmbeddingsGenerator : public QObject QJsonObject prepareRequest(const QString &content) const; QJsonObject prepareMessageRequest(const QString &message) const; - static constexpr const char *MODEL_NAME - = "starcoder2:15b-instruct"; //"starcoder2:15b"; //"all-minilm"; //"starcoder2:7b"; - static constexpr const char *BASE_URL = "http://192.168.50.189:11434"; //"http://localhost:11434"; + static constexpr const char *MODEL_NAME = "starcoder2:7b"; + //"starcoder2:15b-instruct"; //"starcoder2:15b"; //"all-minilm"; //"starcoder2:7b"; + static constexpr const char *BASE_URL = "http://localhost:11434"; static constexpr const char *ENDPOINT = "/api/embeddings"; static constexpr const char *QUERY_TEMPLATE = "Convert this question into code context: %1"; diff --git a/llmcore/EmbeddingsManager.cpp b/llmcore/EmbeddingsManager.cpp index 69cf1df..f1c8016 100644 --- a/llmcore/EmbeddingsManager.cpp +++ b/llmcore/EmbeddingsManager.cpp @@ -128,13 +128,7 @@ void EmbeddingManager::findSimilarCode(const QString &query, for (const auto &result : results) { searchResults.append(result); - formattedResponse - += QString("filepath:%1 startLine:%2 endLine:%3 similarity:%4 content:%5") - .arg(result.filePath) - .arg(result.startLine) - .arg(result.endLine) - .arg(result.similarity, 0, 'f', 4) - .arg(result.content); + formattedResponse += result.content; } LOG_MESSAGE(QString("Found %1 similar code fragments").arg(results.size())); diff --git a/llmcore/EmbeddingsManager.h b/llmcore/EmbeddingsManager.h index 8f17a3b..e086243 100644 --- a/llmcore/EmbeddingsManager.h +++ b/llmcore/EmbeddingsManager.h @@ -44,8 +44,8 @@ class EmbeddingManager : public QObject QString getEmbeddingsPath(ProjectExplorer::Project *project) const; void findSimilarCode(const QString &query, ProjectExplorer::Project *project, - float minSimilarity = 0.65f, - int maxResults = 5); + float minSimilarity, + int maxResults); signals: void searchCompleted(const QString &query,