mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-10-04 19:17:29 -04:00
Refactor llm providers to use internal http client (#227)
* refactor: Move http client into provider * refactor: Rework ollama provider for work with internal http client * refactor: Rework LM Studio provider to work with internal http client * refactor: Rework Mistral AI to work with internal http client * fix: Replace url and header to QNetworkRequest * refactor: Rework Google provider to use internal http client * refactor: OpenAI compatible providers switch to use internal http client * fix: Remove m_requestHandler from tests * refactor: Remove old handleData method * fix: Remove LLMClientInterfaceTest
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
#include <context/Utils.hpp>
|
||||
#include <llmcore/PromptTemplateManager.hpp>
|
||||
#include <llmcore/ProvidersManager.hpp>
|
||||
#include <llmcore/RequestConfig.hpp>
|
||||
#include <logger/Logger.hpp>
|
||||
#include <settings/ChatAssistantSettings.hpp>
|
||||
#include <settings/GeneralSettings.hpp>
|
||||
@ -36,30 +37,10 @@ namespace QodeAssist {
|
||||
|
||||
QuickRefactorHandler::QuickRefactorHandler(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_requestHandler(new LLMCore::RequestHandler(this))
|
||||
, m_currentEditor(nullptr)
|
||||
, m_isRefactoringInProgress(false)
|
||||
, m_contextManager(this)
|
||||
{
|
||||
connect(
|
||||
m_requestHandler,
|
||||
&LLMCore::RequestHandler::completionReceived,
|
||||
this,
|
||||
&QuickRefactorHandler::handleLLMResponse);
|
||||
|
||||
connect(
|
||||
m_requestHandler,
|
||||
&LLMCore::RequestHandler::requestFinished,
|
||||
this,
|
||||
[this](const QString &requestId, bool success, const QString &errorString) {
|
||||
if (!success && requestId == m_lastRequestId) {
|
||||
m_isRefactoringInProgress = false;
|
||||
RefactorResult result;
|
||||
result.success = false;
|
||||
result.errorMessage = errorString;
|
||||
emit refactoringCompleted(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QuickRefactorHandler::~QuickRefactorHandler() {}
|
||||
@ -172,7 +153,23 @@ void QuickRefactorHandler::prepareAndSendRequest(
|
||||
|
||||
m_isRefactoringInProgress = true;
|
||||
|
||||
m_requestHandler->sendLLMRequest(config, request);
|
||||
m_activeRequests[requestId] = {request, provider};
|
||||
|
||||
connect(
|
||||
provider,
|
||||
&LLMCore::Provider::fullResponseReceived,
|
||||
this,
|
||||
&QuickRefactorHandler::handleFullResponse,
|
||||
Qt::UniqueConnection);
|
||||
|
||||
connect(
|
||||
provider,
|
||||
&LLMCore::Provider::requestFailed,
|
||||
this,
|
||||
&QuickRefactorHandler::handleRequestFailed,
|
||||
Qt::UniqueConnection);
|
||||
|
||||
provider->sendRequest(requestId, config.url, config.providerRequest);
|
||||
}
|
||||
|
||||
LLMCore::ContextData QuickRefactorHandler::prepareContext(
|
||||
@ -280,7 +277,17 @@ void QuickRefactorHandler::handleLLMResponse(
|
||||
void QuickRefactorHandler::cancelRequest()
|
||||
{
|
||||
if (m_isRefactoringInProgress) {
|
||||
m_requestHandler->cancelRequest(m_lastRequestId);
|
||||
auto id = m_lastRequestId;
|
||||
|
||||
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
|
||||
if (it.key() == id) {
|
||||
const RequestContext &ctx = it.value();
|
||||
ctx.provider->httpClient()->cancelRequest(id);
|
||||
m_activeRequests.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_isRefactoringInProgress = false;
|
||||
|
||||
RefactorResult result;
|
||||
@ -290,4 +297,23 @@ void QuickRefactorHandler::cancelRequest()
|
||||
}
|
||||
}
|
||||
|
||||
void QuickRefactorHandler::handleFullResponse(const QString &requestId, const QString &fullText)
|
||||
{
|
||||
if (requestId == m_lastRequestId) {
|
||||
QJsonObject request{{"id", requestId}};
|
||||
handleLLMResponse(fullText, request, true);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickRefactorHandler::handleRequestFailed(const QString &requestId, const QString &error)
|
||||
{
|
||||
if (requestId == m_lastRequestId) {
|
||||
m_isRefactoringInProgress = false;
|
||||
RefactorResult result;
|
||||
result.success = false;
|
||||
result.errorMessage = error;
|
||||
emit refactoringCompleted(result);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QodeAssist
|
||||
|
Reference in New Issue
Block a user