mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-14 11:04:26 -04:00
fix: Handling full input message from OpenAI compatible providers
This commit is contained in:
@ -108,15 +108,22 @@ bool LMStudioProvider::handleResponse(QNetworkReply *reply, QString &accumulated
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArrayList chunks = data.split('\n');
|
bool isDone = false;
|
||||||
for (const QByteArray &chunk : chunks) {
|
QByteArrayList lines = data.split('\n');
|
||||||
if (chunk.trimmed().isEmpty() || chunk == "data: [DONE]") {
|
|
||||||
|
for (const QByteArray &line : lines) {
|
||||||
|
if (line.trimmed().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray jsonData = chunk;
|
if (line == "data: [DONE]") {
|
||||||
if (chunk.startsWith("data: ")) {
|
isDone = true;
|
||||||
jsonData = chunk.mid(6);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray jsonData = line;
|
||||||
|
if (line.startsWith("data: ")) {
|
||||||
|
jsonData = line.mid(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@ -128,15 +135,21 @@ bool LMStudioProvider::handleResponse(QNetworkReply *reply, QString &accumulated
|
|||||||
|
|
||||||
auto message = LLMCore::OpenAIMessage::fromJson(doc.object());
|
auto message = LLMCore::OpenAIMessage::fromJson(doc.object());
|
||||||
if (message.hasError()) {
|
if (message.hasError()) {
|
||||||
LOG_MESSAGE("Error in LMStudioProvider response: " + message.error);
|
LOG_MESSAGE("Error in OpenAI response: " + message.error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
accumulatedResponse += message.getContent();
|
QString content = message.getContent();
|
||||||
return message.isDone();
|
if (!content.isEmpty()) {
|
||||||
|
accumulatedResponse += content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.isDone()) {
|
||||||
|
isDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return isDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> LMStudioProvider::getInstalledModels(const QString &url)
|
QList<QString> LMStudioProvider::getInstalledModels(const QString &url)
|
||||||
|
@ -109,15 +109,22 @@ bool OpenAICompatProvider::handleResponse(QNetworkReply *reply, QString &accumul
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArrayList chunks = data.split('\n');
|
bool isDone = false;
|
||||||
for (const QByteArray &chunk : chunks) {
|
QByteArrayList lines = data.split('\n');
|
||||||
if (chunk.trimmed().isEmpty() || chunk == "data: [DONE]") {
|
|
||||||
|
for (const QByteArray &line : lines) {
|
||||||
|
if (line.trimmed().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray jsonData = chunk;
|
if (line == "data: [DONE]") {
|
||||||
if (chunk.startsWith("data: ")) {
|
isDone = true;
|
||||||
jsonData = chunk.mid(6);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray jsonData = line;
|
||||||
|
if (line.startsWith("data: ")) {
|
||||||
|
jsonData = line.mid(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@ -133,11 +140,17 @@ bool OpenAICompatProvider::handleResponse(QNetworkReply *reply, QString &accumul
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
accumulatedResponse += message.getContent();
|
QString content = message.getContent();
|
||||||
return message.isDone();
|
if (!content.isEmpty()) {
|
||||||
|
accumulatedResponse += content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.isDone()) {
|
||||||
|
isDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return isDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> OpenAICompatProvider::getInstalledModels(const QString &url)
|
QList<QString> OpenAICompatProvider::getInstalledModels(const QString &url)
|
||||||
|
@ -93,16 +93,22 @@ bool OpenRouterProvider::handleResponse(QNetworkReply *reply, QString &accumulat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArrayList chunks = data.split('\n');
|
bool isDone = false;
|
||||||
for (const QByteArray &chunk : chunks) {
|
QByteArrayList lines = data.split('\n');
|
||||||
if (chunk.trimmed().isEmpty() || chunk.contains("OPENROUTER PROCESSING")
|
|
||||||
|| chunk == "data: [DONE]") {
|
for (const QByteArray &line : lines) {
|
||||||
|
if (line.trimmed().isEmpty() || line.contains("OPENROUTER PROCESSING")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray jsonData = chunk;
|
if (line == "data: [DONE]") {
|
||||||
if (chunk.startsWith("data: ")) {
|
isDone = true;
|
||||||
jsonData = chunk.mid(6);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray jsonData = line;
|
||||||
|
if (line.startsWith("data: ")) {
|
||||||
|
jsonData = line.mid(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
@ -114,15 +120,21 @@ bool OpenRouterProvider::handleResponse(QNetworkReply *reply, QString &accumulat
|
|||||||
|
|
||||||
auto message = LLMCore::OpenAIMessage::fromJson(doc.object());
|
auto message = LLMCore::OpenAIMessage::fromJson(doc.object());
|
||||||
if (message.hasError()) {
|
if (message.hasError()) {
|
||||||
LOG_MESSAGE("Error in OpenRouter response: " + message.error);
|
LOG_MESSAGE("Error in OpenAI response: " + message.error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
accumulatedResponse += message.getContent();
|
QString content = message.getContent();
|
||||||
return message.isDone();
|
if (!content.isEmpty()) {
|
||||||
|
accumulatedResponse += content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.isDone()) {
|
||||||
|
isDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return isDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OpenRouterProvider::apiKey() const
|
QString OpenRouterProvider::apiKey() const
|
||||||
|
Reference in New Issue
Block a user