using BeWo.Data.Access; 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; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AICore.Prompt.SystemPrompts; using BeWo.Service.Core; using BS.Shared.Extensions.CustomInterfaces; namespace BeWo.Service.Plugins { public class AiFunctionService { public AiFunctionDocResponse ExecuteAiFunctionServiceRecordDocumentation(AiFunctionDocRequest request) { // Request valideren ValidateDocRequest(request); // Request auswerten // DB Daten holen // DB Daten prüfen // Anfrage zusammensetzen var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request); var systemPromptFolderPath = PathHelper.GetAiSystemPromptPath(); var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath); var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context); var prompt_baustein_ref = request.AiPromptbaustein; var prompt_baustein_ref_oid = prompt_baustein_ref.Oid; var prompt_baustein_ref_ver = prompt_baustein_ref.Version; var prompt_baustein = DAOFactory.GenericDAO.LoadByID(prompt_baustein_ref_oid); ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, prompt_baustein); if (prompt_baustein.IsOrdner()) throw new Exception("prompt is folder"); if (prompt_baustein.IsKette()) throw new NotImplementedException(); if (prompt_baustein.Oid < 0) throw new NotImplementedException(); // Anfrage abschicken var result = getResult(system_prompt, prompt_baustein.Content); // Response auswerten // Eigene Response erstellen 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 }, } }; var logger = ServiceLogger.GetRequestLogger(); var response = ServiceFacade.OllamaApiClient.SendAiMessageRequest(payload, out string message, out string model, out int? duration, logger); return message; } private void ValidateDocRequest(AiFunctionDocRequest request) { //throw new NotImplementedException(); } } }