mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-04-02 02:42:45 -04:00
feat: Rename old llmcore module to pluginllmcore
This commit is contained in:
@ -37,32 +37,32 @@ void ClaudeMessage::handleContentBlockStart(
|
||||
.arg(blockType));
|
||||
|
||||
if (blockType == "text") {
|
||||
addCurrentContent<LLMCore::TextContent>();
|
||||
addCurrentContent<PluginLLMCore::TextContent>();
|
||||
|
||||
} else if (blockType == "image") {
|
||||
QJsonObject source = data["source"].toObject();
|
||||
QString sourceType = source["type"].toString();
|
||||
QString imageData;
|
||||
QString mediaType;
|
||||
LLMCore::ImageContent::ImageSourceType imgSourceType = LLMCore::ImageContent::ImageSourceType::Base64;
|
||||
PluginLLMCore::ImageContent::ImageSourceType imgSourceType = PluginLLMCore::ImageContent::ImageSourceType::Base64;
|
||||
|
||||
if (sourceType == "base64") {
|
||||
imageData = source["data"].toString();
|
||||
mediaType = source["media_type"].toString();
|
||||
imgSourceType = LLMCore::ImageContent::ImageSourceType::Base64;
|
||||
imgSourceType = PluginLLMCore::ImageContent::ImageSourceType::Base64;
|
||||
} else if (sourceType == "url") {
|
||||
imageData = source["url"].toString();
|
||||
imgSourceType = LLMCore::ImageContent::ImageSourceType::Url;
|
||||
imgSourceType = PluginLLMCore::ImageContent::ImageSourceType::Url;
|
||||
}
|
||||
|
||||
addCurrentContent<LLMCore::ImageContent>(imageData, mediaType, imgSourceType);
|
||||
addCurrentContent<PluginLLMCore::ImageContent>(imageData, mediaType, imgSourceType);
|
||||
|
||||
} else if (blockType == "tool_use") {
|
||||
QString toolId = data["id"].toString();
|
||||
QString toolName = data["name"].toString();
|
||||
QJsonObject toolInput = data["input"].toObject();
|
||||
|
||||
addCurrentContent<LLMCore::ToolUseContent>(toolId, toolName, toolInput);
|
||||
addCurrentContent<PluginLLMCore::ToolUseContent>(toolId, toolName, toolInput);
|
||||
m_pendingToolInputs[index] = "";
|
||||
|
||||
} else if (blockType == "thinking") {
|
||||
@ -70,13 +70,13 @@ void ClaudeMessage::handleContentBlockStart(
|
||||
QString signature = data["signature"].toString();
|
||||
LOG_MESSAGE(QString("ClaudeMessage: Creating thinking block with signature length=%1")
|
||||
.arg(signature.length()));
|
||||
addCurrentContent<LLMCore::ThinkingContent>(thinking, signature);
|
||||
addCurrentContent<PluginLLMCore::ThinkingContent>(thinking, signature);
|
||||
|
||||
} else if (blockType == "redacted_thinking") {
|
||||
QString signature = data["signature"].toString();
|
||||
LOG_MESSAGE(QString("ClaudeMessage: Creating redacted_thinking block with signature length=%1")
|
||||
.arg(signature.length()));
|
||||
addCurrentContent<LLMCore::RedactedThinkingContent>(signature);
|
||||
addCurrentContent<PluginLLMCore::RedactedThinkingContent>(signature);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ void ClaudeMessage::handleContentBlockDelta(
|
||||
}
|
||||
|
||||
if (deltaType == "text_delta") {
|
||||
if (auto textContent = qobject_cast<LLMCore::TextContent *>(m_currentBlocks[index])) {
|
||||
if (auto textContent = qobject_cast<PluginLLMCore::TextContent *>(m_currentBlocks[index])) {
|
||||
textContent->appendText(delta["text"].toString());
|
||||
}
|
||||
|
||||
@ -99,17 +99,17 @@ void ClaudeMessage::handleContentBlockDelta(
|
||||
}
|
||||
|
||||
} else if (deltaType == "thinking_delta") {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(m_currentBlocks[index])) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(m_currentBlocks[index])) {
|
||||
thinkingContent->appendThinking(delta["thinking"].toString());
|
||||
}
|
||||
|
||||
} else if (deltaType == "signature_delta") {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(m_currentBlocks[index])) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(m_currentBlocks[index])) {
|
||||
QString signature = delta["signature"].toString();
|
||||
thinkingContent->setSignature(signature);
|
||||
LOG_MESSAGE(QString("Set signature for thinking block %1: length=%2")
|
||||
.arg(index).arg(signature.length()));
|
||||
} else if (auto redactedContent = qobject_cast<LLMCore::RedactedThinkingContent *>(m_currentBlocks[index])) {
|
||||
} else if (auto redactedContent = qobject_cast<PluginLLMCore::RedactedThinkingContent *>(m_currentBlocks[index])) {
|
||||
QString signature = delta["signature"].toString();
|
||||
redactedContent->setSignature(signature);
|
||||
LOG_MESSAGE(QString("Set signature for redacted_thinking block %1: length=%2")
|
||||
@ -132,7 +132,7 @@ void ClaudeMessage::handleContentBlockStop(int index)
|
||||
}
|
||||
|
||||
if (index < m_currentBlocks.size()) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(m_currentBlocks[index])) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(m_currentBlocks[index])) {
|
||||
toolContent->setInput(inputObject);
|
||||
}
|
||||
}
|
||||
@ -155,7 +155,7 @@ QJsonObject ClaudeMessage::toProviderFormat() const
|
||||
QJsonArray content;
|
||||
|
||||
for (auto block : m_currentBlocks) {
|
||||
QJsonValue blockJson = block->toJson(LLMCore::ProviderFormat::Claude);
|
||||
QJsonValue blockJson = block->toJson(PluginLLMCore::ProviderFormat::Claude);
|
||||
content.append(blockJson);
|
||||
}
|
||||
|
||||
@ -173,42 +173,42 @@ QJsonArray ClaudeMessage::createToolResultsContent(const QHash<QString, QString>
|
||||
|
||||
for (auto toolContent : getCurrentToolUseContent()) {
|
||||
if (toolResults.contains(toolContent->id())) {
|
||||
auto toolResult = std::make_unique<LLMCore::ToolResultContent>(
|
||||
auto toolResult = std::make_unique<PluginLLMCore::ToolResultContent>(
|
||||
toolContent->id(), toolResults[toolContent->id()]);
|
||||
results.append(toolResult->toJson(LLMCore::ProviderFormat::Claude));
|
||||
results.append(toolResult->toJson(PluginLLMCore::ProviderFormat::Claude));
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
QList<LLMCore::ToolUseContent *> ClaudeMessage::getCurrentToolUseContent() const
|
||||
QList<PluginLLMCore::ToolUseContent *> ClaudeMessage::getCurrentToolUseContent() const
|
||||
{
|
||||
QList<LLMCore::ToolUseContent *> toolBlocks;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolBlocks.append(toolContent);
|
||||
}
|
||||
}
|
||||
return toolBlocks;
|
||||
}
|
||||
|
||||
QList<LLMCore::ThinkingContent *> ClaudeMessage::getCurrentThinkingContent() const
|
||||
QList<PluginLLMCore::ThinkingContent *> ClaudeMessage::getCurrentThinkingContent() const
|
||||
{
|
||||
QList<LLMCore::ThinkingContent *> thinkingBlocks;
|
||||
QList<PluginLLMCore::ThinkingContent *> thinkingBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
thinkingBlocks.append(thinkingContent);
|
||||
}
|
||||
}
|
||||
return thinkingBlocks;
|
||||
}
|
||||
|
||||
QList<LLMCore::RedactedThinkingContent *> ClaudeMessage::getCurrentRedactedThinkingContent() const
|
||||
QList<PluginLLMCore::RedactedThinkingContent *> ClaudeMessage::getCurrentRedactedThinkingContent() const
|
||||
{
|
||||
QList<LLMCore::RedactedThinkingContent *> redactedBlocks;
|
||||
QList<PluginLLMCore::RedactedThinkingContent *> redactedBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto redactedContent = qobject_cast<LLMCore::RedactedThinkingContent *>(block)) {
|
||||
if (auto redactedContent = qobject_cast<PluginLLMCore::RedactedThinkingContent *>(block)) {
|
||||
redactedBlocks.append(redactedContent);
|
||||
}
|
||||
}
|
||||
@ -222,17 +222,17 @@ void ClaudeMessage::startNewContinuation()
|
||||
m_currentBlocks.clear();
|
||||
m_pendingToolInputs.clear();
|
||||
m_stopReason.clear();
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
}
|
||||
|
||||
void ClaudeMessage::updateStateFromStopReason()
|
||||
{
|
||||
if (m_stopReason == "tool_use" && !getCurrentToolUseContent().empty()) {
|
||||
m_state = LLMCore::MessageState::RequiresToolExecution;
|
||||
m_state = PluginLLMCore::MessageState::RequiresToolExecution;
|
||||
} else if (m_stopReason == "end_turn") {
|
||||
m_state = LLMCore::MessageState::Final;
|
||||
m_state = PluginLLMCore::MessageState::Final;
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Complete;
|
||||
m_state = PluginLLMCore::MessageState::Complete;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/ContentBlocks.hpp>
|
||||
#include <pluginllmcore/ContentBlocks.hpp>
|
||||
|
||||
namespace QodeAssist {
|
||||
|
||||
@ -37,18 +37,18 @@ public:
|
||||
QJsonObject toProviderFormat() const;
|
||||
QJsonArray createToolResultsContent(const QHash<QString, QString> &toolResults) const;
|
||||
|
||||
LLMCore::MessageState state() const { return m_state; }
|
||||
QList<LLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<LLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<LLMCore::RedactedThinkingContent *> getCurrentRedactedThinkingContent() const;
|
||||
const QList<LLMCore::ContentBlock *> &getCurrentBlocks() const { return m_currentBlocks; }
|
||||
PluginLLMCore::MessageState state() const { return m_state; }
|
||||
QList<PluginLLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<PluginLLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<PluginLLMCore::RedactedThinkingContent *> getCurrentRedactedThinkingContent() const;
|
||||
const QList<PluginLLMCore::ContentBlock *> &getCurrentBlocks() const { return m_currentBlocks; }
|
||||
|
||||
void startNewContinuation();
|
||||
|
||||
private:
|
||||
QString m_stopReason;
|
||||
LLMCore::MessageState m_state = LLMCore::MessageState::Building;
|
||||
QList<LLMCore::ContentBlock *> m_currentBlocks;
|
||||
PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building;
|
||||
QList<PluginLLMCore::ContentBlock *> m_currentBlocks;
|
||||
QHash<int, QString> m_pendingToolInputs;
|
||||
|
||||
void updateStateFromStopReason();
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -35,7 +35,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
ClaudeProvider::ClaudeProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -72,9 +72,9 @@ bool ClaudeProvider::supportsModelListing() const
|
||||
|
||||
void ClaudeProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -102,10 +102,10 @@ void ClaudeProvider::prepareRequest(
|
||||
request["temperature"] = 1.0;
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
request["temperature"] = Settings::codeCompletionSettings().temperature();
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
const auto &qrSettings = Settings::quickRefactorSettings();
|
||||
applyModelParams(qrSettings);
|
||||
|
||||
@ -126,13 +126,13 @@ void ClaudeProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Claude, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::Claude, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to Claude request").arg(toolsDefinitions.size()));
|
||||
@ -175,7 +175,7 @@ QFuture<QList<QString>> ClaudeProvider::getInstalledModels(const QString &baseUr
|
||||
});
|
||||
}
|
||||
|
||||
QList<QString> ClaudeProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
|
||||
QList<QString> ClaudeProvider::validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto templateReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -191,7 +191,7 @@ QList<QString> ClaudeProvider::validateRequest(const QJsonObject &request, LLMCo
|
||||
{"tools", {}},
|
||||
{"thinking", QJsonObject{{"type", {}}, {"budget_tokens", {}}}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
}
|
||||
|
||||
QString ClaudeProvider::apiKey() const
|
||||
@ -209,13 +209,13 @@ void ClaudeProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) cons
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID ClaudeProvider::providerID() const
|
||||
PluginLLMCore::ProviderID ClaudeProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::Claude;
|
||||
return PluginLLMCore::ProviderID::Claude;
|
||||
}
|
||||
|
||||
void ClaudeProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -245,22 +245,22 @@ bool ClaudeProvider::supportImage() const {
|
||||
return true;
|
||||
};
|
||||
|
||||
void ClaudeProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void ClaudeProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("ClaudeProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
LLMCore::IToolsManager *ClaudeProvider::toolsManager() const
|
||||
PluginLLMCore::IToolsManager *ClaudeProvider::toolsManager() const
|
||||
{
|
||||
return m_toolsManager;
|
||||
}
|
||||
|
||||
void ClaudeProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -273,7 +273,7 @@ void ClaudeProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void ClaudeProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("ClaudeProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -284,7 +284,7 @@ void ClaudeProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
ClaudeMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -292,7 +292,7 @@ void ClaudeProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -403,7 +403,7 @@ void ClaudeProvider::processStreamEvent(const QString &requestId, const QJsonObj
|
||||
|
||||
if (deltaType == "text_delta") {
|
||||
QString text = delta["text"].toString();
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += text;
|
||||
emit partialResponseReceived(requestId, text);
|
||||
} else if (deltaType == "signature_delta") {
|
||||
@ -434,7 +434,7 @@ void ClaudeProvider::processStreamEvent(const QString &requestId, const QJsonObj
|
||||
if (!signature.isEmpty()) {
|
||||
auto allBlocks = message->getCurrentBlocks();
|
||||
if (index < allBlocks.size()) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(allBlocks[index])) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(allBlocks[index])) {
|
||||
thinkingContent->setSignature(signature);
|
||||
LOG_MESSAGE(
|
||||
QString("Updated thinking block signature from content_block_stop, "
|
||||
@ -448,7 +448,7 @@ void ClaudeProvider::processStreamEvent(const QString &requestId, const QJsonObj
|
||||
if (!signature.isEmpty()) {
|
||||
auto allBlocks = message->getCurrentBlocks();
|
||||
if (index < allBlocks.size()) {
|
||||
if (auto redactedContent = qobject_cast<LLMCore::RedactedThinkingContent *>(allBlocks[index])) {
|
||||
if (auto redactedContent = qobject_cast<PluginLLMCore::RedactedThinkingContent *>(allBlocks[index])) {
|
||||
redactedContent->setSignature(signature);
|
||||
LOG_MESSAGE(
|
||||
QString("Updated redacted_thinking block signature from content_block_stop, "
|
||||
@ -507,7 +507,7 @@ void ClaudeProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
ClaudeMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Claude message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -530,7 +530,7 @@ void ClaudeProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void ClaudeProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void ClaudeProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up Claude request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
#include "ClaudeMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class ClaudeProvider : public LLMCore::Provider
|
||||
class ClaudeProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -39,32 +39,32 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportThinking() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
LLMCore::IToolsManager *toolsManager() const override;
|
||||
PluginLLMCore::IToolsManager *toolsManager() const override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -74,11 +74,11 @@ private slots:
|
||||
private:
|
||||
void processStreamEvent(const QString &requestId, const QJsonObject &event);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<QodeAssist::LLMCore::RequestID, ClaudeMessage *> m_messages;
|
||||
QHash<QodeAssist::LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<QodeAssist::LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, ClaudeMessage *> m_messages;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QtCore/qurlquery.h>
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -35,7 +35,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
GoogleAIProvider::GoogleAIProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -72,9 +72,9 @@ bool GoogleAIProvider::supportsModelListing() const
|
||||
|
||||
void GoogleAIProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -119,9 +119,9 @@ void GoogleAIProvider::prepareRequest(
|
||||
request["generationConfig"] = generationConfig;
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
const auto &qrSettings = Settings::quickRefactorSettings();
|
||||
|
||||
if (isThinkingEnabled) {
|
||||
@ -140,13 +140,13 @@ void GoogleAIProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Google, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::Google, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to Google AI request").arg(toolsDefinitions.size()));
|
||||
@ -184,7 +184,7 @@ QFuture<QList<QString>> GoogleAIProvider::getInstalledModels(const QString &url)
|
||||
}
|
||||
|
||||
QList<QString> GoogleAIProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
QJsonObject templateReq;
|
||||
|
||||
@ -202,7 +202,7 @@ QList<QString> GoogleAIProvider::validateRequest(
|
||||
{"safetySettings", QJsonArray{}},
|
||||
{"tools", QJsonArray{}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
}
|
||||
|
||||
QString GoogleAIProvider::apiKey() const
|
||||
@ -221,13 +221,13 @@ void GoogleAIProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) co
|
||||
networkRequest.setUrl(url);
|
||||
}
|
||||
|
||||
LLMCore::ProviderID GoogleAIProvider::providerID() const
|
||||
PluginLLMCore::ProviderID GoogleAIProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::GoogleAI;
|
||||
return PluginLLMCore::ProviderID::GoogleAI;
|
||||
}
|
||||
|
||||
void GoogleAIProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -260,15 +260,15 @@ bool GoogleAIProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void GoogleAIProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void GoogleAIProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("GoogleAIProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void GoogleAIProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
@ -292,7 +292,7 @@ void GoogleAIProvider::onDataReceived(
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -309,7 +309,7 @@ void GoogleAIProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void GoogleAIProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("GoogleAIProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -330,7 +330,7 @@ void GoogleAIProvider::onRequestFinished(
|
||||
|
||||
handleMessageComplete(requestId);
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -338,7 +338,7 @@ void GoogleAIProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
} else {
|
||||
@ -407,7 +407,7 @@ void GoogleAIProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
m_emittedThinkingBlocksCount[requestId] = 0;
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -440,7 +440,7 @@ void GoogleAIProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
|
||||
message->handleContentDelta(text);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += text;
|
||||
emit partialResponseReceived(requestId, text);
|
||||
}
|
||||
@ -533,7 +533,7 @@ void GoogleAIProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
GoogleMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Google AI message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -555,7 +555,7 @@ void GoogleAIProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void GoogleAIProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void GoogleAIProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up Google AI request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -20,12 +20,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "GoogleMessage.hpp"
|
||||
#include "llmcore/Provider.hpp"
|
||||
#include "pluginllmcore/Provider.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class GoogleAIProvider : public LLMCore::Provider
|
||||
class GoogleAIProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,30 +38,30 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportThinking() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -72,13 +72,13 @@ private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void emitPendingThinkingBlocks(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, GoogleMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<LLMCore::RequestID, int> m_emittedThinkingBlocksCount;
|
||||
QSet<LLMCore::RequestID> m_failedRequests;
|
||||
QHash<PluginLLMCore::RequestID, GoogleMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, int> m_emittedThinkingBlocksCount;
|
||||
QSet<PluginLLMCore::RequestID> m_failedRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -32,26 +32,26 @@ GoogleMessage::GoogleMessage(QObject *parent)
|
||||
|
||||
void GoogleMessage::handleContentDelta(const QString &text)
|
||||
{
|
||||
if (m_currentBlocks.isEmpty() || !qobject_cast<LLMCore::TextContent *>(m_currentBlocks.last())) {
|
||||
auto textContent = new LLMCore::TextContent();
|
||||
if (m_currentBlocks.isEmpty() || !qobject_cast<PluginLLMCore::TextContent *>(m_currentBlocks.last())) {
|
||||
auto textContent = new PluginLLMCore::TextContent();
|
||||
textContent->setParent(this);
|
||||
m_currentBlocks.append(textContent);
|
||||
}
|
||||
|
||||
if (auto textContent = qobject_cast<LLMCore::TextContent *>(m_currentBlocks.last())) {
|
||||
if (auto textContent = qobject_cast<PluginLLMCore::TextContent *>(m_currentBlocks.last())) {
|
||||
textContent->appendText(text);
|
||||
}
|
||||
}
|
||||
|
||||
void GoogleMessage::handleThoughtDelta(const QString &text)
|
||||
{
|
||||
if (m_currentBlocks.isEmpty() || !qobject_cast<LLMCore::ThinkingContent *>(m_currentBlocks.last())) {
|
||||
auto thinkingContent = new LLMCore::ThinkingContent();
|
||||
if (m_currentBlocks.isEmpty() || !qobject_cast<PluginLLMCore::ThinkingContent *>(m_currentBlocks.last())) {
|
||||
auto thinkingContent = new PluginLLMCore::ThinkingContent();
|
||||
thinkingContent->setParent(this);
|
||||
m_currentBlocks.append(thinkingContent);
|
||||
}
|
||||
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(m_currentBlocks.last())) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(m_currentBlocks.last())) {
|
||||
thinkingContent->appendThinking(text);
|
||||
}
|
||||
}
|
||||
@ -59,13 +59,13 @@ void GoogleMessage::handleThoughtDelta(const QString &text)
|
||||
void GoogleMessage::handleThoughtSignature(const QString &signature)
|
||||
{
|
||||
for (int i = m_currentBlocks.size() - 1; i >= 0; --i) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(m_currentBlocks[i])) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(m_currentBlocks[i])) {
|
||||
thinkingContent->setSignature(signature);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto thinkingContent = new LLMCore::ThinkingContent();
|
||||
auto thinkingContent = new PluginLLMCore::ThinkingContent();
|
||||
thinkingContent->setParent(this);
|
||||
thinkingContent->setSignature(signature);
|
||||
m_currentBlocks.append(thinkingContent);
|
||||
@ -97,7 +97,7 @@ void GoogleMessage::handleFunctionCallComplete()
|
||||
}
|
||||
|
||||
QString id = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
auto toolContent = new LLMCore::ToolUseContent(id, m_currentFunctionName, args);
|
||||
auto toolContent = new PluginLLMCore::ToolUseContent(id, m_currentFunctionName, args);
|
||||
toolContent->setParent(this);
|
||||
m_currentBlocks.append(toolContent);
|
||||
|
||||
@ -122,14 +122,14 @@ QJsonObject GoogleMessage::toProviderFormat() const
|
||||
if (!block)
|
||||
continue;
|
||||
|
||||
if (auto text = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto text = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
parts.append(QJsonObject{{"text", text->text()}});
|
||||
} else if (auto tool = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
} else if (auto tool = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
QJsonObject functionCall;
|
||||
functionCall["name"] = tool->name();
|
||||
functionCall["args"] = tool->input();
|
||||
parts.append(QJsonObject{{"functionCall", functionCall}});
|
||||
} else if (auto thinking = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
} else if (auto thinking = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
// Include thinking blocks with their text
|
||||
QJsonObject thinkingPart;
|
||||
thinkingPart["text"] = thinking->thinking();
|
||||
@ -169,22 +169,22 @@ QJsonArray GoogleMessage::createToolResultParts(const QHash<QString, QString> &t
|
||||
return parts;
|
||||
}
|
||||
|
||||
QList<LLMCore::ToolUseContent *> GoogleMessage::getCurrentToolUseContent() const
|
||||
QList<PluginLLMCore::ToolUseContent *> GoogleMessage::getCurrentToolUseContent() const
|
||||
{
|
||||
QList<LLMCore::ToolUseContent *> toolBlocks;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolBlocks.append(toolContent);
|
||||
}
|
||||
}
|
||||
return toolBlocks;
|
||||
}
|
||||
|
||||
QList<LLMCore::ThinkingContent *> GoogleMessage::getCurrentThinkingContent() const
|
||||
QList<PluginLLMCore::ThinkingContent *> GoogleMessage::getCurrentThinkingContent() const
|
||||
{
|
||||
QList<LLMCore::ThinkingContent *> thinkingBlocks;
|
||||
QList<PluginLLMCore::ThinkingContent *> thinkingBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
thinkingBlocks.append(thinkingContent);
|
||||
}
|
||||
}
|
||||
@ -199,7 +199,7 @@ void GoogleMessage::startNewContinuation()
|
||||
m_pendingFunctionArgs.clear();
|
||||
m_currentFunctionName.clear();
|
||||
m_finishReason.clear();
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
}
|
||||
|
||||
bool GoogleMessage::isErrorFinishReason() const
|
||||
@ -234,10 +234,10 @@ void GoogleMessage::updateStateFromFinishReason()
|
||||
{
|
||||
if (m_finishReason == "STOP" || m_finishReason == "MAX_TOKENS") {
|
||||
m_state = getCurrentToolUseContent().isEmpty()
|
||||
? LLMCore::MessageState::Complete
|
||||
: LLMCore::MessageState::RequiresToolExecution;
|
||||
? PluginLLMCore::MessageState::Complete
|
||||
: PluginLLMCore::MessageState::RequiresToolExecution;
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Complete;
|
||||
m_state = PluginLLMCore::MessageState::Complete;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
|
||||
#include <llmcore/ContentBlocks.hpp>
|
||||
#include <pluginllmcore/ContentBlocks.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
@ -45,11 +45,11 @@ public:
|
||||
QJsonObject toProviderFormat() const;
|
||||
QJsonArray createToolResultParts(const QHash<QString, QString> &toolResults) const;
|
||||
|
||||
QList<LLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<LLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<LLMCore::ContentBlock *> currentBlocks() const { return m_currentBlocks; }
|
||||
QList<PluginLLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<PluginLLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<PluginLLMCore::ContentBlock *> currentBlocks() const { return m_currentBlocks; }
|
||||
|
||||
LLMCore::MessageState state() const { return m_state; }
|
||||
PluginLLMCore::MessageState state() const { return m_state; }
|
||||
QString finishReason() const { return m_finishReason; }
|
||||
bool isErrorFinishReason() const;
|
||||
QString getErrorMessage() const;
|
||||
@ -58,11 +58,11 @@ public:
|
||||
private:
|
||||
void updateStateFromFinishReason();
|
||||
|
||||
QList<LLMCore::ContentBlock *> m_currentBlocks;
|
||||
QList<PluginLLMCore::ContentBlock *> m_currentBlocks;
|
||||
QString m_pendingFunctionArgs;
|
||||
QString m_currentFunctionName;
|
||||
QString m_finishReason;
|
||||
LLMCore::MessageState m_state = LLMCore::MessageState::Building;
|
||||
PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "LMStudioProvider.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -34,7 +34,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
LMStudioProvider::LMStudioProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -90,7 +90,7 @@ QFuture<QList<QString>> LMStudioProvider::getInstalledModels(const QString &url)
|
||||
}
|
||||
|
||||
QList<QString> LMStudioProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto templateReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -105,7 +105,7 @@ QList<QString> LMStudioProvider::validateRequest(
|
||||
{"stream", {}},
|
||||
{"tools", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
}
|
||||
|
||||
QString LMStudioProvider::apiKey() const
|
||||
@ -118,13 +118,13 @@ void LMStudioProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) co
|
||||
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
}
|
||||
|
||||
LLMCore::ProviderID LMStudioProvider::providerID() const
|
||||
PluginLLMCore::ProviderID LMStudioProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::LMStudio;
|
||||
return PluginLLMCore::ProviderID::LMStudio;
|
||||
}
|
||||
|
||||
void LMStudioProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -152,17 +152,17 @@ bool LMStudioProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void LMStudioProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void LMStudioProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("LMStudioProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void LMStudioProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -179,7 +179,7 @@ void LMStudioProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void LMStudioProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("LMStudioProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -190,7 +190,7 @@ void LMStudioProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -198,7 +198,7 @@ void LMStudioProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -210,9 +210,9 @@ void LMStudioProvider::onRequestFinished(
|
||||
|
||||
void LMStudioProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -236,22 +236,22 @@ void LMStudioProvider::prepareRequest(
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
applyModelParams(Settings::quickRefactorSettings());
|
||||
} else {
|
||||
applyModelParams(Settings::chatAssistantSettings());
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to LMStudio request").arg(toolsDefinitions.size()));
|
||||
@ -326,7 +326,7 @@ void LMStudioProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -336,7 +336,7 @@ void LMStudioProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
QString content = delta["content"].toString();
|
||||
message->handleContentDelta(content);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -381,7 +381,7 @@ void LMStudioProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("LMStudio message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -403,7 +403,7 @@ void LMStudioProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void LMStudioProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void LMStudioProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up LMStudio request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class LMStudioProvider : public LLMCore::Provider
|
||||
class LMStudioProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,29 +38,29 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -70,11 +70,11 @@ private slots:
|
||||
private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "LlamaCppProvider.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -33,7 +33,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
LlamaCppProvider::LlamaCppProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -70,9 +70,9 @@ bool LlamaCppProvider::supportsModelListing() const
|
||||
|
||||
void LlamaCppProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -96,22 +96,22 @@ void LlamaCppProvider::prepareRequest(
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
applyModelParams(Settings::quickRefactorSettings());
|
||||
} else {
|
||||
applyModelParams(Settings::chatAssistantSettings());
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to llama.cpp request").arg(toolsDefinitions.size()));
|
||||
@ -125,9 +125,9 @@ QFuture<QList<QString>> LlamaCppProvider::getInstalledModels(const QString &)
|
||||
}
|
||||
|
||||
QList<QString> LlamaCppProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
if (type == LLMCore::TemplateType::FIM) {
|
||||
if (type == PluginLLMCore::TemplateType::FIM) {
|
||||
const auto infillReq = QJsonObject{
|
||||
{"model", {}},
|
||||
{"input_prefix", {}},
|
||||
@ -143,7 +143,7 @@ QList<QString> LlamaCppProvider::validateRequest(
|
||||
{"stop", QJsonArray{}},
|
||||
{"stream", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, infillReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, infillReq);
|
||||
} else {
|
||||
const auto chatReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -158,7 +158,7 @@ QList<QString> LlamaCppProvider::validateRequest(
|
||||
{"stream", {}},
|
||||
{"tools", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, chatReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, chatReq);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,13 +172,13 @@ void LlamaCppProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) co
|
||||
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
}
|
||||
|
||||
LLMCore::ProviderID LlamaCppProvider::providerID() const
|
||||
PluginLLMCore::ProviderID LlamaCppProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::LlamaCpp;
|
||||
return PluginLLMCore::ProviderID::LlamaCpp;
|
||||
}
|
||||
|
||||
void LlamaCppProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -206,17 +206,17 @@ bool LlamaCppProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void LlamaCppProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void LlamaCppProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("LlamaCppProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void LlamaCppProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -245,7 +245,7 @@ void LlamaCppProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void LlamaCppProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("LlamaCppProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -256,7 +256,7 @@ void LlamaCppProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -264,7 +264,7 @@ void LlamaCppProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -341,7 +341,7 @@ void LlamaCppProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -351,7 +351,7 @@ void LlamaCppProvider::processStreamChunk(const QString &requestId, const QJsonO
|
||||
QString content = delta["content"].toString();
|
||||
message->handleContentDelta(content);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -396,7 +396,7 @@ void LlamaCppProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("llama.cpp message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -418,7 +418,7 @@ void LlamaCppProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void LlamaCppProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void LlamaCppProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up llama.cpp request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class LlamaCppProvider : public LLMCore::Provider
|
||||
class LlamaCppProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,29 +38,29 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -70,11 +70,11 @@ private slots:
|
||||
private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "MistralAIProvider.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -34,7 +34,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
MistralAIProvider::MistralAIProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -98,7 +98,7 @@ QFuture<QList<QString>> MistralAIProvider::getInstalledModels(const QString &url
|
||||
}
|
||||
|
||||
QList<QString> MistralAIProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto fimReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -121,8 +121,8 @@ QList<QString> MistralAIProvider::validateRequest(
|
||||
{"stream", {}},
|
||||
{"tools", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(
|
||||
request, type == LLMCore::TemplateType::FIM ? fimReq : templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(
|
||||
request, type == PluginLLMCore::TemplateType::FIM ? fimReq : templateReq);
|
||||
}
|
||||
|
||||
QString MistralAIProvider::apiKey() const
|
||||
@ -139,13 +139,13 @@ void MistralAIProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) c
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID MistralAIProvider::providerID() const
|
||||
PluginLLMCore::ProviderID MistralAIProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::MistralAI;
|
||||
return PluginLLMCore::ProviderID::MistralAI;
|
||||
}
|
||||
|
||||
void MistralAIProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -173,17 +173,17 @@ bool MistralAIProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void MistralAIProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void MistralAIProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("MistralAIProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void MistralAIProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -200,7 +200,7 @@ void MistralAIProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void MistralAIProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("MistralAIProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -211,7 +211,7 @@ void MistralAIProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -219,7 +219,7 @@ void MistralAIProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -231,9 +231,9 @@ void MistralAIProvider::onRequestFinished(
|
||||
|
||||
void MistralAIProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -257,22 +257,22 @@ void MistralAIProvider::prepareRequest(
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
applyModelParams(Settings::quickRefactorSettings());
|
||||
} else {
|
||||
applyModelParams(Settings::chatAssistantSettings());
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to Mistral request").arg(toolsDefinitions.size()));
|
||||
@ -347,7 +347,7 @@ void MistralAIProvider::processStreamChunk(const QString &requestId, const QJson
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -357,7 +357,7 @@ void MistralAIProvider::processStreamChunk(const QString &requestId, const QJson
|
||||
QString content = delta["content"].toString();
|
||||
message->handleContentDelta(content);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -402,7 +402,7 @@ void MistralAIProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Mistral message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -424,7 +424,7 @@ void MistralAIProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void MistralAIProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void MistralAIProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up Mistral request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class MistralAIProvider : public LLMCore::Provider
|
||||
class MistralAIProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,29 +38,29 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -70,11 +70,11 @@ private slots:
|
||||
private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -39,13 +39,13 @@ void OllamaMessage::handleContentDelta(const QString &content)
|
||||
}
|
||||
|
||||
if (!m_contentAddedToTextBlock) {
|
||||
LLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
PluginLLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
textContent->setText(m_accumulatedContent);
|
||||
m_contentAddedToTextBlock = true;
|
||||
LOG_MESSAGE(QString("OllamaMessage: Added accumulated content to TextContent, length=%1")
|
||||
.arg(m_accumulatedContent.length()));
|
||||
} else {
|
||||
LLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
PluginLLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
textContent->appendText(content);
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ void OllamaMessage::handleToolCall(const QJsonObject &toolCall)
|
||||
m_accumulatedContent.clear();
|
||||
}
|
||||
|
||||
addCurrentContent<LLMCore::ToolUseContent>(toolId, name, arguments);
|
||||
addCurrentContent<PluginLLMCore::ToolUseContent>(toolId, name, arguments);
|
||||
|
||||
LOG_MESSAGE(
|
||||
QString("OllamaMessage: Structured tool call detected - name=%1, id=%2").arg(name, toolId));
|
||||
@ -73,7 +73,7 @@ void OllamaMessage::handleToolCall(const QJsonObject &toolCall)
|
||||
|
||||
void OllamaMessage::handleThinkingDelta(const QString &thinking)
|
||||
{
|
||||
LLMCore::ThinkingContent *thinkingContent = getOrCreateThinkingContent();
|
||||
PluginLLMCore::ThinkingContent *thinkingContent = getOrCreateThinkingContent();
|
||||
thinkingContent->appendThinking(thinking);
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ void OllamaMessage::handleDone(bool done)
|
||||
.arg(trimmed.length()));
|
||||
|
||||
for (auto it = m_currentBlocks.begin(); it != m_currentBlocks.end();) {
|
||||
if (qobject_cast<LLMCore::TextContent *>(*it)) {
|
||||
if (qobject_cast<PluginLLMCore::TextContent *>(*it)) {
|
||||
LOG_MESSAGE(QString(
|
||||
"OllamaMessage: Removing TextContent block (incomplete tool call)"));
|
||||
(*it)->deleteLater();
|
||||
@ -114,7 +114,7 @@ void OllamaMessage::handleDone(bool done)
|
||||
|
||||
m_accumulatedContent.clear();
|
||||
} else {
|
||||
LLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
PluginLLMCore::TextContent *textContent = getOrCreateTextContent();
|
||||
textContent->setText(m_accumulatedContent);
|
||||
m_contentAddedToTextBlock = true;
|
||||
LOG_MESSAGE(
|
||||
@ -184,13 +184,13 @@ bool OllamaMessage::tryParseToolCall()
|
||||
QString toolId = QString("call_%1_%2").arg(name).arg(QDateTime::currentMSecsSinceEpoch());
|
||||
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
LOG_MESSAGE(QString("OllamaMessage: Removing TextContent block (tool call detected)"));
|
||||
}
|
||||
}
|
||||
m_currentBlocks.clear();
|
||||
|
||||
addCurrentContent<LLMCore::ToolUseContent>(toolId, name, arguments);
|
||||
addCurrentContent<PluginLLMCore::ToolUseContent>(toolId, name, arguments);
|
||||
|
||||
LOG_MESSAGE(
|
||||
QString(
|
||||
@ -238,14 +238,14 @@ QJsonObject OllamaMessage::toProviderFormat() const
|
||||
if (!block)
|
||||
continue;
|
||||
|
||||
if (auto text = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto text = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
textContent += text->text();
|
||||
} else if (auto tool = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
} else if (auto tool = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
QJsonObject toolCall;
|
||||
toolCall["type"] = "function";
|
||||
toolCall["function"] = QJsonObject{{"name", tool->name()}, {"arguments", tool->input()}};
|
||||
toolCalls.append(toolCall);
|
||||
} else if (auto thinking = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
} else if (auto thinking = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
thinkingContent += thinking->thinking();
|
||||
}
|
||||
}
|
||||
@ -287,22 +287,22 @@ QJsonArray OllamaMessage::createToolResultMessages(const QHash<QString, QString>
|
||||
return messages;
|
||||
}
|
||||
|
||||
QList<LLMCore::ToolUseContent *> OllamaMessage::getCurrentToolUseContent() const
|
||||
QList<PluginLLMCore::ToolUseContent *> OllamaMessage::getCurrentToolUseContent() const
|
||||
{
|
||||
QList<LLMCore::ToolUseContent *> toolBlocks;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolBlocks.append(toolContent);
|
||||
}
|
||||
}
|
||||
return toolBlocks;
|
||||
}
|
||||
|
||||
QList<LLMCore::ThinkingContent *> OllamaMessage::getCurrentThinkingContent() const
|
||||
QList<PluginLLMCore::ThinkingContent *> OllamaMessage::getCurrentThinkingContent() const
|
||||
{
|
||||
QList<LLMCore::ThinkingContent *> thinkingBlocks;
|
||||
QList<PluginLLMCore::ThinkingContent *> thinkingBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
thinkingBlocks.append(thinkingContent);
|
||||
}
|
||||
}
|
||||
@ -316,7 +316,7 @@ void OllamaMessage::startNewContinuation()
|
||||
m_currentBlocks.clear();
|
||||
m_accumulatedContent.clear();
|
||||
m_done = false;
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
m_contentAddedToTextBlock = false;
|
||||
m_currentThinkingContent = nullptr;
|
||||
}
|
||||
@ -324,40 +324,40 @@ void OllamaMessage::startNewContinuation()
|
||||
void OllamaMessage::updateStateFromDone()
|
||||
{
|
||||
if (!getCurrentToolUseContent().empty()) {
|
||||
m_state = LLMCore::MessageState::RequiresToolExecution;
|
||||
m_state = PluginLLMCore::MessageState::RequiresToolExecution;
|
||||
LOG_MESSAGE(QString("OllamaMessage: State set to RequiresToolExecution, tools count=%1")
|
||||
.arg(getCurrentToolUseContent().size()));
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Final;
|
||||
m_state = PluginLLMCore::MessageState::Final;
|
||||
LOG_MESSAGE(QString("OllamaMessage: State set to Final"));
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::TextContent *OllamaMessage::getOrCreateTextContent()
|
||||
PluginLLMCore::TextContent *OllamaMessage::getOrCreateTextContent()
|
||||
{
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto textContent = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto textContent = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
return textContent;
|
||||
}
|
||||
}
|
||||
|
||||
return addCurrentContent<LLMCore::TextContent>();
|
||||
return addCurrentContent<PluginLLMCore::TextContent>();
|
||||
}
|
||||
|
||||
LLMCore::ThinkingContent *OllamaMessage::getOrCreateThinkingContent()
|
||||
PluginLLMCore::ThinkingContent *OllamaMessage::getOrCreateThinkingContent()
|
||||
{
|
||||
if (m_currentThinkingContent) {
|
||||
return m_currentThinkingContent;
|
||||
}
|
||||
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
if (auto thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
m_currentThinkingContent = thinkingContent;
|
||||
return m_currentThinkingContent;
|
||||
}
|
||||
}
|
||||
|
||||
m_currentThinkingContent = addCurrentContent<LLMCore::ThinkingContent>();
|
||||
m_currentThinkingContent = addCurrentContent<PluginLLMCore::ThinkingContent>();
|
||||
LOG_MESSAGE(QString("OllamaMessage: Created new ThinkingContent block"));
|
||||
return m_currentThinkingContent;
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/ContentBlocks.hpp>
|
||||
#include <pluginllmcore/ContentBlocks.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
@ -38,26 +38,26 @@ public:
|
||||
QJsonObject toProviderFormat() const;
|
||||
QJsonArray createToolResultMessages(const QHash<QString, QString> &toolResults) const;
|
||||
|
||||
LLMCore::MessageState state() const { return m_state; }
|
||||
QList<LLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<LLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<LLMCore::ContentBlock *> currentBlocks() const { return m_currentBlocks; }
|
||||
PluginLLMCore::MessageState state() const { return m_state; }
|
||||
QList<PluginLLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<PluginLLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<PluginLLMCore::ContentBlock *> currentBlocks() const { return m_currentBlocks; }
|
||||
|
||||
void startNewContinuation();
|
||||
|
||||
private:
|
||||
bool m_done = false;
|
||||
LLMCore::MessageState m_state = LLMCore::MessageState::Building;
|
||||
QList<LLMCore::ContentBlock *> m_currentBlocks;
|
||||
PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building;
|
||||
QList<PluginLLMCore::ContentBlock *> m_currentBlocks;
|
||||
QString m_accumulatedContent;
|
||||
bool m_contentAddedToTextBlock = false;
|
||||
LLMCore::ThinkingContent *m_currentThinkingContent = nullptr;
|
||||
PluginLLMCore::ThinkingContent *m_currentThinkingContent = nullptr;
|
||||
|
||||
void updateStateFromDone();
|
||||
bool tryParseToolCall();
|
||||
bool isLikelyToolCallJson(const QString &content) const;
|
||||
LLMCore::TextContent *getOrCreateTextContent();
|
||||
LLMCore::ThinkingContent *getOrCreateThinkingContent();
|
||||
PluginLLMCore::TextContent *getOrCreateTextContent();
|
||||
PluginLLMCore::ThinkingContent *getOrCreateThinkingContent();
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T *addCurrentContent(Args &&...args)
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -34,7 +34,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
OllamaProvider::OllamaProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -71,9 +71,9 @@ bool OllamaProvider::supportsModelListing() const
|
||||
|
||||
void OllamaProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -109,9 +109,9 @@ void OllamaProvider::prepareRequest(
|
||||
request["options"] = options;
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applySettings(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
const auto &qrSettings = Settings::quickRefactorSettings();
|
||||
applySettings(qrSettings);
|
||||
|
||||
@ -130,13 +130,13 @@ void OllamaProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->toolsFactory()->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Ollama, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::Ollama, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(
|
||||
@ -166,7 +166,7 @@ QFuture<QList<QString>> OllamaProvider::getInstalledModels(const QString &url)
|
||||
});
|
||||
}
|
||||
|
||||
QList<QString> OllamaProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
|
||||
QList<QString> OllamaProvider::validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto fimReq = QJsonObject{
|
||||
{"keep_alive", {}},
|
||||
@ -202,8 +202,8 @@ QList<QString> OllamaProvider::validateRequest(const QJsonObject &request, LLMCo
|
||||
{"frequency_penalty", {}},
|
||||
{"presence_penalty", {}}}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(
|
||||
request, type == LLMCore::TemplateType::FIM ? fimReq : messageReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(
|
||||
request, type == PluginLLMCore::TemplateType::FIM ? fimReq : messageReq);
|
||||
}
|
||||
|
||||
QString OllamaProvider::apiKey() const
|
||||
@ -220,13 +220,13 @@ void OllamaProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) cons
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID OllamaProvider::providerID() const
|
||||
PluginLLMCore::ProviderID OllamaProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::Ollama;
|
||||
return PluginLLMCore::ProviderID::Ollama;
|
||||
}
|
||||
|
||||
void OllamaProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
m_dataBuffers[requestId].clear();
|
||||
|
||||
@ -256,17 +256,17 @@ bool OllamaProvider::supportThinking() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void OllamaProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void OllamaProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("OllamaProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void OllamaProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
if (data.isEmpty()) {
|
||||
@ -297,7 +297,7 @@ void OllamaProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void OllamaProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("OllamaProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -308,7 +308,7 @@ void OllamaProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OllamaMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
return;
|
||||
}
|
||||
@ -319,7 +319,7 @@ void OllamaProvider::onRequestFinished(
|
||||
OllamaMessage *message = m_messages[requestId];
|
||||
|
||||
for (auto block : message->currentBlocks()) {
|
||||
if (auto textContent = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto textContent = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
finalText += textContent->text();
|
||||
}
|
||||
}
|
||||
@ -408,7 +408,7 @@ void OllamaProvider::processStreamData(const QString &requestId, const QJsonObje
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -455,14 +455,14 @@ void OllamaProvider::processStreamData(const QString &requestId, const QJsonObje
|
||||
|
||||
bool hasTextContent = false;
|
||||
for (auto block : message->currentBlocks()) {
|
||||
if (qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
hasTextContent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasTextContent) {
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -485,14 +485,14 @@ void OllamaProvider::processStreamData(const QString &requestId, const QJsonObje
|
||||
|
||||
bool hasTextContent = false;
|
||||
for (auto block : message->currentBlocks()) {
|
||||
if (qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
hasTextContent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasTextContent) {
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -521,7 +521,7 @@ void OllamaProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
emitThinkingBlocks(requestId, message);
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Ollama message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -554,7 +554,7 @@ void OllamaProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void OllamaProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void OllamaProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up Ollama request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -19,14 +19,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
#include "OllamaMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OllamaProvider : public LLMCore::Provider
|
||||
class OllamaProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -39,30 +39,30 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
bool supportThinking() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -72,12 +72,12 @@ private slots:
|
||||
private:
|
||||
void processStreamData(const QString &requestId, const QJsonObject &data);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
void emitThinkingBlocks(const QString &requestId, OllamaMessage *message);
|
||||
|
||||
QHash<QodeAssist::LLMCore::RequestID, OllamaMessage *> m_messages;
|
||||
QHash<QodeAssist::LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<QodeAssist::LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, OllamaMessage *> m_messages;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<QodeAssist::PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QSet<QString> m_thinkingEmitted;
|
||||
QSet<QString> m_thinkingStarted;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "OpenAICompatProvider.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -35,7 +35,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
OpenAICompatProvider::OpenAICompatProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -72,9 +72,9 @@ bool OpenAICompatProvider::supportsModelListing() const
|
||||
|
||||
void OpenAICompatProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -98,22 +98,22 @@ void OpenAICompatProvider::prepareRequest(
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
applyModelParams(Settings::quickRefactorSettings());
|
||||
} else {
|
||||
applyModelParams(Settings::chatAssistantSettings());
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(
|
||||
@ -128,7 +128,7 @@ QFuture<QList<QString>> OpenAICompatProvider::getInstalledModels(const QString &
|
||||
}
|
||||
|
||||
QList<QString> OpenAICompatProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto templateReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -143,7 +143,7 @@ QList<QString> OpenAICompatProvider::validateRequest(
|
||||
{"stream", {}},
|
||||
{"tools", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
}
|
||||
|
||||
QString OpenAICompatProvider::apiKey() const
|
||||
@ -160,13 +160,13 @@ void OpenAICompatProvider::prepareNetworkRequest(QNetworkRequest &networkRequest
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID OpenAICompatProvider::providerID() const
|
||||
PluginLLMCore::ProviderID OpenAICompatProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::OpenAICompatible;
|
||||
return PluginLLMCore::ProviderID::OpenAICompatible;
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -194,17 +194,17 @@ bool OpenAICompatProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAICompatProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("OpenAICompatProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -221,7 +221,7 @@ void OpenAICompatProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("OpenAICompatProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -232,7 +232,7 @@ void OpenAICompatProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -240,7 +240,7 @@ void OpenAICompatProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -317,7 +317,7 @@ void OpenAICompatProvider::processStreamChunk(const QString &requestId, const QJ
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -327,7 +327,7 @@ void OpenAICompatProvider::processStreamChunk(const QString &requestId, const QJ
|
||||
QString content = delta["content"].toString();
|
||||
message->handleContentDelta(content);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -372,7 +372,7 @@ void OpenAICompatProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("OpenAICompat message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -394,7 +394,7 @@ void OpenAICompatProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAICompatProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up OpenAICompat request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OpenAICompatProvider : public LLMCore::Provider
|
||||
class OpenAICompatProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,29 +38,29 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -70,11 +70,11 @@ private slots:
|
||||
private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ void OpenAIMessage::handleToolCallStart(int index, const QString &id, const QStr
|
||||
m_currentBlocks.append(nullptr);
|
||||
}
|
||||
|
||||
auto toolContent = new LLMCore::ToolUseContent(id, name);
|
||||
auto toolContent = new PluginLLMCore::ToolUseContent(id, name);
|
||||
toolContent->setParent(this);
|
||||
m_currentBlocks[index] = toolContent;
|
||||
m_pendingToolArguments[index] = "";
|
||||
@ -73,7 +73,7 @@ void OpenAIMessage::handleToolCallComplete(int index)
|
||||
}
|
||||
|
||||
if (index < m_currentBlocks.size()) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(m_currentBlocks[index])) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(m_currentBlocks[index])) {
|
||||
toolContent->setInput(argsObject);
|
||||
}
|
||||
}
|
||||
@ -100,10 +100,10 @@ QJsonObject OpenAIMessage::toProviderFormat() const
|
||||
if (!block)
|
||||
continue;
|
||||
|
||||
if (auto text = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto text = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
textContent += text->text();
|
||||
} else if (auto tool = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
toolCalls.append(tool->toJson(LLMCore::ProviderFormat::OpenAI));
|
||||
} else if (auto tool = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolCalls.append(tool->toJson(PluginLLMCore::ProviderFormat::OpenAI));
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,20 +126,20 @@ QJsonArray OpenAIMessage::createToolResultMessages(const QHash<QString, QString>
|
||||
|
||||
for (auto toolContent : getCurrentToolUseContent()) {
|
||||
if (toolResults.contains(toolContent->id())) {
|
||||
auto toolResult = std::make_unique<LLMCore::ToolResultContent>(
|
||||
auto toolResult = std::make_unique<PluginLLMCore::ToolResultContent>(
|
||||
toolContent->id(), toolResults[toolContent->id()]);
|
||||
messages.append(toolResult->toJson(LLMCore::ProviderFormat::OpenAI));
|
||||
messages.append(toolResult->toJson(PluginLLMCore::ProviderFormat::OpenAI));
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
QList<LLMCore::ToolUseContent *> OpenAIMessage::getCurrentToolUseContent() const
|
||||
QList<PluginLLMCore::ToolUseContent *> OpenAIMessage::getCurrentToolUseContent() const
|
||||
{
|
||||
QList<LLMCore::ToolUseContent *> toolBlocks;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolBlocks;
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto toolContent = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
if (auto toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolBlocks.append(toolContent);
|
||||
}
|
||||
}
|
||||
@ -153,29 +153,29 @@ void OpenAIMessage::startNewContinuation()
|
||||
m_currentBlocks.clear();
|
||||
m_pendingToolArguments.clear();
|
||||
m_finishReason.clear();
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
}
|
||||
|
||||
void OpenAIMessage::updateStateFromFinishReason()
|
||||
{
|
||||
if (m_finishReason == "tool_calls" && !getCurrentToolUseContent().empty()) {
|
||||
m_state = LLMCore::MessageState::RequiresToolExecution;
|
||||
m_state = PluginLLMCore::MessageState::RequiresToolExecution;
|
||||
} else if (m_finishReason == "stop") {
|
||||
m_state = LLMCore::MessageState::Final;
|
||||
m_state = PluginLLMCore::MessageState::Final;
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Complete;
|
||||
m_state = PluginLLMCore::MessageState::Complete;
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::TextContent *OpenAIMessage::getOrCreateTextContent()
|
||||
PluginLLMCore::TextContent *OpenAIMessage::getOrCreateTextContent()
|
||||
{
|
||||
for (auto block : m_currentBlocks) {
|
||||
if (auto textContent = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto textContent = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
return textContent;
|
||||
}
|
||||
}
|
||||
|
||||
return addCurrentContent<LLMCore::TextContent>();
|
||||
return addCurrentContent<PluginLLMCore::TextContent>();
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/ContentBlocks.hpp>
|
||||
#include <pluginllmcore/ContentBlocks.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
@ -38,19 +38,19 @@ public:
|
||||
QJsonObject toProviderFormat() const;
|
||||
QJsonArray createToolResultMessages(const QHash<QString, QString> &toolResults) const;
|
||||
|
||||
LLMCore::MessageState state() const { return m_state; }
|
||||
QList<LLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
PluginLLMCore::MessageState state() const { return m_state; }
|
||||
QList<PluginLLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
|
||||
void startNewContinuation();
|
||||
|
||||
private:
|
||||
QString m_finishReason;
|
||||
LLMCore::MessageState m_state = LLMCore::MessageState::Building;
|
||||
QList<LLMCore::ContentBlock *> m_currentBlocks;
|
||||
PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building;
|
||||
QList<PluginLLMCore::ContentBlock *> m_currentBlocks;
|
||||
QHash<int, QString> m_pendingToolArguments;
|
||||
|
||||
void updateStateFromFinishReason();
|
||||
LLMCore::TextContent *getOrCreateTextContent();
|
||||
PluginLLMCore::TextContent *getOrCreateTextContent();
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T *addCurrentContent(Args &&...args)
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#include "OpenAIProvider.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -34,7 +34,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
OpenAIProvider::OpenAIProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -71,9 +71,9 @@ bool OpenAIProvider::supportsModelListing() const
|
||||
|
||||
void OpenAIProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -116,22 +116,22 @@ void OpenAIProvider::prepareRequest(
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
applyModelParams(Settings::quickRefactorSettings());
|
||||
} else {
|
||||
applyModelParams(Settings::chatAssistantSettings());
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
LLMCore::RunToolsFilter filter = LLMCore::RunToolsFilter::ALL;
|
||||
if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
filter = LLMCore::RunToolsFilter::OnlyRead;
|
||||
PluginLLMCore::RunToolsFilter filter = PluginLLMCore::RunToolsFilter::ALL;
|
||||
if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
filter = PluginLLMCore::RunToolsFilter::OnlyRead;
|
||||
}
|
||||
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
request["tools"] = toolsDefinitions;
|
||||
LOG_MESSAGE(QString("Added %1 tools to OpenAI request").arg(toolsDefinitions.size()));
|
||||
@ -172,7 +172,7 @@ QFuture<QList<QString>> OpenAIProvider::getInstalledModels(const QString &url)
|
||||
});
|
||||
}
|
||||
|
||||
QList<QString> OpenAIProvider::validateRequest(const QJsonObject &request, LLMCore::TemplateType type)
|
||||
QList<QString> OpenAIProvider::validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
const auto templateReq = QJsonObject{
|
||||
{"model", {}},
|
||||
@ -188,7 +188,7 @@ QList<QString> OpenAIProvider::validateRequest(const QJsonObject &request, LLMCo
|
||||
{"stream", {}},
|
||||
{"tools", {}}};
|
||||
|
||||
return LLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
return PluginLLMCore::ValidationUtils::validateRequestFields(request, templateReq);
|
||||
}
|
||||
|
||||
QString OpenAIProvider::apiKey() const
|
||||
@ -205,13 +205,13 @@ void OpenAIProvider::prepareNetworkRequest(QNetworkRequest &networkRequest) cons
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID OpenAIProvider::providerID() const
|
||||
PluginLLMCore::ProviderID OpenAIProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::OpenAI;
|
||||
return PluginLLMCore::ProviderID::OpenAI;
|
||||
}
|
||||
|
||||
void OpenAIProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -238,17 +238,17 @@ bool OpenAIProvider::supportImage() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAIProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAIProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("OpenAIProvider: Cancelling request %1").arg(requestId));
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void OpenAIProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
for (const QString &line : lines) {
|
||||
@ -265,7 +265,7 @@ void OpenAIProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void OpenAIProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("OpenAIProvider request %1 failed: %2").arg(requestId, *error));
|
||||
@ -276,7 +276,7 @@ void OpenAIProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("Waiting for tools to complete for %1").arg(requestId));
|
||||
m_dataBuffers.remove(requestId);
|
||||
return;
|
||||
@ -284,7 +284,7 @@ void OpenAIProvider::onRequestFinished(
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
LOG_MESSAGE(QString("Emitting full response for %1").arg(requestId));
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
@ -361,7 +361,7 @@ void OpenAIProvider::processStreamChunk(const QString &requestId, const QJsonObj
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
LOG_MESSAGE(QString("Cleared message state for continuation request %1").arg(requestId));
|
||||
@ -371,7 +371,7 @@ void OpenAIProvider::processStreamChunk(const QString &requestId, const QJsonObj
|
||||
QString content = delta["content"].toString();
|
||||
message->handleContentDelta(content);
|
||||
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
buffers.responseContent += content;
|
||||
emit partialResponseReceived(requestId, content);
|
||||
}
|
||||
@ -416,7 +416,7 @@ void OpenAIProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
OpenAIMessage *message = m_messages[requestId];
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
LOG_MESSAGE(QString("OpenAI message requires tool execution for %1").arg(requestId));
|
||||
|
||||
auto toolUseContent = message->getCurrentToolUseContent();
|
||||
@ -438,7 +438,7 @@ void OpenAIProvider::handleMessageComplete(const QString &requestId)
|
||||
}
|
||||
}
|
||||
|
||||
void OpenAIProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAIProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LOG_MESSAGE(QString("Cleaning up OpenAI request %1").arg(requestId));
|
||||
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OpenAIProvider : public LLMCore::Provider
|
||||
class OpenAIProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,29 +38,29 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -70,11 +70,11 @@ private slots:
|
||||
private:
|
||||
void processStreamChunk(const QString &requestId, const QJsonObject &chunk);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ void OpenAIResponsesMessage::handleItemDelta(const QJsonObject &item)
|
||||
|
||||
void OpenAIResponsesMessage::handleToolCallStart(const QString &callId, const QString &name)
|
||||
{
|
||||
auto toolContent = new LLMCore::ToolUseContent(callId, name);
|
||||
auto toolContent = new PluginLLMCore::ToolUseContent(callId, name);
|
||||
toolContent->setParent(this);
|
||||
m_items.append(toolContent);
|
||||
m_toolCalls[callId] = toolContent;
|
||||
@ -86,7 +86,7 @@ void OpenAIResponsesMessage::handleToolCallComplete(const QString &callId)
|
||||
|
||||
void OpenAIResponsesMessage::handleReasoningStart(const QString &itemId)
|
||||
{
|
||||
auto thinkingContent = new LLMCore::ThinkingContent();
|
||||
auto thinkingContent = new PluginLLMCore::ThinkingContent();
|
||||
thinkingContent->setParent(this);
|
||||
m_items.append(thinkingContent);
|
||||
m_thinkingBlocks[itemId] = thinkingContent;
|
||||
@ -115,13 +115,13 @@ QList<QJsonObject> OpenAIResponsesMessage::toItemsFormat() const
|
||||
QList<QJsonObject> items;
|
||||
|
||||
QString textContent;
|
||||
QList<LLMCore::ToolUseContent *> toolCalls;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolCalls;
|
||||
|
||||
for (const auto *block : m_items) {
|
||||
if (const auto *text = qobject_cast<const LLMCore::TextContent *>(block)) {
|
||||
if (const auto *text = qobject_cast<const PluginLLMCore::TextContent *>(block)) {
|
||||
textContent += text->text();
|
||||
} else if (auto *tool = qobject_cast<LLMCore::ToolUseContent *>(
|
||||
const_cast<LLMCore::ContentBlock *>(block))) {
|
||||
} else if (auto *tool = qobject_cast<PluginLLMCore::ToolUseContent *>(
|
||||
const_cast<PluginLLMCore::ContentBlock *>(block))) {
|
||||
toolCalls.append(tool);
|
||||
}
|
||||
}
|
||||
@ -146,22 +146,22 @@ QList<QJsonObject> OpenAIResponsesMessage::toItemsFormat() const
|
||||
return items;
|
||||
}
|
||||
|
||||
QList<LLMCore::ToolUseContent *> OpenAIResponsesMessage::getCurrentToolUseContent() const
|
||||
QList<PluginLLMCore::ToolUseContent *> OpenAIResponsesMessage::getCurrentToolUseContent() const
|
||||
{
|
||||
QList<LLMCore::ToolUseContent *> toolBlocks;
|
||||
QList<PluginLLMCore::ToolUseContent *> toolBlocks;
|
||||
for (auto *block : m_items) {
|
||||
if (auto *toolContent = qobject_cast<LLMCore::ToolUseContent *>(block)) {
|
||||
if (auto *toolContent = qobject_cast<PluginLLMCore::ToolUseContent *>(block)) {
|
||||
toolBlocks.append(toolContent);
|
||||
}
|
||||
}
|
||||
return toolBlocks;
|
||||
}
|
||||
|
||||
QList<LLMCore::ThinkingContent *> OpenAIResponsesMessage::getCurrentThinkingContent() const
|
||||
QList<PluginLLMCore::ThinkingContent *> OpenAIResponsesMessage::getCurrentThinkingContent() const
|
||||
{
|
||||
QList<LLMCore::ThinkingContent *> thinkingBlocks;
|
||||
QList<PluginLLMCore::ThinkingContent *> thinkingBlocks;
|
||||
for (auto *block : m_items) {
|
||||
if (auto *thinkingContent = qobject_cast<LLMCore::ThinkingContent *>(block)) {
|
||||
if (auto *thinkingContent = qobject_cast<PluginLLMCore::ThinkingContent *>(block)) {
|
||||
thinkingBlocks.append(thinkingContent);
|
||||
}
|
||||
}
|
||||
@ -189,7 +189,7 @@ QString OpenAIResponsesMessage::accumulatedText() const
|
||||
{
|
||||
QString text;
|
||||
for (const auto *block : m_items) {
|
||||
if (const auto *textContent = qobject_cast<const LLMCore::TextContent *>(block)) {
|
||||
if (const auto *textContent = qobject_cast<const PluginLLMCore::TextContent *>(block)) {
|
||||
text += textContent->text();
|
||||
}
|
||||
}
|
||||
@ -202,28 +202,28 @@ void OpenAIResponsesMessage::updateStateFromStatus()
|
||||
|
||||
if (m_status == "completed") {
|
||||
if (!getCurrentToolUseContent().isEmpty()) {
|
||||
m_state = LLMCore::MessageState::RequiresToolExecution;
|
||||
m_state = PluginLLMCore::MessageState::RequiresToolExecution;
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Complete;
|
||||
m_state = PluginLLMCore::MessageState::Complete;
|
||||
}
|
||||
} else if (m_status == "in_progress") {
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
} else if (m_status == "failed" || m_status == "cancelled" || m_status == "incomplete") {
|
||||
m_state = LLMCore::MessageState::Final;
|
||||
m_state = PluginLLMCore::MessageState::Final;
|
||||
} else {
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::TextContent *OpenAIResponsesMessage::getOrCreateTextItem()
|
||||
PluginLLMCore::TextContent *OpenAIResponsesMessage::getOrCreateTextItem()
|
||||
{
|
||||
for (auto *block : m_items) {
|
||||
if (auto *textContent = qobject_cast<LLMCore::TextContent *>(block)) {
|
||||
if (auto *textContent = qobject_cast<PluginLLMCore::TextContent *>(block)) {
|
||||
return textContent;
|
||||
}
|
||||
}
|
||||
|
||||
auto *textContent = new LLMCore::TextContent();
|
||||
auto *textContent = new PluginLLMCore::TextContent();
|
||||
textContent->setParent(this);
|
||||
m_items.append(textContent);
|
||||
return textContent;
|
||||
@ -239,7 +239,7 @@ void OpenAIResponsesMessage::startNewContinuation()
|
||||
|
||||
m_pendingToolArguments.clear();
|
||||
m_status.clear();
|
||||
m_state = LLMCore::MessageState::Building;
|
||||
m_state = PluginLLMCore::MessageState::Building;
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <llmcore/ContentBlocks.hpp>
|
||||
#include <pluginllmcore/ContentBlocks.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
@ -41,10 +41,10 @@ public:
|
||||
QList<QJsonObject> toItemsFormat() const;
|
||||
QJsonArray createToolResultItems(const QHash<QString, QString> &toolResults) const;
|
||||
|
||||
LLMCore::MessageState state() const noexcept { return m_state; }
|
||||
PluginLLMCore::MessageState state() const noexcept { return m_state; }
|
||||
QString accumulatedText() const;
|
||||
QList<LLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<LLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
QList<PluginLLMCore::ToolUseContent *> getCurrentToolUseContent() const;
|
||||
QList<PluginLLMCore::ThinkingContent *> getCurrentThinkingContent() const;
|
||||
|
||||
bool hasToolCalls() const noexcept { return !m_toolCalls.isEmpty(); }
|
||||
bool hasThinkingContent() const noexcept { return !m_thinkingBlocks.isEmpty(); }
|
||||
@ -53,14 +53,14 @@ public:
|
||||
|
||||
private:
|
||||
QString m_status;
|
||||
LLMCore::MessageState m_state = LLMCore::MessageState::Building;
|
||||
QList<LLMCore::ContentBlock *> m_items;
|
||||
PluginLLMCore::MessageState m_state = PluginLLMCore::MessageState::Building;
|
||||
QList<PluginLLMCore::ContentBlock *> m_items;
|
||||
QHash<QString, QString> m_pendingToolArguments;
|
||||
QHash<QString, LLMCore::ToolUseContent *> m_toolCalls;
|
||||
QHash<QString, LLMCore::ThinkingContent *> m_thinkingBlocks;
|
||||
QHash<QString, PluginLLMCore::ToolUseContent *> m_toolCalls;
|
||||
QHash<QString, PluginLLMCore::ThinkingContent *> m_thinkingBlocks;
|
||||
|
||||
void updateStateFromStatus();
|
||||
LLMCore::TextContent *getOrCreateTextItem();
|
||||
PluginLLMCore::TextContent *getOrCreateTextItem();
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#include "OpenAIResponsesProvider.hpp"
|
||||
#include "OpenAIResponses/ResponseObject.hpp"
|
||||
|
||||
#include "llmcore/ValidationUtils.hpp"
|
||||
#include "pluginllmcore/ValidationUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
@ -35,7 +35,7 @@
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
OpenAIResponsesProvider::OpenAIResponsesProvider(QObject *parent)
|
||||
: LLMCore::Provider(parent)
|
||||
: PluginLLMCore::Provider(parent)
|
||||
, m_toolsManager(new Tools::ToolsManager(this))
|
||||
{
|
||||
connect(
|
||||
@ -72,9 +72,9 @@ bool OpenAIResponsesProvider::supportsModelListing() const
|
||||
|
||||
void OpenAIResponsesProvider::prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled)
|
||||
{
|
||||
@ -109,9 +109,9 @@ void OpenAIResponsesProvider::prepareRequest(
|
||||
request["include"] = include;
|
||||
};
|
||||
|
||||
if (type == LLMCore::RequestType::CodeCompletion) {
|
||||
if (type == PluginLLMCore::RequestType::CodeCompletion) {
|
||||
applyModelParams(Settings::codeCompletionSettings());
|
||||
} else if (type == LLMCore::RequestType::QuickRefactoring) {
|
||||
} else if (type == PluginLLMCore::RequestType::QuickRefactoring) {
|
||||
const auto &qrSettings = Settings::quickRefactorSettings();
|
||||
applyModelParams(qrSettings);
|
||||
|
||||
@ -128,12 +128,12 @@ void OpenAIResponsesProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (isToolsEnabled) {
|
||||
const LLMCore::RunToolsFilter filter = (type == LLMCore::RequestType::QuickRefactoring)
|
||||
? LLMCore::RunToolsFilter::OnlyRead
|
||||
: LLMCore::RunToolsFilter::ALL;
|
||||
const PluginLLMCore::RunToolsFilter filter = (type == PluginLLMCore::RequestType::QuickRefactoring)
|
||||
? PluginLLMCore::RunToolsFilter::OnlyRead
|
||||
: PluginLLMCore::RunToolsFilter::ALL;
|
||||
|
||||
const auto toolsDefinitions
|
||||
= m_toolsManager->getToolsDefinitions(LLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
= m_toolsManager->getToolsDefinitions(PluginLLMCore::ToolSchemaFormat::OpenAI, filter);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
QJsonArray responsesTools;
|
||||
|
||||
@ -197,7 +197,7 @@ QFuture<QList<QString>> OpenAIResponsesProvider::getInstalledModels(const QStrin
|
||||
}
|
||||
|
||||
QList<QString> OpenAIResponsesProvider::validateRequest(
|
||||
const QJsonObject &request, LLMCore::TemplateType type)
|
||||
const QJsonObject &request, PluginLLMCore::TemplateType type)
|
||||
{
|
||||
Q_UNUSED(type);
|
||||
|
||||
@ -250,13 +250,13 @@ void OpenAIResponsesProvider::prepareNetworkRequest(QNetworkRequest &networkRequ
|
||||
}
|
||||
}
|
||||
|
||||
LLMCore::ProviderID OpenAIResponsesProvider::providerID() const
|
||||
PluginLLMCore::ProviderID OpenAIResponsesProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::OpenAIResponses;
|
||||
return PluginLLMCore::ProviderID::OpenAIResponses;
|
||||
}
|
||||
|
||||
void OpenAIResponsesProvider::sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload)
|
||||
{
|
||||
if (!m_messages.contains(requestId)) {
|
||||
m_dataBuffers[requestId].clear();
|
||||
@ -286,16 +286,16 @@ bool OpenAIResponsesProvider::supportThinking() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenAIResponsesProvider::cancelRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAIResponsesProvider::cancelRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
LLMCore::Provider::cancelRequest(requestId);
|
||||
PluginLLMCore::Provider::cancelRequest(requestId);
|
||||
cleanupRequest(requestId);
|
||||
}
|
||||
|
||||
void OpenAIResponsesProvider::onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data)
|
||||
{
|
||||
LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const QStringList lines = buffers.rawStreamBuffer.processData(data);
|
||||
|
||||
QString currentEventType;
|
||||
@ -329,7 +329,7 @@ void OpenAIResponsesProvider::onDataReceived(
|
||||
}
|
||||
|
||||
void OpenAIResponsesProvider::onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, std::optional<QString> error)
|
||||
{
|
||||
if (error) {
|
||||
LOG_MESSAGE(QString("OpenAIResponses request %1 failed: %2").arg(requestId, *error));
|
||||
@ -340,13 +340,13 @@ void OpenAIResponsesProvider::onRequestFinished(
|
||||
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIResponsesMessage *message = m_messages[requestId];
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_dataBuffers.contains(requestId)) {
|
||||
const LLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
const PluginLLMCore::DataBuffers &buffers = m_dataBuffers[requestId];
|
||||
if (!buffers.responseContent.isEmpty()) {
|
||||
emit fullResponseReceived(requestId, buffers.responseContent);
|
||||
} else {
|
||||
@ -376,7 +376,7 @@ void OpenAIResponsesProvider::processStreamEvent(
|
||||
}
|
||||
} else if (
|
||||
m_dataBuffers.contains(requestId)
|
||||
&& message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
&& message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
message->startNewContinuation();
|
||||
emit continuationStarted(requestId);
|
||||
}
|
||||
@ -571,7 +571,7 @@ void OpenAIResponsesProvider::handleMessageComplete(const QString &requestId)
|
||||
|
||||
emitPendingThinkingBlocks(requestId);
|
||||
|
||||
if (message->state() == LLMCore::MessageState::RequiresToolExecution) {
|
||||
if (message->state() == PluginLLMCore::MessageState::RequiresToolExecution) {
|
||||
const auto toolUseContent = message->getCurrentToolUseContent();
|
||||
|
||||
if (toolUseContent.isEmpty()) {
|
||||
@ -633,7 +633,7 @@ void OpenAIResponsesProvider::onToolExecutionComplete(
|
||||
sendRequest(requestId, m_requestUrls[requestId], continuationRequest);
|
||||
}
|
||||
|
||||
void OpenAIResponsesProvider::cleanupRequest(const LLMCore::RequestID &requestId)
|
||||
void OpenAIResponsesProvider::cleanupRequest(const PluginLLMCore::RequestID &requestId)
|
||||
{
|
||||
if (m_messages.contains(requestId)) {
|
||||
OpenAIResponsesMessage *message = m_messages.take(requestId);
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "OpenAIResponsesMessage.hpp"
|
||||
#include "tools/ToolsManager.hpp"
|
||||
#include <llmcore/Provider.hpp>
|
||||
#include <pluginllmcore/Provider.hpp>
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OpenAIResponsesProvider : public LLMCore::Provider
|
||||
class OpenAIResponsesProvider : public PluginLLMCore::Provider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -38,30 +38,30 @@ public:
|
||||
bool supportsModelListing() const override;
|
||||
void prepareRequest(
|
||||
QJsonObject &request,
|
||||
LLMCore::PromptTemplate *prompt,
|
||||
LLMCore::ContextData context,
|
||||
LLMCore::RequestType type,
|
||||
PluginLLMCore::PromptTemplate *prompt,
|
||||
PluginLLMCore::ContextData context,
|
||||
PluginLLMCore::RequestType type,
|
||||
bool isToolsEnabled,
|
||||
bool isThinkingEnabled) override;
|
||||
QFuture<QList<QString>> getInstalledModels(const QString &url) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, LLMCore::TemplateType type) override;
|
||||
QList<QString> validateRequest(const QJsonObject &request, PluginLLMCore::TemplateType type) override;
|
||||
QString apiKey() const override;
|
||||
void prepareNetworkRequest(QNetworkRequest &networkRequest) const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
|
||||
void sendRequest(
|
||||
const LLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
const PluginLLMCore::RequestID &requestId, const QUrl &url, const QJsonObject &payload) override;
|
||||
|
||||
bool supportsTools() const override;
|
||||
bool supportImage() const override;
|
||||
bool supportThinking() const override;
|
||||
void cancelRequest(const LLMCore::RequestID &requestId) override;
|
||||
void cancelRequest(const PluginLLMCore::RequestID &requestId) override;
|
||||
|
||||
public slots:
|
||||
void onDataReceived(
|
||||
const QodeAssist::LLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId, const QByteArray &data) override;
|
||||
void onRequestFinished(
|
||||
const QodeAssist::LLMCore::RequestID &requestId,
|
||||
const QodeAssist::PluginLLMCore::RequestID &requestId,
|
||||
std::optional<QString> error) override;
|
||||
|
||||
private slots:
|
||||
@ -72,13 +72,13 @@ private:
|
||||
void processStreamEvent(const QString &requestId, const QString &eventType, const QJsonObject &data);
|
||||
void emitPendingThinkingBlocks(const QString &requestId);
|
||||
void handleMessageComplete(const QString &requestId);
|
||||
void cleanupRequest(const LLMCore::RequestID &requestId);
|
||||
void cleanupRequest(const PluginLLMCore::RequestID &requestId);
|
||||
|
||||
QHash<LLMCore::RequestID, OpenAIResponsesMessage *> m_messages;
|
||||
QHash<LLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<LLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<LLMCore::RequestID, QHash<QString, QString>> m_itemIdToCallId;
|
||||
QHash<LLMCore::RequestID, int> m_emittedThinkingBlocksCount;
|
||||
QHash<PluginLLMCore::RequestID, OpenAIResponsesMessage *> m_messages;
|
||||
QHash<PluginLLMCore::RequestID, QUrl> m_requestUrls;
|
||||
QHash<PluginLLMCore::RequestID, QJsonObject> m_originalRequests;
|
||||
QHash<PluginLLMCore::RequestID, QHash<QString, QString>> m_itemIdToCallId;
|
||||
QHash<PluginLLMCore::RequestID, int> m_emittedThinkingBlocksCount;
|
||||
Tools::ToolsManager *m_toolsManager;
|
||||
};
|
||||
|
||||
|
||||
@ -43,9 +43,9 @@ QString OpenRouterProvider::apiKey() const
|
||||
return Settings::providerSettings().openRouterApiKey();
|
||||
}
|
||||
|
||||
LLMCore::ProviderID OpenRouterProvider::providerID() const
|
||||
PluginLLMCore::ProviderID OpenRouterProvider::providerID() const
|
||||
{
|
||||
return LLMCore::ProviderID::OpenRouter;
|
||||
return PluginLLMCore::ProviderID::OpenRouter;
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
QString name() const override;
|
||||
QString url() const override;
|
||||
QString apiKey() const override;
|
||||
LLMCore::ProviderID providerID() const override;
|
||||
PluginLLMCore::ProviderID providerID() const override;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Providers
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "llmcore/ProvidersManager.hpp"
|
||||
#include "pluginllmcore/ProvidersManager.hpp"
|
||||
#include "providers/ClaudeProvider.hpp"
|
||||
#include "providers/CodestralProvider.hpp"
|
||||
#include "providers/GoogleAIProvider.hpp"
|
||||
@ -36,7 +36,7 @@ namespace QodeAssist::Providers {
|
||||
|
||||
inline void registerProviders()
|
||||
{
|
||||
auto &providerManager = LLMCore::ProvidersManager::instance();
|
||||
auto &providerManager = PluginLLMCore::ProvidersManager::instance();
|
||||
providerManager.registerProvider<OllamaProvider>();
|
||||
providerManager.registerProvider<ClaudeProvider>();
|
||||
providerManager.registerProvider<OpenAIProvider>();
|
||||
|
||||
Reference in New Issue
Block a user