mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-21 10:40:57 -04:00
refactor: Restructure project into sources/tests layout and dissolve PluginLLMCore
This commit is contained in:
121
sources/templates/MistralAI.hpp
Normal file
121
sources/templates/MistralAI.hpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Additional attribution terms under GPLv3 §7(b) apply — see LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "templates/PromptTemplate.hpp"
|
||||
#include "templates/ToolMessages.hpp"
|
||||
|
||||
namespace QodeAssist::Templates {
|
||||
|
||||
class MistralAIFim : public Templates::PromptTemplate
|
||||
{
|
||||
public:
|
||||
Templates::TemplateType type() const override { return Templates::TemplateType::FIM; }
|
||||
QString name() const override { return "Mistral AI FIM"; }
|
||||
QString endpoint() const override { return QStringLiteral("/v1/fim/completions"); }
|
||||
QStringList stopWords() const override { return QStringList(); }
|
||||
void prepareRequest(QJsonObject &request, const LLMCore::ContextData &context) const override
|
||||
{
|
||||
request["prompt"] = context.prefix.value_or("");
|
||||
request["suffix"] = context.suffix.value_or("");
|
||||
}
|
||||
QString description() const override
|
||||
{
|
||||
return "Template for MistralAI models with FIM support:\n\n"
|
||||
"{\n"
|
||||
" \"prompt\": \"<code prefix>\",\n"
|
||||
" \"suffix\": \"<code suffix>\"\n"
|
||||
"}\n\n"
|
||||
"Optimized for code completion with MistralAI models.";
|
||||
}
|
||||
bool isSupportProvider(Providers::ProviderID id) const override
|
||||
{
|
||||
switch (id) {
|
||||
case QodeAssist::Providers::ProviderID::MistralAI:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class MistralAIChat : public Templates::PromptTemplate
|
||||
{
|
||||
public:
|
||||
Templates::TemplateType type() const override { return Templates::TemplateType::Chat; }
|
||||
QString name() const override { return "Mistral AI Chat"; }
|
||||
QStringList stopWords() const override { return QStringList(); }
|
||||
bool supportsToolHistory() const override { return true; }
|
||||
|
||||
void prepareRequest(QJsonObject &request, const LLMCore::ContextData &context) const override
|
||||
{
|
||||
QJsonArray messages;
|
||||
|
||||
if (context.systemPrompt) {
|
||||
messages.append(
|
||||
QJsonObject{{"role", "system"}, {"content", context.systemPrompt.value()}});
|
||||
}
|
||||
|
||||
if (context.history) {
|
||||
for (const auto &msg : context.history.value()) {
|
||||
if (appendOpenAIToolMessage(messages, msg)) {
|
||||
continue;
|
||||
}
|
||||
if (msg.images && !msg.images->isEmpty()) {
|
||||
QJsonArray content;
|
||||
|
||||
if (!msg.content.isEmpty()) {
|
||||
content.append(QJsonObject{{"type", "text"}, {"text", msg.content}});
|
||||
}
|
||||
|
||||
for (const auto &image : msg.images.value()) {
|
||||
QJsonObject imageBlock;
|
||||
imageBlock["type"] = "image_url";
|
||||
|
||||
QJsonObject imageUrl;
|
||||
if (image.isUrl) {
|
||||
imageUrl["url"] = image.data;
|
||||
} else {
|
||||
imageUrl["url"] = QString("data:%1;base64,%2").arg(image.mediaType, image.data);
|
||||
}
|
||||
imageBlock["image_url"] = imageUrl;
|
||||
content.append(imageBlock);
|
||||
}
|
||||
|
||||
messages.append(QJsonObject{{"role", msg.role}, {"content", content}});
|
||||
} else {
|
||||
messages.append(QJsonObject{{"role", msg.role}, {"content", msg.content}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request["messages"] = messages;
|
||||
}
|
||||
QString description() const override
|
||||
{
|
||||
return "Template for MistralAI chat-capable models:\n\n"
|
||||
"{\n"
|
||||
" \"messages\": [\n"
|
||||
" {\"role\": \"system\", \"content\": \"<system prompt>\"},\n"
|
||||
" {\"role\": \"user\", \"content\": \"<user message>\"},\n"
|
||||
" {\"role\": \"assistant\", \"content\": \"<assistant response>\"}\n"
|
||||
" ]\n"
|
||||
"}\n\n"
|
||||
"Supports system messages, conversation history, and images.";
|
||||
}
|
||||
bool isSupportProvider(Providers::ProviderID id) const override
|
||||
{
|
||||
switch (id) {
|
||||
case QodeAssist::Providers::ProviderID::MistralAI:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Templates
|
||||
Reference in New Issue
Block a user