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

@@ -15,6 +15,7 @@ public:
PluginLLMCore::TemplateType type() const override { return PluginLLMCore::TemplateType::Chat; }
QString name() const override { return "Claude"; }
QStringList stopWords() const override { return QStringList(); }
bool supportsToolHistory() const override { return true; }
void prepareRequest(QJsonObject &request, const PluginLLMCore::ContextData &context) const override
{
QJsonArray messages;
@@ -24,9 +25,48 @@ public:
}
if (context.history) {
int toolResultUserIdx = -1;
for (const auto &msg : context.history.value()) {
if (msg.role == "system") continue;
if (!msg.toolCalls.isEmpty()) {
toolResultUserIdx = -1;
QJsonArray content;
if (!msg.content.isEmpty()) {
content.append(QJsonObject{{"type", "text"}, {"text", msg.content}});
}
for (const auto &call : msg.toolCalls) {
content.append(QJsonObject{
{"type", "tool_use"},
{"id", call.id},
{"name", call.name},
{"input", call.arguments}});
}
messages.append(QJsonObject{{"role", "assistant"}, {"content", content}});
continue;
}
if (msg.role == "tool") {
QJsonObject resultBlock{
{"type", "tool_result"},
{"tool_use_id", msg.toolCallId},
{"content", msg.content}};
if (toolResultUserIdx >= 0) {
QJsonObject userMsg = messages[toolResultUserIdx].toObject();
QJsonArray content = userMsg["content"].toArray();
content.append(resultBlock);
userMsg["content"] = content;
messages[toolResultUserIdx] = userMsg;
} else {
messages.append(QJsonObject{
{"role", "user"}, {"content", QJsonArray{resultBlock}}});
toolResultUserIdx = messages.size() - 1;
}
continue;
}
toolResultUserIdx = -1;
if (msg.isThinking) {
// Claude API requires signature for thinking blocks
if (msg.signature.isEmpty()) {