mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-30 22:43:00 -05:00
fix: Add signature to chat history
This commit is contained in:
@ -44,6 +44,11 @@ public:
|
||||
if (msg.role == "system") continue;
|
||||
|
||||
if (msg.isThinking) {
|
||||
// Claude API requires signature for thinking blocks
|
||||
if (msg.signature.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QJsonArray content;
|
||||
QJsonObject thinkingBlock;
|
||||
thinkingBlock["type"] = msg.isRedacted ? "redacted_thinking" : "thinking";
|
||||
@ -57,9 +62,7 @@ public:
|
||||
if (!msg.isRedacted) {
|
||||
thinkingBlock["thinking"] = thinkingText;
|
||||
}
|
||||
if (!msg.signature.isEmpty()) {
|
||||
thinkingBlock["signature"] = msg.signature;
|
||||
}
|
||||
thinkingBlock["signature"] = msg.signature;
|
||||
content.append(thinkingBlock);
|
||||
|
||||
messages.append(QJsonObject{{"role", "assistant"}, {"content", content}});
|
||||
|
||||
@ -46,36 +46,58 @@ public:
|
||||
QJsonObject content;
|
||||
QJsonArray parts;
|
||||
|
||||
if (!msg.content.isEmpty()) {
|
||||
parts.append(QJsonObject{{"text", msg.content}});
|
||||
}
|
||||
|
||||
if (msg.images && !msg.images->isEmpty()) {
|
||||
for (const auto &image : msg.images.value()) {
|
||||
QJsonObject imagePart;
|
||||
|
||||
if (image.isUrl) {
|
||||
QJsonObject fileData;
|
||||
fileData["mime_type"] = image.mediaType;
|
||||
fileData["file_uri"] = image.data;
|
||||
imagePart["file_data"] = fileData;
|
||||
} else {
|
||||
QJsonObject inlineData;
|
||||
inlineData["mime_type"] = image.mediaType;
|
||||
inlineData["data"] = image.data;
|
||||
imagePart["inline_data"] = inlineData;
|
||||
}
|
||||
|
||||
parts.append(imagePart);
|
||||
if (msg.isThinking) {
|
||||
if (!msg.content.isEmpty()) {
|
||||
QJsonObject thinkingPart;
|
||||
thinkingPart["text"] = msg.content;
|
||||
thinkingPart["thought"] = true;
|
||||
parts.append(thinkingPart);
|
||||
}
|
||||
|
||||
if (!msg.signature.isEmpty()) {
|
||||
QJsonObject signaturePart;
|
||||
signaturePart["thoughtSignature"] = msg.signature;
|
||||
parts.append(signaturePart);
|
||||
}
|
||||
|
||||
if (parts.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
content["role"] = "model";
|
||||
} else {
|
||||
if (!msg.content.isEmpty()) {
|
||||
parts.append(QJsonObject{{"text", msg.content}});
|
||||
}
|
||||
|
||||
if (msg.images && !msg.images->isEmpty()) {
|
||||
for (const auto &image : msg.images.value()) {
|
||||
QJsonObject imagePart;
|
||||
|
||||
if (image.isUrl) {
|
||||
QJsonObject fileData;
|
||||
fileData["mime_type"] = image.mediaType;
|
||||
fileData["file_uri"] = image.data;
|
||||
imagePart["file_data"] = fileData;
|
||||
} else {
|
||||
QJsonObject inlineData;
|
||||
inlineData["mime_type"] = image.mediaType;
|
||||
inlineData["data"] = image.data;
|
||||
imagePart["inline_data"] = inlineData;
|
||||
}
|
||||
|
||||
parts.append(imagePart);
|
||||
}
|
||||
}
|
||||
|
||||
QString role = msg.role;
|
||||
if (role == "assistant") {
|
||||
role = "model";
|
||||
}
|
||||
|
||||
content["role"] = role;
|
||||
}
|
||||
|
||||
QString role = msg.role;
|
||||
if (role == "assistant") {
|
||||
role = "model";
|
||||
}
|
||||
|
||||
content["role"] = role;
|
||||
content["parts"] = parts;
|
||||
contents.append(content);
|
||||
}
|
||||
@ -95,11 +117,15 @@ public:
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"role\": \"model\",\n"
|
||||
" \"parts\": [{\"text\": \"<assistant response>\"}]\n"
|
||||
" \"parts\": [\n"
|
||||
" {\"text\": \"<thinking>\", \"thought\": true},\n"
|
||||
" {\"thoughtSignature\": \"<signature>\"},\n"
|
||||
" {\"text\": \"<assistant response>\"}\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
"}\n\n"
|
||||
"Supports proper role mapping, including model/user roles.";
|
||||
"Supports proper role mapping (model/user roles), images, and thinking blocks.";
|
||||
}
|
||||
|
||||
bool isSupportProvider(LLMCore::ProviderID id) const override
|
||||
|
||||
Reference in New Issue
Block a user