2025-11-28 14:54:24 +01:00
|
|
|
|
using BeWo.Data.Access;
|
2025-11-27 14:17:54 +01:00
|
|
|
|
using BeWo.Data.Entities;
|
|
|
|
|
|
using BeWo.Service.ServiceProxy;
|
|
|
|
|
|
using BeWo.Service.ServiceUtils;
|
|
|
|
|
|
using BS.Shared;
|
|
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
using BS.Shared.DataContracts.Feature.AI;
|
|
|
|
|
|
using BS.Shared.DataContracts.Feature.AI.Functions.ServiceRecords;
|
|
|
|
|
|
using DevExpress.DataAccess.Native.Web;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using RestSharp.Validation;
|
2025-11-24 15:47:45 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-12-04 15:06:39 +01:00
|
|
|
|
using AICore.Prompt.SystemPrompts;
|
2025-11-28 14:54:24 +01:00
|
|
|
|
using BeWo.Service.Core;
|
2025-11-24 15:47:45 +01:00
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Service.Plugins
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AiFunctionService
|
|
|
|
|
|
{
|
|
|
|
|
|
public AiFunctionDocResponse ExecuteAiFunctionServiceRecordDocumentation(AiFunctionDocRequest request)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Request valideren
|
2025-11-27 14:17:54 +01:00
|
|
|
|
ValidateDocRequest(request);
|
2025-11-24 15:47:45 +01:00
|
|
|
|
|
|
|
|
|
|
// Request auswerten
|
|
|
|
|
|
// DB Daten holen
|
|
|
|
|
|
// DB Daten prüfen
|
|
|
|
|
|
// Anfrage zusammensetzen
|
2025-11-27 14:17:54 +01:00
|
|
|
|
var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request);
|
|
|
|
|
|
|
2025-12-04 15:06:39 +01:00
|
|
|
|
var systemPromptFolderPath = PathHelper.GetAiSystemPromptPath();
|
|
|
|
|
|
var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath);
|
|
|
|
|
|
var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context);
|
2025-11-27 14:17:54 +01:00
|
|
|
|
|
|
|
|
|
|
var user_prompt = request.AiPromptbaustein;
|
|
|
|
|
|
var user_prompt_oid = user_prompt.Oid;
|
|
|
|
|
|
var user_prompt_ver = user_prompt.Version;
|
|
|
|
|
|
|
|
|
|
|
|
var predefined = new PredefinedAiPromptbausteine();
|
|
|
|
|
|
var prompts = predefined.GetAllPromptbausteine();
|
2025-12-08 15:39:16 +01:00
|
|
|
|
var prompt = prompts.First(x => x.Oid == user_prompt_oid).Content;
|
2025-11-24 15:47:45 +01:00
|
|
|
|
|
|
|
|
|
|
// Anfrage abschicken
|
2025-11-27 14:17:54 +01:00
|
|
|
|
var result = getResult(system_prompt, prompt);
|
2025-11-24 15:47:45 +01:00
|
|
|
|
|
|
|
|
|
|
// Response auswerten
|
|
|
|
|
|
|
|
|
|
|
|
// Eigene Response erstellen
|
2025-11-27 14:17:54 +01:00
|
|
|
|
var response = new AiFunctionDocResponse();
|
|
|
|
|
|
response.Result = result;
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string getResult(string system, string user_prompt)
|
|
|
|
|
|
{
|
|
|
|
|
|
var payload = new
|
|
|
|
|
|
{
|
|
|
|
|
|
model = "gemma3_12b-max-context:latest",
|
|
|
|
|
|
messages = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new
|
|
|
|
|
|
{
|
|
|
|
|
|
role = "System",
|
|
|
|
|
|
content = system
|
|
|
|
|
|
},
|
|
|
|
|
|
new
|
|
|
|
|
|
{
|
|
|
|
|
|
role = "User",
|
|
|
|
|
|
content = user_prompt
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-02 15:40:12 +01:00
|
|
|
|
var logger = ServiceLogger.GetRequestLogger();
|
|
|
|
|
|
var response = ServiceFacade.OllamaApiClient.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger);
|
2025-11-24 15:47:45 +01:00
|
|
|
|
|
2025-11-27 14:17:54 +01:00
|
|
|
|
return message;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ValidateDocRequest(AiFunctionDocRequest request)
|
|
|
|
|
|
{
|
|
|
|
|
|
//throw new NotImplementedException();
|
2025-11-24 15:47:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|