File-Upload: Attachments-Tabelle, Base64-Speicherung, Frontend mit Drag&Drop/Paste/Preview, Error-Handling Fix
This commit is contained in:
1 parent
680f1d6fe2
commit
1271c9c651
11 files changed
+513
-11
No files matched your search
@@ -104,20 +104,57 @@ public static class ChatEndpoint
|
||||
|
||||
var messages = new List<object>();
|
||||
foreach (var msg in body.Messages)
|
||||
messages.Add(new { role = msg.Role, content = msg.Content });
|
||||
{
|
||||
// Content bereinigen: interne Felder (_file_name) entfernen
|
||||
JsonElement content = msg.Content;
|
||||
if (msg.Content.ValueKind == System.Text.Json.JsonValueKind.Array)
|
||||
{
|
||||
var node = System.Text.Json.Nodes.JsonNode.Parse(msg.Content.GetRawText());
|
||||
foreach (var block in node.AsArray())
|
||||
{
|
||||
if (block is System.Text.Json.Nodes.JsonObject obj)
|
||||
obj.Remove("_file_name");
|
||||
}
|
||||
content = JsonSerializer.Deserialize<JsonElement>(node.ToJsonString());
|
||||
}
|
||||
|
||||
messages.Add(new Dictionary<string, JsonElement>
|
||||
{
|
||||
["role"] = JsonSerializer.Deserialize<JsonElement>($"\"{msg.Role}\""),
|
||||
["content"] = content
|
||||
});
|
||||
}
|
||||
|
||||
// Nur die letzte User-Message speichern (= die neue)
|
||||
var lastUserMsg = body.Messages.LastOrDefault(m => m.Role == "user");
|
||||
if (lastUserMsg != null)
|
||||
{
|
||||
await db.SaveMessage(new MessageRecord
|
||||
var textContent = lastUserMsg.GetTextContent();
|
||||
var attachmentInfos = lastUserMsg.GetAttachments();
|
||||
var attachmentBlocks = lastUserMsg.GetAttachmentBlocks();
|
||||
|
||||
var messageId = await db.SaveMessage(new MessageRecord
|
||||
{
|
||||
ChainId = chainId,
|
||||
Iteration = 0,
|
||||
Role = "user",
|
||||
Type = "text",
|
||||
Content = lastUserMsg.Content
|
||||
Content = textContent,
|
||||
AttachmentCount = attachmentBlocks.Count
|
||||
});
|
||||
|
||||
// Attachments separat speichern
|
||||
foreach (var block in attachmentBlocks)
|
||||
{
|
||||
await db.SaveAttachment(new AttachmentRecord
|
||||
{
|
||||
MessageId = messageId,
|
||||
Type = block.Type,
|
||||
MediaType = block.MediaType,
|
||||
FileName = block.FileName,
|
||||
Data = block.Data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var systemPrompt = new List<object>
|
||||
|
||||
Reference in new issue
Block a user