fix: Add checking model support for tool calling (#350)

This commit is contained in:
Petr Mironychev
2026-05-17 21:27:18 +02:00
committed by GitHub
parent 6addcedfd0
commit 74c899c8c3
16 changed files with 334 additions and 18 deletions

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2024-2026 Petr Mironychev
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include "pluginllmcore/ContextData.hpp"
namespace QodeAssist::Templates {
inline bool appendOpenAIToolMessage(QJsonArray &messages, const PluginLLMCore::Message &msg)
{
if (!msg.toolCalls.isEmpty()) {
QJsonArray toolCalls;
for (const auto &call : msg.toolCalls) {
toolCalls.append(QJsonObject{
{"id", call.id},
{"type", "function"},
{"function",
QJsonObject{
{"name", call.name},
{"arguments",
QString::fromUtf8(
QJsonDocument(call.arguments).toJson(QJsonDocument::Compact))}}}});
}
QJsonObject toolMessage{{"role", "assistant"}, {"tool_calls", toolCalls}};
toolMessage["content"] = msg.content.isEmpty() ? QJsonValue() : QJsonValue(msg.content);
messages.append(toolMessage);
return true;
}
if (msg.role == QLatin1String("tool")) {
messages.append(QJsonObject{
{"role", "tool"}, {"tool_call_id", msg.toolCallId}, {"content", msg.content}});
return true;
}
return false;
}
} // namespace QodeAssist::Templates