Logging verbessert

This commit is contained in:
2026-03-09 12:40:29 +01:00
parent 652871cd52
commit 7b53c1e595
12 changed files with 80 additions and 18 deletions

View File

@@ -31,6 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\..\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=9.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Bcl.AsyncInterfaces.9.0.7\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>

View File

@@ -10,16 +10,21 @@ using System.Net;
using BeWo.ServerUtils.ApiFacade;
using BS.Shared;
using BS.Shared.Logger;
using log4net;
using System.Runtime.CompilerServices;
using BS.Shared.Core;
namespace AICore.Facade.LLM
{
public class OllamaApiClient : BaseLLMApiClient
{
private AiModelSource _aiModelSource;
private ILog _logger;
public OllamaApiClient(string base_url, string api_key, AiModelSource modelSource = AiModelSource.ollama) : base(base_url, api_key)
{
_aiModelSource = modelSource;
_logger = LoggerUtils.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
if (modelSource != AiModelSource.ollama && modelSource != AiModelSource.ollama2)
throw new NotImplementedException("err4548975");
@@ -29,6 +34,8 @@ namespace AICore.Facade.LLM
{
var models = new List<AiModelDC>();
_logger.Info($"GetModels: Hole aktuelle Modelle von '{_aiModelSource}'");
var response_format = new
{
models = new[]
@@ -50,11 +57,17 @@ namespace AICore.Facade.LLM
if (!response.Success)
{
_logger.Error(response);
_logger.Error(response.ToErrorString());
throw new NotImplementedException();
}
var data = response.Data.models.Select(x => new AiModelDC(_aiModelSource, x.name, x.details.max_context_size));
var log_str = string.Join("", data.Select(x => $"\r\n\t\t\t\t- {x.ToString()}"));
_logger.Info($"GetModels: Aktuelle Modelle von '{_aiModelSource}': {log_str}");
return ApiResponse<IEnumerable<AiModelDC>>.SuccessResponse(data);
}
@@ -68,7 +81,7 @@ namespace AICore.Facade.LLM
if(logger is object)
{
logger.Log(LogLevel.Debug, "Request:");
logger.Log(LogLevel.Debug, "Chat Request:");
logger.LogJson(LogLevel.Debug, _PostClientFacade.JsonObject);
}
@@ -101,7 +114,7 @@ namespace AICore.Facade.LLM
if(logger is object)
{
logger.Log(LogLevel.Debug, "Response:");
logger.Log(LogLevel.Debug, "Chat Response:");
logger.LogJson(LogLevel.Debug, response);
}