Request ID
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace BeWo.Service.ServiceProxy
|
||||
private static readonly Lazy<XRechnungApiClient> _XRechnungFacade = new Lazy<XRechnungApiClient>(()
|
||||
=> 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:
|
||||
|
||||
Reference in New Issue
Block a user