diff --git a/AiCoreUnitTest/Ollama2FacadeTest.cs b/AiCoreUnitTest/Ollama2FacadeTest.cs index 5298aaa92..4781039b1 100644 --- a/AiCoreUnitTest/Ollama2FacadeTest.cs +++ b/AiCoreUnitTest/Ollama2FacadeTest.cs @@ -30,6 +30,8 @@ namespace AiCoreUnitTest [TestMethod] public void SendMessage() { + var logger = ServiceLogger.GetRequestLogger(out string id); + // Build Payload var payload = new { @@ -39,10 +41,10 @@ namespace AiCoreUnitTest role = "user", message = "why is the sky blue?" } - } + }, + requestid = id }; - var logger = ServiceLogger.GetRequestLogger(); var response = Client.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger); Assert.IsTrue(response?.Success); diff --git a/AiCoreUnitTest/OllamaFacadeTest.cs b/AiCoreUnitTest/OllamaFacadeTest.cs index 7948d1b22..f616ce1c2 100644 --- a/AiCoreUnitTest/OllamaFacadeTest.cs +++ b/AiCoreUnitTest/OllamaFacadeTest.cs @@ -39,6 +39,7 @@ namespace AiCoreUnitTest public void SendMessage() { var client = GetClient(); + var logger = ServiceLogger.GetRequestLogger(out string id); // Build Payload var payload = new @@ -50,10 +51,10 @@ namespace AiCoreUnitTest message = "Say 'Hi'!" } }, - customerid = UserRightHelper.GetTenant() + customerid = UserRightHelper.GetTenant(), + requestid = id }; - var logger = ServiceLogger.GetRequestLogger(); var response = client.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger); Assert.IsTrue(response?.Success); diff --git a/Service/Core/BeWoServerPathHelper.cs b/Service/Core/BeWoServerPathHelper.cs index 48e26d795..91e32ae0b 100644 --- a/Service/Core/BeWoServerPathHelper.cs +++ b/Service/Core/BeWoServerPathHelper.cs @@ -1,4 +1,5 @@ using BeWo.Service.Plugins; +using BeWo.Service.Security; using System; using System.Collections.Generic; using System.IO; @@ -10,8 +11,10 @@ namespace BeWo.Service.Core { public static class BeWoServerPathHelper { - public static string GetUniqueRequestLogFile() + public static string GetUniqueRequestLogFile(out string id) { + id = null; + var folder_path = Path.Combine(getLogRootPath(), "ai", "requests"); Directory.CreateDirectory(folder_path); @@ -20,7 +23,9 @@ namespace BeWo.Service.Core if (file_name == null) return null; - return Path.Combine(folder_path, file_name + ".log"); + id = SecurityUtils.CreateRandomString(10); + + return Path.Combine(folder_path, $"{file_name}_{id}.log"); } public static string GetServiceLogFile() diff --git a/Service/Core/ServiceLogger.cs b/Service/Core/ServiceLogger.cs index e22ab4b75..a49775377 100644 --- a/Service/Core/ServiceLogger.cs +++ b/Service/Core/ServiceLogger.cs @@ -14,9 +14,9 @@ namespace BeWo.Service.Core { public static FileLogger CoreLogger { get; } = new FileLogger(BeWoServerPathHelper.GetServiceLogFile()); - public static FileLogger GetRequestLogger() + public static FileLogger GetRequestLogger(out string id) { - var filePath = BeWoServerPathHelper.GetUniqueRequestLogFile(); + var filePath = BeWoServerPathHelper.GetUniqueRequestLogFile(out id); if (filePath == null) throw new NotImplementedException("err98462"); diff --git a/Service/Plugins/AiFunctionService.cs b/Service/Plugins/AiFunctionService.cs index abc5c103e..93b6d1c45 100644 --- a/Service/Plugins/AiFunctionService.cs +++ b/Service/Plugins/AiFunctionService.cs @@ -88,6 +88,8 @@ namespace BeWo.Service.Plugins } } + var logger = ServiceLogger.GetRequestLogger(out string id); + var payload = new { model = "gemma3_12b_max_context:latest", @@ -104,10 +106,10 @@ namespace BeWo.Service.Plugins content = user_prompt }, }, - customerid = UserRightHelper.GetTenant() + customerid = UserRightHelper.GetTenant(), + requestid = id }; - var logger = ServiceLogger.GetRequestLogger(); var response = ServiceFacade.Ollama2ApiClient.SendAiMessageRequest(payload, out string message, out string model2, out int? duration, logger); return message; diff --git a/Service/Plugins/AiService2.cs b/Service/Plugins/AiService2.cs index 2beb3a88b..ea6c6fa4d 100644 --- a/Service/Plugins/AiService2.cs +++ b/Service/Plugins/AiService2.cs @@ -325,13 +325,15 @@ namespace BeWo.Service.Plugins var configModel = config.SelectedModel; var configModelName = config.SelectedModel.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() + customerid = UserRightHelper.GetTenant(), + requestid = id }; // Updated @@ -374,7 +376,6 @@ namespace BeWo.Service.Plugins // Send Request, wait for Response var dt_before_request = DateTime.Now; - var logger = ServiceLogger.GetRequestLogger(); var client = ServiceFacade.GetLLMApiClientByConfig(config.SelectedModel.ModelSource); var response = client.SendAiMessageRequest(payload, out var message2, out var model, out var duration, logger); diff --git a/Service/ServiceProxy/ServiceFacade.cs b/Service/ServiceProxy/ServiceFacade.cs index ca6c49720..c6969e3ab 100644 --- a/Service/ServiceProxy/ServiceFacade.cs +++ b/Service/ServiceProxy/ServiceFacade.cs @@ -31,7 +31,6 @@ namespace BeWo.Service.ServiceProxy private static readonly Lazy _XRechnungFacade = new Lazy(() => new XRechnungApiClient()); - public static OpenWebApiClient OpenWebApiClient => null; public static OllamaApiClient OllamaApiClient => _OllamaApiClient.Value; public static OllamaApiClient Ollama2ApiClient => _Ollama2ApiClient.Value; public static XRechnungApiClient XRechnung => _XRechnungFacade.Value; @@ -41,7 +40,7 @@ namespace BeWo.Service.ServiceProxy switch (aiModelSource) { case AiModelSource.openwebui: - return OpenWebApiClient; + throw new NotImplementedException(); case AiModelSource.ollama: return OllamaApiClient; case AiModelSource.ollama2: