AICore abkapseln

This commit is contained in:
2025-09-08 15:17:51 +02:00
parent 3c7d953d67
commit 4acad3adaf
62 changed files with 202 additions and 130 deletions

View File

@@ -15,6 +15,7 @@ using BeWo.Service.Core;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Invoicing;
using BeWo.Service.ServiceContracts;
using BeWo.Service.ServiceImplementations;
using BeWo.Service.ServiceProxy;
using BS.Shared;
using BS.Shared.Core;
@@ -265,16 +266,19 @@ namespace BeWo.Service.Plugins
return models;
}
protected virtual AiConversation createAiConversation(AiContextType uicontext, Dictionary<TableID, IDataContract[]> context, long modell_oid, AiDataContextType context_Type)
protected virtual AiConversation createAiConversation(AiContextType uicontext, Dictionary<TableID, long[]> context_reference, long modell_oid, AiDataContextType context_Type)
{
var current_user = UserRightHelper.GetLoggedInUserWithOid();
var factory = new AiPromptFactory();
var system_prompt = factory.CreateSystemInstructions(uicontext, context, context_Type);
loadContext(uicontext, context_reference, out var context_loaded);
var system_prompt = factory.CreateSystemInstructions(uicontext, context_loaded, context_Type);
var conv = new AiConversation();
conv.Created = DateTime.Now;
conv.ContextBeWoObjects = MapperFactory.AiConversation.Parse(context);
// RETODO Muss noch bzgl Sicherheit geprüft werden.
conv.ContextBeWoObjects = MapperFactory.AiConversation.Parse(context_reference);
conv.Displayname = "Neue Unterhaltung";
conv.Messages = new List<AiConversationMessage>();
conv.Modell = DAOFactory.GenericDAO.LoadByID<AiModel>(modell_oid);
@@ -373,5 +377,51 @@ namespace BeWo.Service.Plugins
return new AiConversationMessageDC[] { user_msg_dc, assi_msg_dc };
}
protected virtual IEnumerable<IDataContract> loadContext(AiContextType uicontext, Dictionary<TableID, long[]> context_reference)
{
switch (uicontext)
{
case AiContextType.SupportConceptNavigation:
return new CustomerServiceImp().GetAllAuthorizedCompactSupportConcepts()
.Where(x => oidsContainsOid(context_reference[TableID.SupportConcept], x.SupportConceptOid));
case AiContextType.CustomerNavigation:
return new CustomerServiceImp().GetAllAuthorizedCompactCustomers()
.Where(x => oidsContainsOid(context_reference[TableID.Customer], x.CustomerOid));
case AiContextType.PersonNavigation:
return new CustomerServiceImp().GetAllAuthorizedCompactPersons()
.Where(x => oidsContainsOid(context_reference[TableID.Person], x.PersonOid));
case AiContextType.EmployeeNavigation:
return new EmployeeServiceImp().GetAllCompactEmployees()
.Where(x => oidsContainsOid(context_reference[TableID.Employee], x.EmployeeOid));
case AiContextType.OrganisationNavigation:
return new CustomerServiceImp().GetAllOrganisationsCompact()
.Where(x => oidsContainsOid(context_reference[TableID.Organisation], x.OrganisationOid));
case AiContextType.ServiceRecord:
break;
case AiContextType.CustomerDetail:
break;
case AiContextType.PersonDetail:
break;
case AiContextType.EmployeeDetail:
break;
case AiContextType.OrganisationDetail:
break;
case AiContextType.SupportConceptDetail:
break;
default:
break;
}
throw new NotImplementedException();
}
private bool oidsContainsOid(long[] oids, long oid)
{
if(oids == null || oids.Length == 0)
return false;
return oids.Contains(oid);
}
}
}