refactor: Remove non-streaming support (#229)

This commit is contained in:
Petr Mironychev
2025-09-17 19:38:27 +02:00
committed by GitHub
parent 561661b476
commit ec1b5bdf5f
33 changed files with 412 additions and 408 deletions

View File

@ -15,6 +15,8 @@ add_library(LLMCore STATIC
ValidationUtils.hpp ValidationUtils.cpp
ProviderID.hpp
HttpClient.hpp HttpClient.cpp
DataBuffers.hpp
SSEBuffer.hpp SSEBuffer.cpp
)
target_link_libraries(LLMCore

39
llmcore/DataBuffers.hpp Normal file
View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "SSEBuffer.hpp"
#include <QString>
namespace QodeAssist::LLMCore {
struct DataBuffers
{
SSEBuffer rawStreamBuffer;
QString responseContent;
void clear()
{
rawStreamBuffer.clear();
responseContent.clear();
}
};
} // namespace QodeAssist::LLMCore

View File

@ -1,18 +1,31 @@
#include "Provider.hpp"
#include <QJsonDocument>
namespace QodeAssist::LLMCore {
Provider::Provider(QObject *parent)
: QObject(parent)
, m_httpClient(std::make_unique<HttpClient>())
, m_httpClient(new HttpClient(this))
{
connect(m_httpClient.get(), &HttpClient::dataReceived, this, &Provider::onDataReceived);
connect(m_httpClient.get(), &HttpClient::requestFinished, this, &Provider::onRequestFinished);
connect(m_httpClient, &HttpClient::dataReceived, this, &Provider::onDataReceived);
connect(m_httpClient, &HttpClient::requestFinished, this, &Provider::onRequestFinished);
}
HttpClient *Provider::httpClient() const
{
return m_httpClient.get();
return m_httpClient;
}
QJsonObject Provider::parseEventLine(const QString &line)
{
if (!line.startsWith("data: "))
return QJsonObject();
QString jsonStr = line.mid(6);
QJsonDocument doc = QJsonDocument::fromJson(jsonStr.toUtf8());
return doc.object();
}
} // namespace QodeAssist::LLMCore

View File

@ -25,6 +25,7 @@
#include <QString>
#include "ContextData.hpp"
#include "DataBuffers.hpp"
#include "HttpClient.hpp"
#include "PromptTemplate.hpp"
#include "RequestType.hpp"
@ -73,8 +74,14 @@ signals:
void fullResponseReceived(const QString &requestId, const QString &fullText);
void requestFailed(const QString &requestId, const QString &error);
protected:
QJsonObject parseEventLine(const QString &line);
QHash<RequestID, DataBuffers> m_dataBuffers;
QHash<RequestID, QUrl> m_requestUrls;
private:
std::unique_ptr<HttpClient> m_httpClient;
HttpClient *m_httpClient;
};
} // namespace QodeAssist::LLMCore

View File

@ -17,9 +17,13 @@
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QString>
#pragma once
namespace QodeAssist::LLMCore {
enum RequestType { CodeCompletion, Chat, Embedding };
using RequestID = QString;
}

51
llmcore/SSEBuffer.cpp Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#include "SSEBuffer.hpp"
namespace QodeAssist::LLMCore {
QStringList SSEBuffer::processData(const QByteArray &data)
{
m_buffer += QString::fromUtf8(data);
QStringList lines = m_buffer.split('\n');
m_buffer = lines.takeLast();
lines.removeAll(QString());
return lines;
}
void SSEBuffer::clear()
{
m_buffer.clear();
}
QString SSEBuffer::currentBuffer() const
{
return m_buffer;
}
bool SSEBuffer::hasIncompleteData() const
{
return !m_buffer.isEmpty();
}
} // namespace QodeAssist::LLMCore

42
llmcore/SSEBuffer.hpp Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2025 Petr Mironychev
*
* This file is part of QodeAssist.
*
* QodeAssist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QodeAssist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QString>
#include <QStringList>
namespace QodeAssist::LLMCore {
class SSEBuffer
{
public:
SSEBuffer() = default;
QStringList processData(const QByteArray &data);
void clear();
QString currentBuffer() const;
bool hasIncompleteData() const;
private:
QString m_buffer;
};
} // namespace QodeAssist::LLMCore