Cleanup
This commit is contained in:
@@ -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<IEnumerable<AiModel>> GetAiModelle();
|
||||
public abstract ApiResponse<string> SendAiMessageRequest(dynamic payload, out string message, out string model, out int? duration);
|
||||
}
|
||||
|
||||
@@ -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<IEnumerable<AiModel>> GetAiModelle()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace AiCoreUnitTest
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
OllamaUrl = "https://w2.owchat.de";
|
||||
OllamaUrl = "https://w2.ownchat.de";
|
||||
OllamaKey = "mu9ZPuUXJ4aVGLU1WL2RfPCeSMRmJREwyjVJBP7bHfSz8quZRqN7e7UwnwCDi8GZ";
|
||||
}
|
||||
|
||||
|
||||
@@ -260,10 +260,6 @@ namespace BeWo.ViewModel.View
|
||||
|
||||
IsSending = false;
|
||||
}
|
||||
private void Test()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private AiConversationVM InsertConverstion(AiConversationDC dc)
|
||||
{
|
||||
|
||||
@@ -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<string, string> Headers { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>();
|
||||
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<string, string> Headers { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> Parameters { get; set; } = new Dictionary<string, string>();
|
||||
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);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Führt einen Request aus, erwartet einen komplexen Datentyp: Schaue Verweise für Beispiele.
|
||||
/// </summary>
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user