From 4ba5e4afc31d2879e3d2c0399bc715d43cf434fd Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Tue, 5 Aug 2025 14:45:25 +0200 Subject: [PATCH] Cleanup --- AICore/Facade/LLM/BaseLLMApiClient.cs | 9 ------ AICore/Facade/LLM/OllamaApiClient.cs | 24 ++++---------- AICore/Facade/LLM/OpenWebApiClient.cs | 11 +++---- AiCoreUnitTest/OllamaFacadeTest.cs | 2 +- .../View/AiConversationChatViewModel.cs | 4 --- Server/ApiFacade/Core/HttpClientFacade.cs | 31 ++++++++++--------- Server/ApiFacade/Core/JsonHttpClientFacade.cs | 4 +++ Server/ApiFacade/README.txt | 5 ++- 8 files changed, 37 insertions(+), 53 deletions(-) diff --git a/AICore/Facade/LLM/BaseLLMApiClient.cs b/AICore/Facade/LLM/BaseLLMApiClient.cs index 970c4240c..39860a8aa 100644 --- a/AICore/Facade/LLM/BaseLLMApiClient.cs +++ b/AICore/Facade/LLM/BaseLLMApiClient.cs @@ -15,15 +15,6 @@ namespace AICore.Facade.LLM { public abstract class BaseLLMApiClient { - public string BaseUrl { get; set; } - public string ApiKey { get; set; } - - protected BaseLLMApiClient(string base_url, string api_key) - { - base_url = BaseUrl; - ApiKey = api_key; - } - public abstract ApiResponse> GetAiModelle(); public abstract ApiResponse SendAiMessageRequest(dynamic payload, out string message, out string model, out int? duration); } diff --git a/AICore/Facade/LLM/OllamaApiClient.cs b/AICore/Facade/LLM/OllamaApiClient.cs index 5fc33c845..4fae59a9e 100644 --- a/AICore/Facade/LLM/OllamaApiClient.cs +++ b/AICore/Facade/LLM/OllamaApiClient.cs @@ -18,26 +18,14 @@ namespace AICore.Facade.LLM private protected readonly JsonHttpClientFacade _PostClientFacade; private protected readonly IApiErrorExtractor _ErrorExtractor; - public OllamaApiClient(string base_url, string api_key) : base(base_url, api_key) + public OllamaApiClient(string base_url, string api_key) { - var authorization = $"Bearer {api_key}"; - _GetClientFacade = new HttpClientFacade(base_url); - _GetClientFacade.SetToken(authorization); - _PostClientFacade = new JsonHttpClientFacade(base_url); - _PostClientFacade.SetToken(authorization); - _PostClientFacade.Timeout = TimeSpan.FromSeconds(300); + _GetClientFacade = new HttpClientFacade(base_url, api_key, false); + _PostClientFacade = new JsonHttpClientFacade(base_url, api_key, false) + { + Timeout = TimeSpan.FromSeconds(300) + }; _ErrorExtractor = new DefaultErrorExtractor(); - - try - { - var addresses = Dns.GetHostAddresses("w2.ownchat.de"); - foreach (var addr in addresses) - Console.WriteLine(addr); - } - catch (SocketException ex) - { - Console.WriteLine($"DNS resolution failed: {ex.Message}"); - } } public override ApiResponse> GetAiModelle() diff --git a/AICore/Facade/LLM/OpenWebApiClient.cs b/AICore/Facade/LLM/OpenWebApiClient.cs index 2778472e3..7fb04b7a9 100644 --- a/AICore/Facade/LLM/OpenWebApiClient.cs +++ b/AICore/Facade/LLM/OpenWebApiClient.cs @@ -20,12 +20,11 @@ namespace AICore.Facade.LLM public OpenWebApiClient(string base_url, string api_key) { - var authorization = $"Bearer {api_key}"; - _GetClientFacade = new HttpClientFacade(base_url); - _GetClientFacade.SetToken(authorization); - _PostClientFacade = new JsonHttpClientFacade(base_url); - _PostClientFacade.SetToken(authorization); - _PostClientFacade.Timeout = TimeSpan.FromSeconds(300); + _GetClientFacade = new HttpClientFacade(base_url, api_key); + _PostClientFacade = new JsonHttpClientFacade(base_url, api_key) + { + Timeout = TimeSpan.FromSeconds(300) + }; _ErrorExtractor = new DefaultErrorExtractor(); } diff --git a/AiCoreUnitTest/OllamaFacadeTest.cs b/AiCoreUnitTest/OllamaFacadeTest.cs index 761d8758e..58154443c 100644 --- a/AiCoreUnitTest/OllamaFacadeTest.cs +++ b/AiCoreUnitTest/OllamaFacadeTest.cs @@ -14,7 +14,7 @@ namespace AiCoreUnitTest [TestInitialize] public void TestInitialize() { - OllamaUrl = "https://w2.owchat.de"; + OllamaUrl = "https://w2.ownchat.de"; OllamaKey = "mu9ZPuUXJ4aVGLU1WL2RfPCeSMRmJREwyjVJBP7bHfSz8quZRqN7e7UwnwCDi8GZ"; } diff --git a/BeWo/ViewModel/View/AiConversationChatViewModel.cs b/BeWo/ViewModel/View/AiConversationChatViewModel.cs index 5a46a5bb6..afd0fba21 100644 --- a/BeWo/ViewModel/View/AiConversationChatViewModel.cs +++ b/BeWo/ViewModel/View/AiConversationChatViewModel.cs @@ -260,10 +260,6 @@ namespace BeWo.ViewModel.View IsSending = false; } - private void Test() - { - throw new NotImplementedException(); - } private AiConversationVM InsertConverstion(AiConversationDC dc) { diff --git a/Server/ApiFacade/Core/HttpClientFacade.cs b/Server/ApiFacade/Core/HttpClientFacade.cs index f86a911d6..9cda67390 100644 --- a/Server/ApiFacade/Core/HttpClientFacade.cs +++ b/Server/ApiFacade/Core/HttpClientFacade.cs @@ -21,15 +21,6 @@ namespace BeWo.Server.ApiFacade.Core { public class HttpClientFacade { - public bool DirectConnect { get; private set; } - public string Base_Url { get; private set; } - public HttpMethod Method { get; set; } = HttpMethod.Get; - public Dictionary Headers { get; set; } = new Dictionary(); - public Dictionary Parameters { get; set; } = new Dictionary(); - public string ContentType { get; set; } = "application/x-www-form-urlencoded"; - public Encoding Encoding { get; private set; } = Encoding.UTF8; - public TimeSpan Timeout { get; private set; } = TimeSpan.FromSeconds(30); - public HttpClientFacade(string base_url, string api_key, bool directConntect = true) { if (string.IsNullOrEmpty(base_url)) @@ -43,6 +34,17 @@ namespace BeWo.Server.ApiFacade.Core DirectConnect = directConntect; } + public bool DirectConnect { get; private set; } + public string Base_Url { get; private set; } + + public HttpMethod Method { get; set; } = HttpMethod.Get; + public Dictionary Headers { get; set; } = new Dictionary(); + public Dictionary Parameters { get; set; } = new Dictionary(); + public string ContentType { get; set; } = "application/x-www-form-urlencoded"; + public Encoding Encoding { get; set; } = Encoding.UTF8; + public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30); + + /// /// Führt einen Request aus, erwartet einen komplexen Datentyp: Schaue Verweise für Beispiele. /// @@ -147,6 +149,10 @@ namespace BeWo.Server.ApiFacade.Core { await checkForDirect(request).ConfigureAwait(false); + // Add headers + foreach (var header in Headers) + request.Headers.TryAddWithoutValidation(header.Key, header.Value); + // Add body if POST or PUT if (Method == HttpMethod.Post || Method == HttpMethod.Put) { @@ -190,15 +196,12 @@ namespace BeWo.Server.ApiFacade.Core // Optional: Logging des Fehlers Console.WriteLine($"DNS resolution failed for {host}: {ex.Message}"); } - - // Add headers - foreach (var header in Headers) - request.Headers.TryAddWithoutValidation(header.Key, header.Value); } - private void SetToken(string token) + private void SetToken(string api_key) { var key = nameof(HttpRequestHeader.Authorization); + var token = $"Bearer {api_key}"; if (Headers.ContainsKey(key)) { diff --git a/Server/ApiFacade/Core/JsonHttpClientFacade.cs b/Server/ApiFacade/Core/JsonHttpClientFacade.cs index 41b5af14c..f1081ea63 100644 --- a/Server/ApiFacade/Core/JsonHttpClientFacade.cs +++ b/Server/ApiFacade/Core/JsonHttpClientFacade.cs @@ -29,6 +29,10 @@ namespace BeWo.Server.ApiFacade.Core { await checkForDirect(request).ConfigureAwait(false); + // Add headers + foreach (var header in Headers) + request.Headers.TryAddWithoutValidation(header.Key, header.Value); + // Add body if POST or PUT if (Method == HttpMethod.Post || Method == HttpMethod.Put) { diff --git a/Server/ApiFacade/README.txt b/Server/ApiFacade/README.txt index e1219c70b..9621956b7 100644 --- a/Server/ApiFacade/README.txt +++ b/Server/ApiFacade/README.txt @@ -1,4 +1,7 @@ -Hallo zusammen! Dies ist eine kleine Info über das Projekt. +Betreff: Projektübersicht: API-Kommunikations-Facade + + +Hallo zusammen! Dies ist eine kleine Info über das Projekt. Ich habe mir dieses Projekt auf der selben Ebenen wie Data gedacht. Data: ist ein Projekt, was speziell für die Datenbank Logik dient.