| 128 | } |
| 129 | |
| 130 | ChatModel::Message ChatSerializer::deserializeMessage( |
| 131 | const QJsonObject &json, const QString &chatFilePath) |
| 132 | { |
| 133 | ChatModel::Message message; |
| 134 | message.role = static_cast<ChatModel::ChatRole>(json["role"].toInt()); |
| 135 | message.content = json["content"].toString(); |
| 136 | message.id = json["id"].toString(); |
| 137 | message.isRedacted = json["isRedacted"].toBool(false); |
| 138 | message.signature = json["signature"].toString(); |
| 139 | message.toolName = json["toolName"].toString(); |
| 140 | message.toolArguments = json["toolArguments"].toObject(); |
| 141 | message.toolResult = json["toolResult"].toString(); |
| 142 | |
| 143 | if (json.contains("attachments")) { |
| 144 | QJsonArray attachmentsArray = json["attachments"].toArray(); |
| 145 | for (const auto &attachmentValue : attachmentsArray) { |
| 146 | QJsonObject attachmentObj = attachmentValue.toObject(); |
| 147 | Context::ContentFile attachment; |
| 148 | attachment.filename = attachmentObj["fileName"].toString(); |
| 149 | attachment.content = attachmentObj["storedPath"].toString(); |
| 150 | message.attachments.append(attachment); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if (json.contains("images")) { |
| 155 | QJsonArray imagesArray = json["images"].toArray(); |
| 156 | for (const auto &imageValue : imagesArray) { |
| 157 | QJsonObject imageObj = imageValue.toObject(); |
| 158 | ChatModel::ImageAttachment image; |
| 159 | image.fileName = imageObj["fileName"].toString(); |
| 160 | image.storedPath = imageObj["storedPath"].toString(); |
| 161 | image.mediaType = imageObj["mediaType"].toString(); |
| 162 | message.images.append(image); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (json.contains("usage")) { |
| 167 | const QJsonObject usageObj = json["usage"].toObject(); |
| 168 | message.promptTokens = usageObj["promptTokens"].toInt(); |
| 169 | message.completionTokens = usageObj["completionTokens"].toInt(); |
| 170 | message.cachedPromptTokens = usageObj["cachedPromptTokens"].toInt(); |
| 171 | message.reasoningTokens = usageObj["reasoningTokens"].toInt(); |
| 172 | } |
| 173 | |
| 174 | return message; |
| 175 | } |
| 176 | |
| 177 | QJsonObject ChatSerializer::serializeChat(const ChatModel *model, const QString &chatFilePath) |
| 178 | { |