Alte Logik + SamplesCount
This commit is contained in:
@@ -39,6 +39,8 @@ namespace BeWo.Data.Entities
|
|||||||
|
|
||||||
public virtual string PromptId { get; set; }
|
public virtual string PromptId { get; set; }
|
||||||
|
|
||||||
|
public virtual int SamplesCount { get; set; }
|
||||||
|
|
||||||
public virtual AiActionType ActionType { get; set; }
|
public virtual AiActionType ActionType { get; set; }
|
||||||
|
|
||||||
public virtual IList<Employee> UserFavorites { get; set;} = new List<Employee>();
|
public virtual IList<Employee> UserFavorites { get; set;} = new List<Employee>();
|
||||||
@@ -69,12 +71,13 @@ namespace BeWo.Data.Entities
|
|||||||
x.Description == ent.Description &&
|
x.Description == ent.Description &&
|
||||||
x.OwnsoftRefLink == ent.OwnsoftRefLink &&
|
x.OwnsoftRefLink == ent.OwnsoftRefLink &&
|
||||||
x.Prompt == ent.Prompt &&
|
x.Prompt == ent.Prompt &&
|
||||||
x.ActionType == ent.ActionType;
|
x.ActionType == ent.ActionType &&
|
||||||
|
x.SamplesCount == ent.SamplesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetHashCode(AiPromptbausteinPrompt obj)
|
public int GetHashCode(AiPromptbausteinPrompt obj)
|
||||||
{
|
{
|
||||||
return (obj.PromptId, obj.ActionType, obj.Title, obj.Description, obj.OwnsoftRefLink, obj.Prompt).GetHashCode();
|
return (obj.PromptId, obj.ActionType, obj.Title, obj.Description, obj.OwnsoftRefLink, obj.Prompt, obj.SamplesCount).GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,4 +96,7 @@ CREATE TABLE `aipromptbausteinfolder2empshare` (
|
|||||||
PRIMARY KEY (`AiPromptbausteinFolderOid`,`EmployeeOid`),
|
PRIMARY KEY (`AiPromptbausteinFolderOid`,`EmployeeOid`),
|
||||||
CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_AIFOLDER` FOREIGN KEY (`AiPromptbausteinFolderOid`) REFERENCES `aipromptbausteinfolder` (`Oid`),
|
CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_AIFOLDER` FOREIGN KEY (`AiPromptbausteinFolderOid`) REFERENCES `aipromptbausteinfolder` (`Oid`),
|
||||||
CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_APPUSER` FOREIGN KEY (`EmployeeOid`) REFERENCES `employee` (`Oid`)
|
CONSTRAINT `FK_AIPROMPTBAUSTEIN2EMPSHARE_APPUSER` FOREIGN KEY (`EmployeeOid`) REFERENCES `employee` (`Oid`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
|
ALTER TABLE `aipromptbausteinprompt`
|
||||||
|
ADD COLUMN `SamplesCount` INT NOT NULL DEFAULT 0 AFTER `ActionType`;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ namespace BeWo.Service.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetAiSystemPromptPath()
|
public static string GetAiSystemPromptPath()
|
||||||
=> Path.Combine(getRoot(), "AI", "systemPrompts");
|
=> Path.Combine(getRoot(), "AI", "systemPrompts");
|
||||||
public static string GetAiOwnsoftPromptPath()
|
|
||||||
=> Path.Combine(getRoot(), "AI", "ownsoftPrompts");
|
|
||||||
|
|
||||||
|
|
||||||
public static string GetUniqueRequestLogFile()
|
public static string GetUniqueRequestLogFile()
|
||||||
|
|||||||
@@ -36,27 +36,23 @@ namespace BeWo.Service.Plugins
|
|||||||
// DB Daten holen
|
// DB Daten holen
|
||||||
// DB Daten prüfen
|
// DB Daten prüfen
|
||||||
// Anfrage zusammensetzen
|
// Anfrage zusammensetzen
|
||||||
var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request);
|
|
||||||
|
|
||||||
var systemPromptFolderPath = BeWoServerPathHelper.GetAiSystemPromptPath();
|
|
||||||
var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath);
|
|
||||||
var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context);
|
|
||||||
|
|
||||||
var prompt_baustein_ref = request.AiPromptbausteinPrompt;
|
var prompt_baustein_ref = request.AiPromptbausteinPrompt;
|
||||||
var prompt_baustein_ref_oid = prompt_baustein_ref.Oid;
|
var prompt_baustein_ref_oid = prompt_baustein_ref.Oid;
|
||||||
var prompt_baustein_ref_ver = prompt_baustein_ref.Version;
|
var prompt_baustein_ref_ver = prompt_baustein_ref.Version;
|
||||||
|
|
||||||
IAiPromptbausteinPrompt prompt_baustein = null;
|
if (prompt_baustein_ref_oid <= 0)
|
||||||
if(prompt_baustein_ref_oid > 0)
|
throw new BeWoNotImplementedException();
|
||||||
{
|
|
||||||
prompt_baustein = DAOFactory.GenericDAO.LoadByID<AiPromptbausteinPrompt>(prompt_baustein_ref_oid);
|
|
||||||
ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, (AiPromptbausteinPrompt)prompt_baustein);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prompt_baustein = findOwnsoftPrompt(AiActionType.ServiceRecordDocumentation, prompt_baustein_ref.Oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var prompt_baustein = DAOFactory.GenericDAO.LoadByID<AiPromptbausteinPrompt>(prompt_baustein_ref_oid);
|
||||||
|
ServiceLogic.ConcurrencyCheck(prompt_baustein_ref_ver, prompt_baustein);
|
||||||
|
|
||||||
|
var context = AiFunctionContextLoader.LoadServiceRecordDocumentationContext(request, prompt_baustein.SamplesCount);
|
||||||
|
|
||||||
|
var systemPromptFolderPath = BeWoServerPathHelper.GetAiSystemPromptPath();
|
||||||
|
var factory = new AiFunctionSystemPromptBuilder(systemPromptFolderPath);
|
||||||
|
var system_prompt = factory.CreateServiceRecordDocumentationSystemPrompt(context);
|
||||||
|
|
||||||
// Anfrage abschicken
|
// Anfrage abschicken
|
||||||
var result = getResult(system_prompt, prompt_baustein.Prompt);
|
var result = getResult(system_prompt, prompt_baustein.Prompt);
|
||||||
|
|
||||||
@@ -121,48 +117,5 @@ namespace BeWo.Service.Plugins
|
|||||||
{
|
{
|
||||||
//throw new NotImplementedException();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private AiPromptbausteinPromptDC findOwnsoftPrompt(AiActionType aiAction, long prompt_oid)
|
|
||||||
{
|
|
||||||
var root = getOwnsoftFolder(aiAction);
|
|
||||||
|
|
||||||
return findOwnsoftPrompt_rec(root, prompt_oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private AiPromptbausteinPromptDC findOwnsoftPrompt_rec(AiPromptbausteinFolderDC dc, long prompt_oid)
|
|
||||||
{
|
|
||||||
foreach (var subprompts in dc.SubPrompts)
|
|
||||||
{
|
|
||||||
if (subprompts.Oid == prompt_oid)
|
|
||||||
return subprompts;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var subfolder in dc.SubFolders)
|
|
||||||
{
|
|
||||||
var search = findOwnsoftPrompt_rec(subfolder, prompt_oid);
|
|
||||||
|
|
||||||
if (search != null)
|
|
||||||
return search;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AiPromptbausteinFolderDC getOwnsoftFolder(AiActionType aiActionType)
|
|
||||||
{
|
|
||||||
var folder_path = BeWoServerPathHelper.GetAiOwnsoftPromptPath();
|
|
||||||
var file_name = $"{aiActionType.ToString().ToLower()}.json";
|
|
||||||
var file_path = Path.Combine(folder_path, file_name);
|
|
||||||
|
|
||||||
if (!File.Exists(file_path))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var json = File.ReadAllText(file_path, Encoding.UTF8);
|
|
||||||
|
|
||||||
var ownsoft_folder = JsonSerializer.Deserialize<AiPromptbausteinFolderDC>(json);
|
|
||||||
|
|
||||||
return ownsoft_folder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,23 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AICore.Context.Core;
|
using AICore.Context.Core;
|
||||||
|
using BS.Shared.DataContracts;
|
||||||
|
|
||||||
namespace BeWo.Service.ServiceUtils
|
namespace BeWo.Service.ServiceUtils
|
||||||
{
|
{
|
||||||
public class AiFunctionContextLoader
|
public class AiFunctionContextLoader
|
||||||
{
|
{
|
||||||
public static BaseContextSummary LoadServiceRecordDocumentationContext(AiFunctionDocRequest request)
|
public static BaseContextSummary LoadServiceRecordDocumentationContext(AiFunctionDocRequest request, int samplesCount)
|
||||||
{
|
{
|
||||||
var srs = request.ServiceRecords;
|
IEnumerable<ServiceRecordDC> srs_loaded = null;
|
||||||
var srs_loaded = DataContractLoader.LoadServiceRecordDCs(srs);
|
|
||||||
|
if(samplesCount > 0)
|
||||||
|
{
|
||||||
|
var srs = request.ServiceRecords;
|
||||||
|
srs_loaded = DataContractLoader.LoadServiceRecordDCs(srs)
|
||||||
|
.OrderByDescending(x => x.Start)
|
||||||
|
.Take(samplesCount);
|
||||||
|
}
|
||||||
|
|
||||||
var sc_ref = request.SupportConcept;
|
var sc_ref = request.SupportConcept;
|
||||||
var sc_loaded = DataContractLoader.LoadSupportConceptDC(sc_ref);
|
var sc_loaded = DataContractLoader.LoadSupportConceptDC(sc_ref);
|
||||||
|
|||||||
Reference in New Issue
Block a user