161 lines
3.8 KiB
C#
161 lines
3.8 KiB
C#
using BeWo.ServiceProxy;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using ChatController.Utilities.Extensions;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.XtraPrinting.Native;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Contexts;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BeWo.ViewModel.ListViewModel
|
|
{
|
|
public class AiConversationListVM : AbstractDCListMapperVM<AiConversationDC, AiConversationVM>
|
|
{
|
|
private string _MessageInput;
|
|
private string _ContextInput;
|
|
|
|
private AiModelDC _SelectedModel;
|
|
|
|
public AiConversationListVM() : this(null)
|
|
{
|
|
//VMList.Add(new AiConversationVM()
|
|
//{
|
|
// Created = DateTime.Now,
|
|
// Displayname = "Chat1",
|
|
// Messages = new AiConversationMessageListVM(new List<AiConversationMessageDC>()
|
|
// {
|
|
// new AiConversationMessageDC() {
|
|
// Context = "context",
|
|
// Model = "model",
|
|
// Oid = 1,
|
|
// Prompt = "prompt",
|
|
// Result = "result" }
|
|
// })
|
|
//});
|
|
}
|
|
public AiConversationListVM(List<AiConversationDC> pDCs) : base(pDCs)
|
|
{
|
|
Models = new ObservableSortCollection<AiModelDC>();
|
|
|
|
SendNewMessageCommand = new DelegateCommand(SendNewMessage, CanSendNewMessage);
|
|
RequestNewConversationCommand = new DelegateCommand(RequestNewConversation);
|
|
TestCommand = new DelegateCommand(Test);
|
|
}
|
|
|
|
public DelegateCommand SendNewMessageCommand { get; set; }
|
|
public DelegateCommand RequestNewConversationCommand { get; set; }
|
|
public DelegateCommand TestCommand { get; set; }
|
|
|
|
public ObservableCollection<AiModelDC> Models { get; set; }
|
|
public AiModelDC SelectedModel {
|
|
get { return _SelectedModel; }
|
|
set
|
|
{
|
|
if (_SelectedModel == value)
|
|
return;
|
|
|
|
_SelectedModel = value;
|
|
FirePropertyChanged(nameof(SelectedModel));
|
|
}
|
|
}
|
|
public string MessageInput
|
|
{
|
|
get { return _MessageInput; }
|
|
set
|
|
{
|
|
if (MessageInput == value)
|
|
return;
|
|
|
|
_MessageInput = value;
|
|
FirePropertyChanged(nameof(MessageInput));
|
|
}
|
|
}
|
|
|
|
public string ContextInput
|
|
{
|
|
get { return _ContextInput; }
|
|
set
|
|
{
|
|
if (ContextInput == value)
|
|
return;
|
|
|
|
_ContextInput = value;
|
|
FirePropertyChanged(nameof(ContextInput));
|
|
}
|
|
}
|
|
|
|
public void SendNewMessage()
|
|
{
|
|
var msg = MessageInput;
|
|
|
|
var context = ContextInput;
|
|
|
|
ServiceFacade.DoOperationsEnhancedServiceAsnyc(x => x.SendNewMessage(SelectedVM.CommitToDataContract(), context, msg), (message) =>
|
|
{
|
|
SelectedVM.Messages.VMList.Add(new AiConversationMessageVM(message));
|
|
});
|
|
}
|
|
|
|
public void RequestNewConversation()
|
|
{
|
|
var dc = new AiConversationDC();
|
|
|
|
dc.Created = DateTime.Now;
|
|
dc.Displayname = "Example";
|
|
dc.Modell = SelectedModel?.ToString();
|
|
|
|
var vm = new AiConversationVM(dc);
|
|
|
|
VMList.Add(vm);
|
|
}
|
|
|
|
public void Test()
|
|
{
|
|
var limit = 5;
|
|
|
|
var models = ServiceFacade.DoOperationsEnhancedServiceSnyc(x => x.GetAiModels());
|
|
Models.MakeEqualTo(models);
|
|
|
|
VMList.Clear();
|
|
|
|
foreach (var vm in Models)
|
|
{
|
|
var dc = new AiConversationDC();
|
|
|
|
dc.Created = DateTime.Now;
|
|
dc.Displayname = "Example";
|
|
dc.Modell = vm.ToString();
|
|
|
|
var pvm = new AiConversationVM(dc);
|
|
|
|
VMList.Add(pvm);
|
|
}
|
|
|
|
var msg = "Wie alt ist Frau Müller?";
|
|
var context = "Frau Müller wurde am 1.1.1950 geboren. Aktuelle haben wir folgende Universalzeit: " + DateTime.Now.ToUniversalTime();
|
|
|
|
for (var i = 0; i < limit; i++)
|
|
{
|
|
foreach (var vm in VMList)
|
|
{
|
|
ServiceFacade.DoOperationsEnhancedServiceAsnyc(x => x.SendNewMessage(vm.CommitToDataContract(), context, msg), (message) =>
|
|
{
|
|
vm.Messages.VMList.Add(new AiConversationMessageVM(message));
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool CanSendNewMessage()
|
|
{
|
|
return SelectedVM is object;
|
|
}
|
|
}
|
|
}
|