64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
using AICore.Facade.LLM;
|
|
using BeWo.Data.Security;
|
|
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 OllamaFacadeTest
|
|
{
|
|
public string OllamaUrl { get; set; }
|
|
public string OllamaKey { get; set; }
|
|
|
|
[TestInitialize]
|
|
public void TestInitialize()
|
|
{
|
|
OllamaUrl = "https://ai2.ownsoft.de";
|
|
OllamaKey = "mu9ZPuUXJ4aVGLU1WL2RfPCeSMRmJREwyjVJBP7bHfSz8quZRqN7e7UwnwCDi8GZ";
|
|
}
|
|
|
|
public OllamaApiClient GetClient()
|
|
=> new OllamaApiClient(OllamaUrl, OllamaKey);
|
|
|
|
[TestMethod]
|
|
public void GetModels()
|
|
{
|
|
var client = GetClient();
|
|
|
|
var response = client.GetAiModelle();
|
|
|
|
Assert.IsTrue(response?.Success);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SendMessage()
|
|
{
|
|
var client = GetClient();
|
|
var logger = ServiceLogger.GetRequestLogger(out string id);
|
|
|
|
// Build Payload
|
|
var payload = new
|
|
{
|
|
model = "llama3:latest",
|
|
messages = new[] {
|
|
new {
|
|
role = "user",
|
|
message = "Say 'Hi'!"
|
|
}
|
|
},
|
|
customerid = UserRightHelper.GetTenant(),
|
|
requestid = id
|
|
};
|
|
|
|
var response = client.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger);
|
|
|
|
Assert.IsTrue(response?.Success);
|
|
}
|
|
}
|
|
}
|