mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
Add sharing current file with model
This commit is contained in:
parent
bc93bce03b
commit
61f1f0ae4f
@ -88,8 +88,8 @@ void ConfigurationManager::selectModel()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const auto providerUrl = (settingsButton == &m_generalSettings.ccSelectModel)
|
const auto providerUrl = (settingsButton == &m_generalSettings.ccSelectModel)
|
||||||
? m_generalSettings.ccUrl.volatileValue()
|
? m_generalSettings.ccUrl()
|
||||||
: m_generalSettings.caUrl.volatileValue();
|
: m_generalSettings.caUrl();
|
||||||
const auto modelList = m_providersManager.getProviderByName(providerName)
|
const auto modelList = m_providersManager.getProviderByName(providerName)
|
||||||
->getInstalledModels(providerUrl);
|
->getInstalledModels(providerUrl);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
#include "ChatAssistantSettings.hpp"
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
@ -37,6 +38,12 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
&Utils::BaseAspect::changed,
|
&Utils::BaseAspect::changed,
|
||||||
this,
|
this,
|
||||||
&ChatRootView::currentTemplateChanged);
|
&ChatRootView::currentTemplateChanged);
|
||||||
|
|
||||||
|
connect(&Settings::chatAssistantSettings().sharingCurrentFile,
|
||||||
|
&Utils::BaseAspect::changed,
|
||||||
|
this,
|
||||||
|
&ChatRootView::isSharingCurrentFileChanged);
|
||||||
|
|
||||||
generateColors();
|
generateColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,9 +57,9 @@ QColor ChatRootView::backgroundColor() const
|
|||||||
return Utils::creatorColor(Utils::Theme::BackgroundColorNormal);
|
return Utils::creatorColor(Utils::Theme::BackgroundColorNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::sendMessage(const QString &message) const
|
void ChatRootView::sendMessage(const QString &message, bool sharingCurrentFile) const
|
||||||
{
|
{
|
||||||
m_clientInterface->sendMessage(message);
|
m_clientInterface->sendMessage(message, sharingCurrentFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::copyToClipboard(const QString &text)
|
void ChatRootView::copyToClipboard(const QString &text)
|
||||||
@ -129,4 +136,9 @@ QColor ChatRootView::codeColor() const
|
|||||||
return m_codeColor;
|
return m_codeColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatRootView::isSharingCurrentFile() const
|
||||||
|
{
|
||||||
|
return Settings::chatAssistantSettings().sharingCurrentFile();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -35,6 +35,8 @@ class ChatRootView : public QQuickItem
|
|||||||
Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL)
|
Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL)
|
||||||
Q_PROPERTY(QColor secondaryColor READ secondaryColor CONSTANT FINAL)
|
Q_PROPERTY(QColor secondaryColor READ secondaryColor CONSTANT FINAL)
|
||||||
Q_PROPERTY(QColor codeColor READ codeColor CONSTANT FINAL)
|
Q_PROPERTY(QColor codeColor READ codeColor CONSTANT FINAL)
|
||||||
|
Q_PROPERTY(bool isSharingCurrentFile READ isSharingCurrentFile NOTIFY
|
||||||
|
isSharingCurrentFileChanged FINAL)
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -49,8 +51,10 @@ public:
|
|||||||
|
|
||||||
QColor codeColor() const;
|
QColor codeColor() const;
|
||||||
|
|
||||||
|
bool isSharingCurrentFile() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendMessage(const QString &message) const;
|
void sendMessage(const QString &message, bool sharingCurrentFile = false) const;
|
||||||
void copyToClipboard(const QString &text);
|
void copyToClipboard(const QString &text);
|
||||||
void cancelRequest();
|
void cancelRequest();
|
||||||
|
|
||||||
@ -58,6 +62,8 @@ signals:
|
|||||||
void chatModelChanged();
|
void chatModelChanged();
|
||||||
void currentTemplateChanged();
|
void currentTemplateChanged();
|
||||||
|
|
||||||
|
void isSharingCurrentFileChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateColors();
|
void generateColors();
|
||||||
QColor generateColor(const QColor &baseColor,
|
QColor generateColor(const QColor &baseColor,
|
||||||
|
@ -19,9 +19,18 @@
|
|||||||
|
|
||||||
#include "ClientInterface.hpp"
|
#include "ClientInterface.hpp"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
#include <coreplugin/idocument.h>
|
||||||
|
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include "ChatAssistantSettings.hpp"
|
#include "ChatAssistantSettings.hpp"
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
@ -55,7 +64,7 @@ ClientInterface::ClientInterface(ChatModel *chatModel, QObject *parent)
|
|||||||
|
|
||||||
ClientInterface::~ClientInterface() = default;
|
ClientInterface::~ClientInterface() = default;
|
||||||
|
|
||||||
void ClientInterface::sendMessage(const QString &message)
|
void ClientInterface::sendMessage(const QString &message, bool includeCurrentFile)
|
||||||
{
|
{
|
||||||
cancelRequest();
|
cancelRequest();
|
||||||
|
|
||||||
@ -71,8 +80,20 @@ void ClientInterface::sendMessage(const QString &message)
|
|||||||
LLMCore::ContextData context;
|
LLMCore::ContextData context;
|
||||||
context.prefix = message;
|
context.prefix = message;
|
||||||
context.suffix = "";
|
context.suffix = "";
|
||||||
if (chatAssistantSettings.useSystemPrompt())
|
|
||||||
context.systemPrompt = chatAssistantSettings.systemPrompt();
|
QString systemPrompt = chatAssistantSettings.systemPrompt();
|
||||||
|
if (includeCurrentFile) {
|
||||||
|
QString fileContext = getCurrentFileContext();
|
||||||
|
if (!fileContext.isEmpty()) {
|
||||||
|
context.systemPrompt = QString("%1\n\n%2").arg(systemPrompt, fileContext);
|
||||||
|
LOG_MESSAGE("Using system prompt with file context");
|
||||||
|
} else {
|
||||||
|
context.systemPrompt = systemPrompt;
|
||||||
|
LOG_MESSAGE("Failed to get file context, using default system prompt");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.systemPrompt = systemPrompt;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject providerRequest;
|
QJsonObject providerRequest;
|
||||||
providerRequest["model"] = Settings::generalSettings().caModel();
|
providerRequest["model"] = Settings::generalSettings().caModel();
|
||||||
@ -128,4 +149,28 @@ void ClientInterface::handleLLMResponse(const QString &response,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ClientInterface::getCurrentFileContext() const
|
||||||
|
{
|
||||||
|
auto currentEditor = Core::EditorManager::currentEditor();
|
||||||
|
if (!currentEditor) {
|
||||||
|
LOG_MESSAGE("No active editor found");
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto textDocument = qobject_cast<TextEditor::TextDocument *>(currentEditor->document());
|
||||||
|
if (!textDocument) {
|
||||||
|
LOG_MESSAGE("Current document is not a text document");
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString fileInfo = QString("Language: %1\nFile: %2\n\n")
|
||||||
|
.arg(textDocument->mimeType(), textDocument->filePath().toString());
|
||||||
|
|
||||||
|
QString content = textDocument->document()->toPlainText();
|
||||||
|
|
||||||
|
LOG_MESSAGE(QString("Got context from file: %1").arg(textDocument->filePath().toString()));
|
||||||
|
|
||||||
|
return QString("Current file context:\n%1\nFile content:\n%2").arg(fileInfo, content);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
explicit ClientInterface(ChatModel *chatModel, QObject *parent = nullptr);
|
explicit ClientInterface(ChatModel *chatModel, QObject *parent = nullptr);
|
||||||
~ClientInterface();
|
~ClientInterface();
|
||||||
|
|
||||||
void sendMessage(const QString &message);
|
void sendMessage(const QString &message, bool includeCurrentFile = false);
|
||||||
void clearMessages();
|
void clearMessages();
|
||||||
void cancelRequest();
|
void cancelRequest();
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
||||||
|
QString getCurrentFileContext() const;
|
||||||
|
|
||||||
LLMCore::RequestHandler *m_requestHandler;
|
LLMCore::RequestHandler *m_requestHandler;
|
||||||
ChatModel *m_chatModel;
|
ChatModel *m_chatModel;
|
||||||
|
@ -137,6 +137,13 @@ ChatRootView {
|
|||||||
text: qsTr("Clear Chat")
|
text: qsTr("Clear Chat")
|
||||||
onClicked: clearChat()
|
onClicked: clearChat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
id: sharingCurrentFile
|
||||||
|
|
||||||
|
text: "Share current file with models"
|
||||||
|
checked: root.isSharingCurrentFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +176,7 @@ ChatRootView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendChatMessage() {
|
function sendChatMessage() {
|
||||||
root.sendMessage(messageInput.text);
|
root.sendMessage(messageInput.text, sharingCurrentFile.checked)
|
||||||
messageInput.text = ""
|
messageInput.text = ""
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
chatTokensThreshold.setRange(1000, 16000);
|
chatTokensThreshold.setRange(1000, 16000);
|
||||||
chatTokensThreshold.setDefaultValue(8000);
|
chatTokensThreshold.setDefaultValue(8000);
|
||||||
|
|
||||||
|
sharingCurrentFile.setSettingsKey(Constants::CA_SHARING_CURRENT_FILE);
|
||||||
|
sharingCurrentFile.setLabelText(Tr::tr("Share Current File With Assistant by Default"));
|
||||||
|
sharingCurrentFile.setDefaultValue(true);
|
||||||
|
|
||||||
// General Parameters Settings
|
// General Parameters Settings
|
||||||
temperature.setSettingsKey(Constants::CA_TEMPERATURE);
|
temperature.setSettingsKey(Constants::CA_TEMPERATURE);
|
||||||
temperature.setLabelText(Tr::tr("Temperature:"));
|
temperature.setLabelText(Tr::tr("Temperature:"));
|
||||||
@ -156,7 +160,8 @@ ChatAssistantSettings::ChatAssistantSettings()
|
|||||||
|
|
||||||
return Column{Row{Stretch{1}, resetToDefaults},
|
return Column{Row{Stretch{1}, resetToDefaults},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{title(Tr::tr("Chat Settings")), Row{chatTokensThreshold, Stretch{1}}},
|
Group{title(Tr::tr("Chat Settings")),
|
||||||
|
Column{Row{chatTokensThreshold, Stretch{1}}, sharingCurrentFile}},
|
||||||
Space{8},
|
Space{8},
|
||||||
Group{
|
Group{
|
||||||
title(Tr::tr("General Parameters")),
|
title(Tr::tr("General Parameters")),
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
|
|
||||||
// Chat settings
|
// Chat settings
|
||||||
Utils::IntegerAspect chatTokensThreshold{this};
|
Utils::IntegerAspect chatTokensThreshold{this};
|
||||||
|
Utils::BoolAspect sharingCurrentFile{this};
|
||||||
|
|
||||||
// General Parameters Settings
|
// General Parameters Settings
|
||||||
Utils::DoubleAspect temperature{this};
|
Utils::DoubleAspect temperature{this};
|
||||||
|
@ -51,6 +51,7 @@ const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
|
|||||||
const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion";
|
const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion";
|
||||||
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_SHARING_CURRENT_FILE[] = "QodeAssist.caSharingCurrentFile";
|
||||||
|
|
||||||
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
||||||
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
||||||
|
Loading…
Reference in New Issue
Block a user