Ollama2 UnitTest

This commit is contained in:
2025-12-03 11:06:45 +01:00
parent ef6d2c49a1
commit 853d3035f7
3 changed files with 94 additions and 39 deletions

View File

@@ -49,6 +49,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Ollama2FacadeTest.cs" />
<Compile Include="OllamaFacadeTest.cs" />
<Compile Include="OpenWebUIFacadeTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -0,0 +1,54 @@
using AICore.Facade.LLM;
using BeWo.Service.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
using System;
using System.Net;
using System.Runtime.InteropServices;
namespace AiCoreUnitTest
{
[TestClass]
public class Ollama2FacadeTest
{
public OllamaApiClient Client { get; set; }
[TestInitialize]
public void TestInitialize()
{
var url = "https://ai3.ownsoft.de";
var key = "mu9ZPuUXJ4aVGLU1WL2RfPCeSMRmJREwyjVJBP7bHfSz8quZRqN7e7UwnwCDi8GZ";
Client = new OllamaApiClient(url, key, BS.Shared.AiModelSource.ollama2);
}
[TestMethod]
public void GetModels()
{
var response = Client.GetAiModelle();
Assert.IsTrue(response?.Success);
}
[TestMethod]
public void SendMessage()
{
// Build Payload
var payload = new
{
model = "llama3:latest",
messages = new[] {
new {
role = "user",
message = "Say 'Hi'!"
}
}
};
var logger = ServiceLogger.GetRequestLogger();
var response = Client.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger);
Assert.IsTrue(response?.Success);
}
}
}

View File

@@ -5,52 +5,52 @@ using System.Net;
namespace AiCoreUnitTest
{
[TestClass]
public class OpenWebUIFacadeTest
{
public string OpenWebUIUrl { get; set; }
public string OpenWebUIKey { get; set; }
//[TestClass]
//public class OpenWebUIFacadeTest
//{
// public string OpenWebUIUrl { get; set; }
// public string OpenWebUIKey { get; set; }
[TestInitialize]
public void TestInitialize()
{
OpenWebUIUrl = "https://owui1.ownsoft.de";
OpenWebUIKey = "sk-7f5d8c418630448dbe31ab1c7e8b100a";
}
// [TestInitialize]
// public void TestInitialize()
// {
// OpenWebUIUrl = "https://owui1.ownsoft.de";
// OpenWebUIKey = "sk-7f5d8c418630448dbe31ab1c7e8b100a";
// }
public OpenWebApiClient GetClient()
=> new OpenWebApiClient(OpenWebUIUrl, OpenWebUIKey);
// public OpenWebApiClient GetClient()
// => new OpenWebApiClient(OpenWebUIUrl, OpenWebUIKey);
[TestMethod]
public void GetModels()
{
var client = GetClient();
// [TestMethod]
// public void GetModels()
// {
// var client = GetClient();
var models = client.GetAiModelle();
// var models = client.GetAiModelle();
Assert.IsNotNull(models);
}
// Assert.IsNotNull(models);
// }
[TestMethod]
public void SendMessage()
{
var client = GetClient();
// [TestMethod]
// public void SendMessage()
// {
// var client = GetClient();
// Build Payload
var payload = new
{
model = "llama3.2:latest",
messages = new[] {
new {
role = "user",
content = "Say Hi!"
}
}
};
// // Build Payload
// var payload = new
// {
// model = "llama3.2:latest",
// messages = new[] {
// new {
// role = "user",
// content = "Say Hi!"
// }
// }
// };
var response = client.SendAiMessageRequest(payload, out string message, out string model, out int? duration);
// var response = client.SendAiMessageRequest(payload, out string message, out string model, out int? duration);
Assert.IsTrue(response?.Success);
}
}
// Assert.IsTrue(response?.Success);
// }
//}
}