Routine bliblablubb
This commit is contained in:
@@ -166,8 +166,6 @@ namespace BeWo.ViewModel
|
||||
|
||||
public override void UpdateByDataContract(AiPromptbausteinPromptDC pDataContract)
|
||||
{
|
||||
DataContract = pDataContract;
|
||||
|
||||
Title = pDataContract.Title;
|
||||
Description = pDataContract.Description;
|
||||
ParentFolderOid = pDataContract.ParentFolderOid;
|
||||
@@ -181,6 +179,10 @@ namespace BeWo.ViewModel
|
||||
OwnsoftRefLink = pDataContract.OwnsoftRefLink;
|
||||
IsFavorite = pDataContract.IsFavorite;
|
||||
ActionType = pDataContract.ActionType;
|
||||
|
||||
DataContract = pDataContract;
|
||||
|
||||
SetDirty(false);
|
||||
}
|
||||
|
||||
public override bool IsDirty
|
||||
|
||||
@@ -109,9 +109,7 @@ namespace BeWo.ViewModel.Controls.AI
|
||||
|
||||
IsVisible = true;
|
||||
|
||||
var context2 = context.References.ToDictionary(kv => kv.Key, kv => kv.Value.ToList());
|
||||
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CheckContextSize(ActionType, context2, null),
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CheckContextSize(ActionType, context),
|
||||
isValid =>
|
||||
{
|
||||
if (isValid)
|
||||
@@ -127,7 +125,7 @@ namespace BeWo.ViewModel.Controls.AI
|
||||
{
|
||||
var context = GetAiVisualContext();
|
||||
|
||||
var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context.References, (long)context.Primary, CanSendNewMessage);
|
||||
var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context, CanSendNewMessage);
|
||||
|
||||
return chat_viewmodel;
|
||||
}
|
||||
@@ -171,13 +169,19 @@ namespace BeWo.ViewModel.Controls.AI
|
||||
{
|
||||
var vm = GetConversationViewModel();
|
||||
vm.SendAfterLoaded = true;
|
||||
vm.PromptInput = prompt;
|
||||
vm.MessageInput = prompt.Prompt;
|
||||
BeWoApp.MainControl.WindowService.Show(vm);
|
||||
return;
|
||||
}
|
||||
else if(e is AiPromptbausteinRoutineVM routine)
|
||||
{
|
||||
|
||||
var vm = GetConversationViewModel();
|
||||
vm.SendAfterLoaded = true;
|
||||
vm.RoutineInput = routine;
|
||||
vm.MessageInput = routine.Steps.VMList[0].PromptReference.Prompt;
|
||||
BeWoApp.MainControl.WindowService.Show(vm);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -912,14 +912,12 @@ namespace BeWo.ViewModel
|
||||
einheit_vm_list.VMList.Sort(WohneinheitVM.Compare);
|
||||
}
|
||||
|
||||
public static AiConversationChatViewModel CreateAiConversationChatViewModel(AiActionType actionType, Dictionary<TableID, long[]> bewoObjects,
|
||||
long? reference_oid = null, bool canSendNewMessage = true)
|
||||
public static AiConversationChatViewModel CreateAiConversationChatViewModel(AiActionType actionType, AiViewContextDC view_context, bool canSendNewMessage = true)
|
||||
{
|
||||
var vm = new AiConversationChatViewModel();
|
||||
|
||||
vm.ActionType = actionType;
|
||||
vm.ContextBeWoObjects = bewoObjects;
|
||||
vm.ReferenceObjectOid = reference_oid;
|
||||
vm.ViewContext = view_context;
|
||||
vm.CanSendNewMessage = canSendNewMessage;
|
||||
|
||||
return vm;
|
||||
|
||||
@@ -14,6 +14,9 @@ using DevExpress.Mvvm;
|
||||
using BeWo.ServiceProxy;
|
||||
using BS.Shared.Extensions;
|
||||
using System.Diagnostics;
|
||||
using DevExpress.XtraCharts.Native;
|
||||
using static DevExpress.Utils.Drawing.Helpers.NativeMethods;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace BeWo.ViewModel.View.AI
|
||||
{
|
||||
@@ -24,7 +27,6 @@ namespace BeWo.ViewModel.View.AI
|
||||
private bool _IsSending;
|
||||
|
||||
private string _MessageInput;
|
||||
private string _ContextInput;
|
||||
|
||||
private AiModelDC _SelectedModel;
|
||||
private AiConfigVM _Config;
|
||||
@@ -121,18 +123,8 @@ namespace BeWo.ViewModel.View.AI
|
||||
FirePropertyChanged(nameof(MessageInput));
|
||||
}
|
||||
}
|
||||
public string ContextInput
|
||||
{
|
||||
get { return _ContextInput; }
|
||||
set
|
||||
{
|
||||
if (ContextInput == value)
|
||||
return;
|
||||
|
||||
_ContextInput = value;
|
||||
FirePropertyChanged(nameof(ContextInput));
|
||||
}
|
||||
}
|
||||
public AiPromptbausteinPromptVM PromptInput { get; set; }
|
||||
public AiPromptbausteinRoutineVM RoutineInput { get; set; }
|
||||
|
||||
public bool IsSettingsOpen
|
||||
{
|
||||
@@ -164,8 +156,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
public bool IsNewConversationVisible => ListVM.SelectedVM is null;
|
||||
|
||||
public AiActionType ActionType { get; set; }
|
||||
public long? ReferenceObjectOid { get; set; }
|
||||
public Dictionary<TableID, long[]> ContextBeWoObjects { get; set; }
|
||||
public AiViewContextDC ViewContext { get; set; }
|
||||
|
||||
public AiPromptbausteinPromptVM SavePromptVM
|
||||
{
|
||||
@@ -201,7 +192,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
conv.Created = DateTime.Now;
|
||||
conv.Updated = DateTime.Now;
|
||||
conv.ActionType = ActionType;
|
||||
conv.ContextBeWoObjects = ContextBeWoObjects;
|
||||
conv.ContextBeWoObjects = ViewContext.References;
|
||||
conv.Messages = new List<AiConversationMessageDC>()
|
||||
{
|
||||
new AiConversationMessageDC()
|
||||
@@ -213,8 +204,36 @@ namespace BeWo.ViewModel.View.AI
|
||||
|
||||
var vm = InsertConverstion(conv);
|
||||
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(
|
||||
x => x.CreateAiConversationWithMessage(conv, Config.SelectedModel.Oid.Value, message),
|
||||
Action<Exception> error = (e) =>
|
||||
{
|
||||
EndSending();
|
||||
ListVM.VMList.Remove(vm);
|
||||
};
|
||||
|
||||
if (RoutineInput != null)
|
||||
{
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(
|
||||
x => x.CreateAiConversationWithPromptbaustein(conv, ViewContext, RoutineInput.Steps.VMList[0].PromptReference.Oid.Value),
|
||||
dc =>
|
||||
{
|
||||
vm.UpdateByDataContract(dc);
|
||||
ExecuteChain(dc.Oid.Value, 1, error);
|
||||
},
|
||||
error
|
||||
);
|
||||
}
|
||||
else if (PromptInput != null)
|
||||
{
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(
|
||||
x => x.CreateAiConversationWithPromptbaustein(conv, ViewContext, PromptInput.DataContract.Oid.Value),
|
||||
dc => UpdateConverstion(vm, dc),
|
||||
error
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(
|
||||
x => x.CreateAiConversationWithMessage(conv, ViewContext, message),
|
||||
dc => UpdateConverstion(vm, dc),
|
||||
e =>
|
||||
{
|
||||
@@ -222,12 +241,51 @@ namespace BeWo.ViewModel.View.AI
|
||||
ListVM.VMList.Remove(vm);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
EndSending();
|
||||
}
|
||||
}
|
||||
private void ExecuteChain(long oid, int c, Action<Exception> error)
|
||||
{
|
||||
if (c >= RoutineInput.Steps.Count)
|
||||
{
|
||||
FinishSending();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MessageInput = RoutineInput.Steps.VMList[c].PromptReference.Prompt;
|
||||
|
||||
var conv = ListVM.SelectedVM;
|
||||
|
||||
var msg_dc = new AiConversationMessageDC();
|
||||
|
||||
msg_dc.Message = MessageInput;
|
||||
msg_dc.Role = BS.Shared.AiConversationMessageRole.User;
|
||||
msg_dc.Created = DateTime.Now;
|
||||
|
||||
var msg_vm = new AiConversationMessageVM(msg_dc);
|
||||
|
||||
conv.Messages.VMList.Add(msg_vm);
|
||||
|
||||
ServiceFacade.DoAiEnhancedServiceAsnyc(
|
||||
x => x.SendNewMessage(conv.DataContract.Oid.Value, MessageInput),
|
||||
(messages) =>
|
||||
{
|
||||
if (messages.Count != 2)
|
||||
throw new InvalidOperationException("message count: " + messages.Count);
|
||||
|
||||
msg_vm.DataContract = messages[0];
|
||||
|
||||
conv.Messages.VMList.Add(new AiConversationMessageVM(messages[1]));
|
||||
|
||||
ExecuteChain(oid, c + 1, error);
|
||||
},
|
||||
error);
|
||||
}
|
||||
private void OpenNewConversation()
|
||||
{
|
||||
ListVM.SelectedVM = null;
|
||||
@@ -261,11 +319,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
|
||||
conv.Messages.VMList.Add(new AiConversationMessageVM(messages[1]));
|
||||
|
||||
MessageInput = string.Empty;
|
||||
|
||||
EndSending();
|
||||
|
||||
SendNewMessageSuccess?.Invoke(this, EventArgs.Empty);
|
||||
FinishSending();
|
||||
},
|
||||
(exception) =>
|
||||
{
|
||||
@@ -286,6 +340,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
throw new InvalidOperationException("Sendet bereits");
|
||||
|
||||
IsSending = true;
|
||||
IsWaiting = true;
|
||||
}
|
||||
private void EndSending()
|
||||
{
|
||||
@@ -293,6 +348,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
throw new InvalidOperationException("Sendet nicht");
|
||||
|
||||
IsSending = false;
|
||||
IsWaiting = false;
|
||||
}
|
||||
|
||||
private AiConversationVM InsertConverstion(AiConversationDC dc)
|
||||
@@ -308,6 +364,10 @@ namespace BeWo.ViewModel.View.AI
|
||||
{
|
||||
vm.UpdateByDataContract(dc);
|
||||
|
||||
FinishSending();
|
||||
}
|
||||
private void FinishSending()
|
||||
{
|
||||
MessageInput = string.Empty;
|
||||
|
||||
EndSending();
|
||||
@@ -356,7 +416,7 @@ namespace BeWo.ViewModel.View.AI
|
||||
private void ReloadConversations()
|
||||
{
|
||||
var ui_context = ActionType;
|
||||
var reference = ReferenceObjectOid;
|
||||
var reference = ViewContext.Primary;
|
||||
|
||||
var list = VMFactory.CreateAiConversationListVM(ui_context, reference);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user