From ced8dc52bf42ba34d674a0ecdf86531fa7865b3f Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Tue, 16 Jun 2026 11:45:25 +0200 Subject: [PATCH] =?UTF-8?q?Bug:=20UserNachricht=20wird=20nicht=20hinzugef?= =?UTF-8?q?=C3=BCgt=20vor=20Absenden=20Bug:=20SystemPrompt=20werden=20mehr?= =?UTF-8?q?fach=20gesendet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Plugins/AiService2.cs | 42 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Service/Plugins/AiService2.cs b/Service/Plugins/AiService2.cs index b6fb075c9..0dc4ea213 100644 --- a/Service/Plugins/AiService2.cs +++ b/Service/Plugins/AiService2.cs @@ -408,15 +408,6 @@ namespace BeWo.Service.Plugins var configModelName = configModel.ModelName; var logger = ServiceLogger.GetRequestLogger(out string id); - // Build Payload - var payload = new - { - model = configModelName, - messages = conv.Messages.Select(m => new { role = m.Role.ToString().ToLower(), content = m.Message }), - customerid = UserRightHelper.GetTenant(), - requestid = id - }; - // Updated conv.Updated = DateTime.Now; @@ -429,19 +420,48 @@ namespace BeWo.Service.Plugins conv.Messages.Add(user_msg); + // Build Payload + var messages2send = new List(); + bool systemPromptAdded = false; + foreach (var msg in conv.Messages) + { + if (msg.Role == AiConversationMessageRole.System) + { + if (systemPromptAdded) + continue; + + systemPromptAdded = true; + } + + messages2send.Add(msg); + } + + if (!systemPromptAdded) + { + throw new Exception("sp not found - invalid request"); + } + + var payload = new + { + model = configModelName, + messages = messages2send.Select(m => new { role = m.Role.ToString().ToLower(), content = m.Message }).ToList(), + customerid = UserRightHelper.GetTenant(), + requestid = id + }; + // Check Token Size if (-1 < configModel.Value) { if (conv.Messages.Count <= 2) { - if (!AiUtils.CheckUserFirstMessageContextSize(conv.Messages.Select(x => x.Message), configModelName, configModel.Value, out var error)) + if (!AiUtils.CheckUserFirstMessageContextSize(messages2send.Select(x => x.Message), configModelName, configModel.Value, out var error)) { throw new BeWoNotImplementedException(error); } } else { - if (!AiUtils.CheckUserAllMessageContextSize(conv.Messages.Select(x => x.Message), configModelName, configModel.Value, out var error)) + if (!AiUtils.CheckUserAllMessageContextSize(messages2send.Select(x => x.Message), configModelName, configModel.Value, out var error)) { throw new BeWoNotImplementedException(error); }