mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-18 21:14:34 -04:00
Upgrade to version 0.3.0
new QML Chat Qwen chat model
This commit is contained in:
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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 <utils/environment.h>
|
||||
|
||||
class QNetworkReply;
|
||||
class QJsonObject;
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class LLMProvider
|
||||
{
|
||||
public:
|
||||
virtual ~LLMProvider() = default;
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual QString url() const = 0;
|
||||
virtual QString completionEndpoint() const = 0;
|
||||
virtual QString chatEndpoint() const = 0;
|
||||
|
||||
virtual void prepareRequest(QJsonObject &request) = 0;
|
||||
virtual bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) = 0;
|
||||
virtual QList<QString> getInstalledModels(const Utils::Environment &env, const QString &url) = 0;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Providers
|
@ -25,7 +25,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "QodeAssistUtils.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/PresetPromptsSettings.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
@ -52,9 +52,11 @@ QString LMStudioProvider::chatEndpoint() const
|
||||
return "/v1/chat/completions";
|
||||
}
|
||||
|
||||
void LMStudioProvider::prepareRequest(QJsonObject &request)
|
||||
void LMStudioProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||
{
|
||||
auto &settings = Settings::presetPromptsSettings();
|
||||
auto &promptSettings = Settings::presetPromptsSettings();
|
||||
auto settings = promptSettings.getSettings(type);
|
||||
|
||||
QJsonArray messages;
|
||||
|
||||
if (request.contains("system")) {
|
||||
@ -72,16 +74,16 @@ void LMStudioProvider::prepareRequest(QJsonObject &request)
|
||||
request["messages"] = std::move(messages);
|
||||
}
|
||||
|
||||
request["max_tokens"] = settings.maxTokens();
|
||||
request["temperature"] = settings.temperature();
|
||||
if (settings.useTopP())
|
||||
request["top_p"] = settings.topP();
|
||||
if (settings.useTopK())
|
||||
request["top_k"] = settings.topK();
|
||||
if (settings.useFrequencyPenalty())
|
||||
request["frequency_penalty"] = settings.frequencyPenalty();
|
||||
if (settings.usePresencePenalty())
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
request["max_tokens"] = settings.maxTokens;
|
||||
request["temperature"] = settings.temperature;
|
||||
if (settings.useTopP)
|
||||
request["top_p"] = settings.topP;
|
||||
if (settings.useTopK)
|
||||
request["top_k"] = settings.topK;
|
||||
if (settings.useFrequencyPenalty)
|
||||
request["frequency_penalty"] = settings.frequencyPenalty;
|
||||
if (settings.usePresencePenalty)
|
||||
request["presence_penalty"] = settings.presencePenalty;
|
||||
}
|
||||
|
||||
bool LMStudioProvider::handleResponse(QNetworkReply *reply, QString &accumulatedResponse)
|
||||
@ -150,7 +152,7 @@ QList<QString> LMStudioProvider::getInstalledModels(const Utils::Environment &en
|
||||
models.append(modelId);
|
||||
}
|
||||
} else {
|
||||
logMessage(QString("Error fetching models: %1").arg(reply->errorString()));
|
||||
LOG_MESSAGE(QString("Error fetching models: %1").arg(reply->errorString()));
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LLMProvider.hpp"
|
||||
#include "llmcore/Provider.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class LMStudioProvider : public LLMProvider
|
||||
class LMStudioProvider : public LLMCore::Provider
|
||||
{
|
||||
public:
|
||||
LMStudioProvider();
|
||||
@ -32,7 +32,7 @@ public:
|
||||
QString url() const override;
|
||||
QString completionEndpoint() const override;
|
||||
QString chatEndpoint() const override;
|
||||
void prepareRequest(QJsonObject &request) override;
|
||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||
QList<QString> getInstalledModels(const Utils::Environment &env, const QString &url) override;
|
||||
};
|
||||
|
@ -25,8 +25,8 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QtCore/qeventloop.h>
|
||||
|
||||
#include "PromptTemplateManager.hpp"
|
||||
#include "QodeAssistUtils.hpp"
|
||||
#include "llmcore/PromptTemplateManager.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/PresetPromptsSettings.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
@ -53,23 +53,24 @@ QString OllamaProvider::chatEndpoint() const
|
||||
return "/api/chat";
|
||||
}
|
||||
|
||||
void OllamaProvider::prepareRequest(QJsonObject &request)
|
||||
void OllamaProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||
{
|
||||
auto &settings = Settings::presetPromptsSettings();
|
||||
auto &promptSettings = Settings::presetPromptsSettings();
|
||||
auto settings = promptSettings.getSettings(type);
|
||||
|
||||
QJsonObject options;
|
||||
options["num_predict"] = settings.maxTokens();
|
||||
options["temperature"] = settings.temperature();
|
||||
if (settings.useTopP())
|
||||
options["top_p"] = settings.topP();
|
||||
if (settings.useTopK())
|
||||
options["top_k"] = settings.topK();
|
||||
if (settings.useFrequencyPenalty())
|
||||
options["frequency_penalty"] = settings.frequencyPenalty();
|
||||
if (settings.usePresencePenalty())
|
||||
options["presence_penalty"] = settings.presencePenalty();
|
||||
options["num_predict"] = settings.maxTokens;
|
||||
options["temperature"] = settings.temperature;
|
||||
if (settings.useTopP)
|
||||
options["top_p"] = settings.topP;
|
||||
if (settings.useTopK)
|
||||
options["top_k"] = settings.topK;
|
||||
if (settings.useFrequencyPenalty)
|
||||
options["frequency_penalty"] = settings.frequencyPenalty;
|
||||
if (settings.usePresencePenalty)
|
||||
options["presence_penalty"] = settings.presencePenalty;
|
||||
request["options"] = options;
|
||||
request["keep_alive"] = settings.ollamaLivetime();
|
||||
request["keep_alive"] = settings.ollamaLivetime;
|
||||
}
|
||||
|
||||
bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedResponse)
|
||||
@ -85,7 +86,7 @@ bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedRe
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(line);
|
||||
if (doc.isNull()) {
|
||||
logMessage("Invalid JSON response from Ollama: " + QString::fromUtf8(line));
|
||||
LOG_MESSAGE("Invalid JSON response from Ollama: " + QString::fromUtf8(line));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -93,7 +94,7 @@ bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedRe
|
||||
|
||||
if (responseObj.contains("error")) {
|
||||
QString errorMessage = responseObj["error"].toString();
|
||||
logMessage("Error in Ollama response: " + errorMessage);
|
||||
LOG_MESSAGE("Error in Ollama response: " + errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -111,7 +112,7 @@ bool OllamaProvider::handleResponse(QNetworkReply *reply, QString &accumulatedRe
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logMessage("Unknown endpoint: " + endpoint);
|
||||
LOG_MESSAGE("Unknown endpoint: " + endpoint);
|
||||
}
|
||||
|
||||
if (responseObj.contains("done") && responseObj["done"].toBool()) {
|
||||
@ -146,7 +147,7 @@ QList<QString> OllamaProvider::getInstalledModels(const Utils::Environment &env,
|
||||
models.append(modelName);
|
||||
}
|
||||
} else {
|
||||
logMessage(QString("Error fetching models: %1").arg(reply->errorString()));
|
||||
LOG_MESSAGE(QString("Error fetching models: %1").arg(reply->errorString()));
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LLMProvider.hpp"
|
||||
#include "llmcore/Provider.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OllamaProvider : public LLMProvider
|
||||
class OllamaProvider : public LLMCore::Provider
|
||||
{
|
||||
public:
|
||||
OllamaProvider();
|
||||
@ -32,7 +32,7 @@ public:
|
||||
QString url() const override;
|
||||
QString completionEndpoint() const override;
|
||||
QString chatEndpoint() const override;
|
||||
void prepareRequest(QJsonObject &request) override;
|
||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||
QList<QString> getInstalledModels(const Utils::Environment &env, const QString &url) override;
|
||||
};
|
||||
|
@ -50,9 +50,10 @@ QString OpenAICompatProvider::chatEndpoint() const
|
||||
return "/v1/chat/completions";
|
||||
}
|
||||
|
||||
void OpenAICompatProvider::prepareRequest(QJsonObject &request)
|
||||
void OpenAICompatProvider::prepareRequest(QJsonObject &request, LLMCore::RequestType type)
|
||||
{
|
||||
auto &settings = Settings::presetPromptsSettings();
|
||||
auto &promptSettings = Settings::presetPromptsSettings();
|
||||
auto settings = promptSettings.getSettings(type);
|
||||
QJsonArray messages;
|
||||
|
||||
if (request.contains("system")) {
|
||||
@ -70,18 +71,18 @@ void OpenAICompatProvider::prepareRequest(QJsonObject &request)
|
||||
request["messages"] = std::move(messages);
|
||||
}
|
||||
|
||||
request["max_tokens"] = settings.maxTokens();
|
||||
request["temperature"] = settings.temperature();
|
||||
if (settings.useTopP())
|
||||
request["top_p"] = settings.topP();
|
||||
if (settings.useTopK())
|
||||
request["top_k"] = settings.topK();
|
||||
if (settings.useFrequencyPenalty())
|
||||
request["frequency_penalty"] = settings.frequencyPenalty();
|
||||
if (settings.usePresencePenalty())
|
||||
request["presence_penalty"] = settings.presencePenalty();
|
||||
request["max_tokens"] = settings.maxTokens;
|
||||
request["temperature"] = settings.temperature;
|
||||
if (settings.useTopP)
|
||||
request["top_p"] = settings.topP;
|
||||
if (settings.useTopK)
|
||||
request["top_k"] = settings.topK;
|
||||
if (settings.useFrequencyPenalty)
|
||||
request["frequency_penalty"] = settings.frequencyPenalty;
|
||||
if (settings.usePresencePenalty)
|
||||
request["presence_penalty"] = settings.presencePenalty;
|
||||
|
||||
const QString &apiKey = settings.apiKey.value();
|
||||
const QString &apiKey = settings.apiKey;
|
||||
if (!apiKey.isEmpty()) {
|
||||
request["api_key"] = apiKey;
|
||||
}
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LLMProvider.hpp"
|
||||
#include "llmcore/Provider.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
|
||||
class OpenAICompatProvider : public LLMProvider
|
||||
class OpenAICompatProvider : public LLMCore::Provider
|
||||
{
|
||||
public:
|
||||
OpenAICompatProvider();
|
||||
@ -32,7 +32,7 @@ public:
|
||||
QString url() const override;
|
||||
QString completionEndpoint() const override;
|
||||
QString chatEndpoint() const override;
|
||||
void prepareRequest(QJsonObject &request) override;
|
||||
void prepareRequest(QJsonObject &request, LLMCore::RequestType type) override;
|
||||
bool handleResponse(QNetworkReply *reply, QString &accumulatedResponse) override;
|
||||
QList<QString> getInstalledModels(const Utils::Environment &env, const QString &url) override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user