version 5.1 (5.0)

This commit is contained in:
2026-06-12 15:44:39 +02:00
parent 42ae76db4b
commit e296d90095
20 changed files with 495 additions and 219 deletions

View File

@@ -15,7 +15,7 @@ namespace BeWo
{
var baseVersion = new Version(BeWoApp.ShortVersion);
var stage = BeWoClientReleaseStage.Sandbox;
var stageVersion = new Version("5.0");
var stageVersion = new Version("5.1");
var feature = BeWoClientFeature.AI;
#if !DEBUG

View File

@@ -65,6 +65,7 @@ namespace BeWo.ServiceProxy
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiConversationMessageRole))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ActivationTypeId))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ValueListEntryType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiRoutineType))]
BS.Shared.DataContracts.Feature.AI.AiConversationDC CreateAiConversation(BS.Shared.DataContracts.Feature.AI.AiConversationDC conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/CreateAiConversationWithMessage", ReplyAction="http://tempuri.org/IAiEnhancedService/CreateAiConversationWithMessageResponse")]
@@ -100,12 +101,29 @@ namespace BeWo.ServiceProxy
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiConversationMessageRole))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ActivationTypeId))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ValueListEntryType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiRoutineType))]
BS.Shared.DataContracts.Feature.AI.AiConversationDC CreateAiConversationWithMessage(BS.Shared.DataContracts.Feature.AI.AiConversationDC conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, string message);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/CreateAiConversationWithPromptbaustein", ReplyAction="http://tempuri.org/IAiEnhancedService/CreateAiConversationWithPromptbausteinRespo" +
"nse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/CreateAiConversationWithPromptbausteinBeWoF" +
"aultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/CloneAiConversation", ReplyAction="http://tempuri.org/IAiEnhancedService/CloneAiConversationResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/CloneAiConversationBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
BS.Shared.DataContracts.Feature.AI.AiConversationDC CloneAiConversation(long conversation_oid, System.Nullable<long> message_oid);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplayname", ReplyAction="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplaynameResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplaynameBeWoFaultFau" +
"lt", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
long UpdateAiConversationDisplayname(long oid, long version, string displayname);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/DeleteAiConversation", ReplyAction="http://tempuri.org/IAiEnhancedService/DeleteAiConversationResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/DeleteAiConversationBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
void DeleteAiConversation(long conversation_oid);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/SendNewMessage", ReplyAction="http://tempuri.org/IAiEnhancedService/SendNewMessageResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/SendNewMessageBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> SendNewMessage(long conversation, string message);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithPrompt", ReplyAction="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithPromptResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithPromptBeWoFaultFau" +
"lt", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.BeWoDataContract))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiConfigDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiModelDC))]
@@ -136,24 +154,44 @@ namespace BeWo.ServiceProxy
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiConversationMessageRole))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ActivationTypeId))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ValueListEntryType))]
BS.Shared.DataContracts.Feature.AI.AiConversationDC CreateAiConversationWithPromptbaustein(BS.Shared.DataContracts.Feature.AI.AiConversationDC conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long prompt_oid);
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiRoutineType))]
System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> ExecuteAiConversationWithPrompt(long conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long prompt_oid);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/CloneAiConversation", ReplyAction="http://tempuri.org/IAiEnhancedService/CloneAiConversationResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/CloneAiConversationBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
BS.Shared.DataContracts.Feature.AI.AiConversationDC CloneAiConversation(long conversation_oid, System.Nullable<long> message_oid);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplayname", ReplyAction="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplaynameResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/UpdateAiConversationDisplaynameBeWoFaultFau" +
"lt", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
long UpdateAiConversationDisplayname(long oid, long version, string displayname);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/DeleteAiConversation", ReplyAction="http://tempuri.org/IAiEnhancedService/DeleteAiConversationResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/DeleteAiConversationBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
void DeleteAiConversation(long conversation_oid);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/SendNewMessage", ReplyAction="http://tempuri.org/IAiEnhancedService/SendNewMessageResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/SendNewMessageBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> SendNewMessage(long conversation, string message);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithRoutine", ReplyAction="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithRoutineResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/ExecuteAiConversationWithRoutineBeWoFaultFa" +
"ult", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.BeWoDataContract))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiConfigDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiModelDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiModelDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiConversationDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiPromptbausteinFolderDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiPromptbausteinFolderDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiPromptbausteinPromptDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiPromptbausteinPromptDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiPromptbausteinRoutineDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiPromptbausteinRoutineDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiPromptbausteinRoutineStepDC>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiPromptbausteinRoutineStepDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Feature.AI.AiUserSettingDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.DataContracts.Compact.CompactEmployeeDC))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.Dictionary<BS.Shared.TableID, System.Collections.Generic.List<long>>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.List<long>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.Collections.Generic.Dictionary<long, BS.Shared.ValueListEntryType>))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.Core.BeWoFault))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.Core.BeWoFaultType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiDataContextType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiModelSource))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiActionType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.TableID))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiConversationMessageRole))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ActivationTypeId))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ValueListEntryType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiRoutineType))]
System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> ExecuteAiConversationWithRoutine(long conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long routine, int step);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/CheckContextSize", ReplyAction="http://tempuri.org/IAiEnhancedService/CheckContextSizeResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(BS.Shared.Core.BeWoFault), Action="http://tempuri.org/IAiEnhancedService/CheckContextSizeBeWoFaultFault", Name="BeWoFault", Namespace="http://schemas.datacontract.org/2004/07/BS.Shared.Core")]
@@ -187,6 +225,7 @@ namespace BeWo.ServiceProxy
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiConversationMessageRole))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ActivationTypeId))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.ValueListEntryType))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(BS.Shared.AiRoutineType))]
bool CheckContextSize(BS.Shared.AiActionType actionType, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAiEnhancedService/GetAiPromptbausteinFolder", ReplyAction="http://tempuri.org/IAiEnhancedService/GetAiPromptbausteinFolderResponse")]
@@ -305,11 +344,6 @@ namespace BeWo.ServiceProxy
return base.Channel.CreateAiConversationWithMessage(conversation, view_context, message);
}
public BS.Shared.DataContracts.Feature.AI.AiConversationDC CreateAiConversationWithPromptbaustein(BS.Shared.DataContracts.Feature.AI.AiConversationDC conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long prompt_oid)
{
return base.Channel.CreateAiConversationWithPromptbaustein(conversation, view_context, prompt_oid);
}
public BS.Shared.DataContracts.Feature.AI.AiConversationDC CloneAiConversation(long conversation_oid, System.Nullable<long> message_oid)
{
return base.Channel.CloneAiConversation(conversation_oid, message_oid);
@@ -330,6 +364,16 @@ namespace BeWo.ServiceProxy
return base.Channel.SendNewMessage(conversation, message);
}
public System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> ExecuteAiConversationWithPrompt(long conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long prompt_oid)
{
return base.Channel.ExecuteAiConversationWithPrompt(conversation, view_context, prompt_oid);
}
public System.Collections.Generic.List<BS.Shared.DataContracts.Feature.AI.AiConversationMessageDC> ExecuteAiConversationWithRoutine(long conversation, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context, long routine, int step)
{
return base.Channel.ExecuteAiConversationWithRoutine(conversation, view_context, routine, step);
}
public bool CheckContextSize(BS.Shared.AiActionType actionType, BS.Shared.DataContracts.Feature.AI.AiViewContextDC view_context)
{
return base.Channel.CheckContextSize(actionType, view_context);

View File

@@ -10,7 +10,7 @@
x:Key="ai_promptbaustein_folder_itemtemplate"
DataType="{x:Type vm:AiPromptbausteinFolderVM}"
ItemsSource="{Binding Path=SubFolders.VMList}">
<Grid Background="Transparent" Margin="0">
<Grid Margin="0" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
@@ -34,11 +34,9 @@
Height="21"
Margin="0,0,0,0"
Padding="0,0,0,0"
BorderThickness="0"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
Cursor="Arrow"
Focusable="False"
FontSize="12"

View File

@@ -151,8 +151,8 @@
<Grid
Margin="0,0,60,0"
HorizontalAlignment="Left"
Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
ContextMenuService.IsEnabled="{Binding DataContext.AssistentCommands, Converter={StaticResource CollectionCountToBoolConverter}, RelativeSource={RelativeSource AncestorType=ItemsControl}}">
ContextMenuService.IsEnabled="{Binding DataContext.AssistentCommands, Converter={StaticResource CollectionCountToBoolConverter}, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ItemsControl}}">
<Grid.ContextMenu>
<ContextMenu ItemsSource="{Binding PlacementTarget.Tag.AssistentCommands, RelativeSource={RelativeSource Self}}">
<ContextMenu.ItemContainerStyle>
@@ -163,7 +163,10 @@
</ContextMenu.ItemContainerStyle>
<ContextMenu.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="3"/>
<TextBlock
Margin="3"
VerticalAlignment="Center"
Text="{Binding Name}" />
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>

View File

@@ -98,12 +98,12 @@
</Popup>-->
<Popup
x:Name="popup_promptbaustein_favoriten"
Width="400"
Height="200"
IsOpen="{Binding IsFavoritenOpen}"
Placement="Top"
PlacementTarget="{Binding ElementName=btnOpenAi5}"
StaysOpen="False"
Width="400"
Height="200">
StaysOpen="False">
<Border x:Name="border_promptbaustein_favoriten" BorderThickness="1" />
</Popup>
</Grid>

View File

@@ -590,7 +590,7 @@
<EventSetter Event="PreviewMouseDown" Handler="listBoxEdit3_PreviewMouseDown" />
</Style>
</TabControl.Resources>
<TabItem Header="Alle">
<TabItem x:Name="tabItemAlle" Header="Alle">
<TabItem.InputBindings>
<KeyBinding Key="Delete" Command="{Binding DeleteItemCommand}" />
<KeyBinding Key="Enter" Command="{Binding OpenEditItemDialogCommand}" />
@@ -661,19 +661,21 @@
<Button
Width="150"
Margin="3,12,3,3"
Command="{Binding OpenAddPromptDialogCommand}">
Command="{Binding OpenAddPromptDialogCommand}"
Visibility="{Binding IsEditMode, ElementName=root, Converter={StaticResource BoolVisibilityConverter}}">
Ersten Prompt anlegen
</Button>
<Button
Width="150"
Margin="3,3,3,3"
Command="{Binding OpenAddRoutineDialogCommand}">
Command="{Binding OpenAddRoutineDialogCommand}"
Visibility="{Binding IsEditMode, ElementName=root, Converter={StaticResource BoolVisibilityConverter}}">
Erste Routine anlegen
</Button>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Prompts">
<TabItem x:Name="tabItemPrompts" Header="Prompts">
<TabItem.InputBindings>
<KeyBinding Key="Delete" Command="{Binding DeletePromptCommand}" />
<KeyBinding Key="Enter" Command="{Binding OpenEditPromptDialogCommand}" />
@@ -736,13 +738,14 @@
<Button
Width="150"
Margin="3,12,3,3"
Command="{Binding OpenAddPromptDialogCommand}">
Command="{Binding OpenAddPromptDialogCommand}"
Visibility="{Binding IsEditMode, ElementName=root, Converter={StaticResource BoolVisibilityConverter}}">
Ersten Prompt anlegen
</Button>
</StackPanel>
</Grid>
</TabItem>
<TabItem Header="Routinen">
<TabItem x:Name="tabItemRoutinen" Header="Routinen">
<TabItem.InputBindings>
<KeyBinding Key="Delete" Command="{Binding DeleteRoutineCommand}" />
<KeyBinding Key="Enter" Command="{Binding OpenEditRoutineDialogCommand}" />
@@ -791,7 +794,8 @@
<Button
Width="150"
Margin="3,12,3,3"
Command="{Binding OpenAddRoutineDialogCommand}">
Command="{Binding OpenAddRoutineDialogCommand}"
Visibility="{Binding IsEditMode, ElementName=root, Converter={StaticResource BoolVisibilityConverter}}">
Erste Routine anlegen
</Button>
</StackPanel>
@@ -801,8 +805,13 @@
<StackPanel
HorizontalAlignment="Right"
VerticalAlignment="Top"
Orientation="Horizontal"
Visibility="{Binding SelectedFolder.CanAddPrompt, Converter={StaticResource BoolVisibilityConverter}}">
Orientation="Horizontal">
<StackPanel.Visibility>
<MultiBinding Converter="{StaticResource BooleanAndVisibilityMultiConverter}">
<Binding Path="SelectedFolder.CanAddPrompt" />
<Binding ElementName="root" Path="IsEditMode" />
</MultiBinding>
</StackPanel.Visibility>
<StackPanel.Resources>
<ResourceDictionary>
<Style BasedOn="{StaticResource HideDisabledButton}" TargetType="Button">

View File

@@ -1,6 +1,8 @@
using BeWo.ViewModel;
using DevExpress.Xpf.Editors;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -48,6 +50,56 @@ namespace BeWo.View.Controls.AI
set { SetValue(RoutineActivatedCommandProperty, value); }
}
public static readonly DependencyProperty IsEditModeProperty =
DependencyProperty.Register("IsEditMode", typeof(bool),
typeof(AiPromptbausteinLibraryControl), new PropertyMetadata(true, OnIsEditModeChanged));
/// <summary>
/// Schaltet den Bearbeitungsmodus (Kontextmenüs, Edit-Shortcuts, Anlegen-Buttons,
/// Ordner-Doppelklick-Bearbeiten). Default: eingeschaltet.
/// </summary>
public bool IsEditMode
{
get { return (bool)GetValue(IsEditModeProperty); }
set { SetValue(IsEditModeProperty, value); }
}
static void OnIsEditModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (AiPromptbausteinLibraryControl)d;
control.UpdateEditMode((bool)e.NewValue);
}
private Dictionary<FrameworkElement, InputBinding[]> _DisabledInputBindings;
void UpdateEditMode(bool isEditMode)
{
if (!isEditMode)
{
if (_DisabledInputBindings != null)
return;
_DisabledInputBindings = new Dictionary<FrameworkElement, InputBinding[]>();
foreach (var element in new FrameworkElement[] { treeView, tabItemAlle, tabItemPrompts, tabItemRoutinen })
{
_DisabledInputBindings[element] = element.InputBindings.Cast<InputBinding>().ToArray();
element.InputBindings.Clear();
}
}
else
{
if (_DisabledInputBindings == null)
return;
foreach (var entry in _DisabledInputBindings)
foreach (var binding in entry.Value)
entry.Key.InputBindings.Add(binding);
_DisabledInputBindings = null;
}
}
/// <summary>
/// Setzt die initiale Selektion zurück (erstes TreeViewItem an- und wieder abwählen),
/// damit beim Öffnen kein Ordner vorselektiert ist.
@@ -114,6 +166,9 @@ namespace BeWo.View.Controls.AI
if (e.ClickCount == 2)
{
if (!IsEditMode)
return;
if (!ViewModel.OpenEditFolderDialogCommand.CanExecute(null))
return;
@@ -130,11 +185,23 @@ namespace BeWo.View.Controls.AI
private void treeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
if (!IsEditMode)
{
e.Handled = true;
return;
}
ViewModel?.UpdateFolderCommands();
}
private void ListBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
if (!IsEditMode)
{
e.Handled = true;
return;
}
ViewModel?.UpdatePromptCommands();
}

View File

@@ -5,6 +5,7 @@ using BeWo.ViewModel.ListViewModel;
using BeWo.ViewModel.View.AI;
using BS.Shared.Extensions;
using DevExpress.Mvvm;
using DevExpress.Xpf.Core.Native;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -30,6 +31,8 @@ namespace BeWo.View.Detail.AI
/// </summary>
public partial class AiConversationChatView : BeWoView
{
private bool _loaded = false;
public AiConversationChatView(AiConversationChatViewModel viewModel)
{
InitializeComponent();
@@ -59,14 +62,15 @@ namespace BeWo.View.Detail.AI
private void BeWoView_Loaded(object sender, RoutedEventArgs e)
{
if (BeWoApp.IsInDesignMode)
if (BeWoApp.IsInDesignMode || _loaded)
return;
_loaded = true;
ViewModel.ReloadConfigCommand.Execute(null);
ViewModel.ReloadConversationsCommand.Execute(null);
if (ViewModel.SendAfterLoaded)
ViewModel.StartConversationWithMessageCommand.Execute(null);
ViewModel.Start();
}
private void listview_conversations_SelectionChanged(object sender, SelectionChangedEventArgs e)

View File

@@ -1,11 +1,12 @@
<view:BeWoView
xmlns:view="clr-namespace:BeWo.View" x:Class="BeWo.View.Detail.AI.AiPromptbausteinComplexSelectionView"
x:Class="BeWo.View.Detail.AI.AiPromptbausteinComplexSelectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ai="clr-namespace:BeWo.ViewModel.View.AI"
xmlns:controls="clr-namespace:BeWo.View.Controls.AI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:view="clr-namespace:BeWo.View"
d:DataContext="{d:DesignInstance Type=ai:AiPromptbausteinSelectionComplexViewModel,
IsDesignTimeCreatable=True}"
d:DesignHeight="450"
@@ -24,9 +25,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle
Height="6"
Fill="{DynamicResource ServiceRecordContentBrush}" />
<Rectangle Height="6" Fill="{DynamicResource ServiceRecordContentBrush}" />
<Grid Grid.Row="1" Margin="6">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
@@ -34,6 +33,7 @@
</Grid.RowDefinitions>
<controls:AiPromptbausteinLibraryControl
x:Name="libraryControl"
IsEditMode="{Binding CanOpenContextMenu}"
PromptActivatedCommand="{Binding SendCommand}"
RoutineActivatedCommand="{Binding SendCommand}" />
<Button

View File

@@ -7,6 +7,7 @@ using BeWo.ServiceProxy;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.Extensions;
using DevExpress.Mvvm;
using DevExpress.Xpf.Core.Native;
using Newtonsoft.Json;
@@ -115,6 +116,12 @@ namespace BeWo.ViewModel
return new AiConversationMessageListVM(messages);
}
public void AddMessages(List<AiConversationMessageDC> messages)
{
var filter = getFilter(messages);
Messages.VMList.AddRange(filter.VMList);
}
public void ResetDisplayname()
{
Displayname = DataContract.Displayname;

View File

@@ -140,18 +140,14 @@ namespace BeWo.ViewModel.Controls.AI
if (e is AiPromptbausteinPromptVM prompt)
{
var vm = GetConversationViewModel();
vm.SendAfterLoaded = true;
vm.PromptInput = prompt;
vm.MessageInput = prompt.Prompt;
vm.InputItem = prompt;
BeWoApp.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;
vm.InputItem = routine;
BeWoApp.WindowService.Show(vm);
return;
}

View File

@@ -18,6 +18,7 @@ using DevExpress.XtraCharts.Native;
using static DevExpress.Utils.Drawing.Helpers.NativeMethods;
using System.Security.Cryptography;
using BeWo.ViewModel.Controls.AI;
using DevExpress.Charts.Native;
namespace BeWo.ViewModel.View.AI
{
@@ -39,7 +40,6 @@ namespace BeWo.ViewModel.View.AI
Models = new ObservableSortCollection<AiModelDC>();
SendNewMessageCommand = new DelegateCommand(SendNewMessage, () => ListVM.SelectedVM is object && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending);
OpenNewConversationCommand = new DelegateCommand(OpenNewConversation, () => CanSendNewMessage && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleServiceRecordChat));
StartConversationWithMessageCommand = new DelegateCommand(StartConversationWithMessage, () => CanSendNewMessage && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending);
ReloadConfigCommand = new DelegateCommand(ReloadConfig);
@@ -47,11 +47,11 @@ namespace BeWo.ViewModel.View.AI
ReloadModelsCommand = new DelegateCommand(ReloadModels);
OpenSettingCommand = new DelegateCommand(OpenSetting, () => BeWoApp.AppSettings?.ModuleAiSettingsEnabled ?? false);
RenameCommand = new DelegateCommand(Rename, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleServiceRecordChat) && ListVM.SelectedVM is object);
RenameCommand = new DelegateCommand(Rename, () => ListVM.SelectedVM is object);
OpenCloneCommand = new DelegateCommand(OpenClone, () => ListVM.SelectedVM is object && BeWoAppInfo.IsInAiDeveloperMode);
CloneCommand = new DelegateCommand(Clone);
AskDeleteCommand = new DelegateCommand(AskDelete, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleServiceRecordChat) && ListVM.SelectedVM is object);
AskDeleteCommand = new DelegateCommand(AskDelete, () => ListVM.SelectedVM is object);
SavePromptCommand = new DelegateCommand<AiConversationMessageVM>(SavePrompt, vm => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModulePromptbausteineEdit));
AcceptSavePromptCommand = new DelegateCommand(AcceptSavePrompt, () => !string.IsNullOrWhiteSpace(SavePromptVM?.Title));
@@ -66,10 +66,7 @@ namespace BeWo.ViewModel.View.AI
public event EventHandler SendNewMessageSuccess;
public ICommand SendNewMessageCommand { get; set; }
public ICommand OpenNewConversationCommand { get; set; }
public ICommand StartConversationWithMessageCommand { get; set; }
public ICommand RequestNewConversationCommand { get; set; }
public ICommand TestCommand { get; set; }
public ICommand AskDeleteCommand { get; set; }
public ICommand ReloadConfigCommand { get; set; }
public ICommand ReloadConversationsCommand { get; set; }
@@ -88,7 +85,6 @@ namespace BeWo.ViewModel.View.AI
public AiViewContextDC ViewContext { get; set; }
public bool CanSendNewMessage { get; set; }
public bool SendAfterLoaded { get; set; }
public AiConversationListVM ListVM { get; set; }
public ObservableCollection<AiModelDC> Models { get; set; }
@@ -129,8 +125,7 @@ namespace BeWo.ViewModel.View.AI
FirePropertyChanged(nameof(MessageInput));
}
}
public AiPromptbausteinPromptVM PromptInput { get; set; }
public AiPromptbausteinRoutineVM RoutineInput { get; set; }
public AbstractBaseVM InputItem { get; set; }
public List<AiMenuItemTemplate> AssistentCommands { get; protected set; }
@@ -197,7 +192,6 @@ namespace BeWo.ViewModel.View.AI
conv.Created = DateTime.Now;
conv.Updated = DateTime.Now;
conv.ActionType = ActionType;
conv.ContextBeWoObjects = ViewContext.References;
conv.Messages = new List<AiConversationMessageDC>()
{
new AiConversationMessageDC()
@@ -209,47 +203,7 @@ namespace BeWo.ViewModel.View.AI
var vm = InsertConverstion(conv);
Action<Exception> error = (e) =>
{
EndSending();
ListVM.VMList.Remove(vm);
ServiceFacade.EndManuelWaiting();
};
if (RoutineInput != null)
{
ServiceFacade.StartManuelWaiting();
ServiceFacade.DoAiEnhancedServiceAsnyc(
x => x.CreateAiConversationWithPromptbaustein(conv, ViewContext, RoutineInput.Steps.VMList[0].PromptReference.Oid.Value),
dc =>
{
vm.UpdateByDataContract(dc);
if(RoutineInput.Steps.Count == 1)
{
ServiceFacade.EndManuelWaiting();
}
else
{
ExecuteChain(dc.Oid.Value, 1, error);
}
},
error,
false
);
}
else if (PromptInput != null)
{
ServiceFacade.DoAiEnhancedServiceAsnyc(
x => x.CreateAiConversationWithPromptbaustein(conv, ViewContext, PromptInput.DataContract.Oid.Value),
dc => UpdateConverstion(vm, dc),
error
);
}
else
{
ServiceFacade.DoAiEnhancedServiceAsnyc(
ServiceFacade.DoAiEnhancedServiceAsnyc(
x => x.CreateAiConversationWithMessage(conv, ViewContext, message),
dc => UpdateConverstion(vm, dc),
e =>
@@ -258,58 +212,13 @@ 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();
ServiceFacade.EndManuelWaiting();
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,
false);
}
private void OpenNewConversation()
{
ListVM.SelectedVM = null;
}
private void SendNewMessage()
{
StartSending();
@@ -559,5 +468,159 @@ namespace BeWo.ViewModel.View.AI
AssistentCommands.Add(imported_menu_item);
}
internal void Start()
{
if (InputItem is null)
return;
if (InputItem is AiPromptbausteinPromptVM prompt)
{
StartPrompt(prompt);
}
else if (InputItem is AiPromptbausteinRoutineVM routine)
{
StartRoutine(routine);
}
else
{
throw new ArgumentOutOfRangeException(nameof(InputItem));
}
InputItem = null;
}
private void StartPrompt(AiPromptbausteinPromptVM prompt)
{
StartSending();
try
{
var conv = new AiConversationDC();
conv.Created = DateTime.Now;
conv.Updated = DateTime.Now;
conv.ActionType = ActionType;
var vm = InsertConverstion(conv);
Action<Exception> error = (e) =>
{
EndSending();
ListVM.VMList.Remove(vm);
ServiceFacade.EndManuelWaiting();
};
ServiceFacade.StartManuelWaiting();
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CreateAiConversation(conv, ViewContext), cb =>
{
vm.UpdateByDataContract(cb);
var msg = prompt.Prompt;
var msg_dc = new AiConversationMessageDC();
msg_dc.Message = msg;
msg_dc.Role = BS.Shared.AiConversationMessageRole.User;
msg_dc.Created = DateTime.Now;
var msg_vm = new AiConversationMessageVM(msg_dc);
vm.Messages.VMList.Add(msg_vm);
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.ExecuteAiConversationWithPrompt(cb.Oid.Value, ViewContext, prompt.DataContract.Oid.Value),
cb2 =>
{
FinishSending();
ServiceFacade.EndManuelWaiting();
vm.Messages.VMList.Remove(msg_vm);
vm.AddMessages(cb2);
}, error);
},
error);
}
catch (Exception ex)
{
EndSending();
}
}
private void StartRoutine(AiPromptbausteinRoutineVM routine)
{
StartSending();
try
{
var conv = new AiConversationDC();
conv.Created = DateTime.Now;
conv.Updated = DateTime.Now;
conv.ActionType = ActionType;
var vm = InsertConverstion(conv);
Action<Exception> error = (e) =>
{
EndSending();
ListVM.VMList.Remove(vm);
ServiceFacade.EndManuelWaiting();
};
ServiceFacade.StartManuelWaiting();
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CreateAiConversation(conv, ViewContext), cb =>
{
vm.UpdateByDataContract(cb);
ExecuteChain(routine, 0, error);
}, error);
}
catch (Exception ex)
{
EndSending();
}
}
private void ExecuteChain(AiPromptbausteinRoutineVM routine, int step, Action<Exception> error)
{
if (step >= routine.Steps.Count)
{
FinishSending();
ServiceFacade.EndManuelWaiting();
return;
}
var msg = routine.Steps.VMList[step].PromptReference.Prompt;
var conv = ListVM.SelectedVM;
var msg_dc = new AiConversationMessageDC();
msg_dc.Message = msg;
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.ExecuteAiConversationWithRoutine(conv.Oid, ViewContext, routine.DataContract.Oid.Value, step),
cb =>
{
ViewContext.Secondary = cb.Last().Message;
conv.Messages.VMList.Remove(msg_vm);
conv.AddMessages(cb);
ExecuteChain(routine, step + 1, error);
}, error);
}
}
}

View File

@@ -1,4 +1,5 @@
using BS.Shared;
using BS.Shared.Interface.Feature.AICore;
using System;
using System.Diagnostics;
using System.Xml.Linq;
@@ -6,7 +7,7 @@ using System.Xml.Linq;
namespace BeWo.Data.Entities
{
[DebuggerDisplay("{ModelName}:{Value}")]
public class AiModel : BeWoEntityBase
public class AiModel : BeWoEntityBase, IAiModel
{
public AiModel()
{

View File

@@ -10,6 +10,7 @@ using System.Security.Cryptography;
using System.ServiceModel;
using System.Text;
using System.Web.Hosting;
using System.Windows.Interop;
using AICore.Context.Summary;
using AICore.Prompt;
using AICore.Prompt.SystemPrompts;
@@ -26,9 +27,11 @@ using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.DataContracts.Feature.AI.Functions.ServiceRecords;
using BS.Shared.Exceptions;
using BS.Shared.Extensions;
using BS.Shared.Interface.Feature.AICore;
using DevExpress.Charts.Native;
using DevExpress.CodeParser;
using DevExpress.DataAccess.Native.Sql;
using DevExpress.XtraCharts.Native;
using Newtonsoft.Json;
namespace BeWo.Service.Plugins
@@ -125,7 +128,7 @@ namespace BeWo.Service.Plugins
public virtual AiConversationDC CreateAiConversation(AiConversationDC conversation, AiViewContextDC view_context)
{
var conv = createAiConversation(conversation.ActionType, view_context);
var conv = createAiConversation(conversation.ActionType, view_context, null);
DAOFactory.GenericDAO.Insert(conv);
@@ -139,7 +142,9 @@ namespace BeWo.Service.Plugins
var conv = createAiConversation(conversation.ActionType, view_context, config);
var new_messages = sendNewMessage(conv, message, config);
addSystemPrompt(conv, view_context);
sendNewMessage(conv, message, false);
DAOFactory.GenericDAO.Insert(conv);
@@ -233,10 +238,15 @@ namespace BeWo.Service.Plugins
{
var conv = DAOFactory.GenericDAO.LoadByID<AiConversation>(conversation);
return sendNewMessage(conv, message);
return sendNewMessage(conv, message, true);
}
public virtual AiConversationMessageDC[] ExecuteAiConversationWithMessage(long conversation, AiViewContextDC view_context, long routine, int step)
public virtual AiConversationMessageDC[] ExecuteAiConversationWithPrompt(long conversation, AiViewContextDC view_context, long prompt_oid)
{
return executePrompt(conversation, view_context, prompt_oid, AiRoutineType.Stack);
}
public virtual AiConversationMessageDC[] ExecuteAiConversationWithRoutine(long conversation, AiViewContextDC view_context, long routine, int step)
{
var conv = DAOFactory.GenericDAO.LoadByID<AiConversation>(conversation);
@@ -244,30 +254,9 @@ namespace BeWo.Service.Plugins
var step_ent = routine_ent.Steps[step];
var message = step_ent.PromptReference.Prompt;
var prompt = step_ent.PromptReference;
var actionType = conv.ActionType;
var conv_messages = conv.Messages;
var conv_messages_filtered = conv_messages.Where(x => x.Role != AiConversationMessageRole.System);
var new_conv = createAiConversation(actionType, view_context);
if (routine_ent.RoutineType == AiRoutineType.Stack)
{
// Stack
return sendNewMessage(new_conv, message);
}
else if (routine_ent.RoutineType == AiRoutineType.Chain)
{
}
else
{
throw BeWoNotImplementedException.CreateFromEnum(routine_ent.RoutineType);
}
return sendNewMessage(conv, message);
return executePrompt(conversation, view_context, prompt.Oid.Value, routine_ent.RoutineType);
}
public virtual bool CheckContextSize(AiActionType actionType, AiViewContextDC view_context)
@@ -281,6 +270,8 @@ namespace BeWo.Service.Plugins
var conversation = createAiConversation(actionType, view_context);
addSystemPrompt(conversation, view_context);
return AiUtils.CheckSystemMessageContextSize(conversation.Messages.Select(x => x.Message), modell.ModelName, modell.Value, out var error);
}
@@ -363,11 +354,7 @@ namespace BeWo.Service.Plugins
var modell_oid = config.SelectedModel.Oid.Value;
var current_user = UserRightHelper.GetLoggedInUserWithOid();
var context_loaded = AiContextLoader.LoadContext(actionType, view_context);
var configPath = getPromptPath(actionType);
var system_prompt = AiSystemPromptFactory.BuildContext(actionType, configPath, context_loaded, context_Type);
var conv = new AiConversation();
conv.Created = DateTime.Now;
@@ -381,27 +368,44 @@ namespace BeWo.Service.Plugins
conv.Updated = DateTime.Now;
conv.ApplicationUserOid = current_user.Oid;
var msg = new AiConversationMessage();
msg.Message = system_prompt;
msg.AiConversation = conv;
msg.Role = AiConversationMessageRole.System;
msg.Created = DateTime.Now;
conv.Messages.Add(msg);
return conv;
}
protected virtual AiConversationMessageDC[] sendNewMessage(AiConversation conv, string message, AiConfigDC config = null)
protected virtual AiConversationMessage addSystemPrompt(AiConversation conversation, AiViewContextDC view_context, AiConfigDC config = null, AiPromptbausteinPrompt prompt = null)
{
CheckPermissions(conv.ActionType);
// Hole Config
if (config is null)
config = GetAiConfig();
var configModel = config.SelectedModel;
var configModelName = config.SelectedModel.ModelName;
var actionType = conversation.ActionType;
var context_Type = config.Context_Type;
var context_loaded = AiContextLoader.LoadContext(actionType, view_context, prompt?.SamplesCount);
var configPath = getPromptPath(actionType);
var system_prompt = AiSystemPromptFactory.BuildContext(actionType, configPath, context_loaded, context_Type);
var msg = new AiConversationMessage();
msg.Message = system_prompt;
msg.AiConversation = conversation;
msg.Role = AiConversationMessageRole.System;
msg.Created = DateTime.Now;
conversation.Messages.Add(msg);
return msg;
}
protected virtual AiConversationMessageDC[] sendNewMessage(AiConversation conv, string message, bool save = true)
{
CheckPermissions(conv.ActionType);
IAiModel configModel = conv.Modell;
if(configModel == null)
{
configModel = GetAiConfig().SelectedModel;
}
var configModelValue = configModel.Value;
var configModelName = configModel.ModelName;
var logger = ServiceLogger.GetRequestLogger(out string id);
// Build Payload
@@ -453,7 +457,7 @@ namespace BeWo.Service.Plugins
// Send Request, wait for Response
var dt_before_request = DateTime.Now;
var client = ServiceFacade.GetLLMApiClientByConfig(config.SelectedModel.ModelSource);
var client = ServiceFacade.GetLLMApiClientByConfig(configModel.ModelSource);
var response = client.SendAiMessageRequest(payload, out var message2, out var model, out var duration, logger);
@@ -471,7 +475,8 @@ namespace BeWo.Service.Plugins
conv.Messages.Add(assi_msg);
// Update conv.
DAOFactory.GenericDAO.Update(conv);
if(save)
DAOFactory.GenericDAO.Update(conv);
var assi_msg_dc = MapperFactory.AiConversationMessage.MapToNewDC(assi_msg);
@@ -543,5 +548,53 @@ namespace BeWo.Service.Plugins
throw new SecurityException("Invalid permissions");
}
}
private AiConversationMessageDC[] executePrompt(long conversation_oid, AiViewContextDC view_context, long prompt_oid, AiRoutineType aiRoutineType)
{
var ai_config = GetAiConfig();
var conversation = DAOFactory.GenericDAO.LoadByID<AiConversation>(conversation_oid);
var prompt = DAOFactory.GenericDAO.LoadByID<AiPromptbausteinPrompt>(prompt_oid);
var new_conv = createAiConversation(conversation.ActionType, view_context, ai_config);
var systemPrompt = addSystemPrompt(new_conv, view_context, ai_config, prompt);
var systemPromptDc = MapperFactory.AiConversationMessage.MapToNewDC(systemPrompt);
if (aiRoutineType == AiRoutineType.Chain)
{
// Conversation = (S(n), U(n)) => A(n)
}
else if (aiRoutineType == AiRoutineType.Stack)
{
// Conversation = (S(n), U(0), A(0), U(1), ..., U(n-1), A(n-1), U(n)) => A(n)
var messages_filtered = conversation.Messages.Where(m => m.Role != AiConversationMessageRole.System);
new_conv.Messages.AddRange(messages_filtered);
}
else
{
throw new ArgumentOutOfRangeException(nameof(aiRoutineType));
}
// Server Request
sendNewMessage(new_conv, prompt.Prompt, false).ToList();
var result = new List<AiConversationMessage>
{
systemPrompt,
new_conv.Messages.Last(x => x.Role == AiConversationMessageRole.User),
new_conv.Messages.Last(x => x.Role == AiConversationMessageRole.Assistent)
};
// Nachrichten in Konversation packen
foreach (var msg in result)
{
msg.AiConversation = conversation;
conversation.Messages.Add(msg);
}
DAOFactory.GenericDAO.Update(conversation);
return MapperFactory.AiConversationMessage.MapToNewDCs(result).ToArray();
}
}
}

View File

@@ -66,7 +66,11 @@ namespace BeWo.Service.ServiceContracts.Enhanced
[FaultContract(typeof(BeWoFault))]
[OperationContract]
AiConversationMessageDC[] ExecuteAiConversationWithMessage(long conversation, AiViewContextDC view_context, long routine, int step);
AiConversationMessageDC[] ExecuteAiConversationWithPrompt(long conversation, AiViewContextDC view_context, long prompt_oid);
[FaultContract(typeof(BeWoFault))]
[OperationContract]
AiConversationMessageDC[] ExecuteAiConversationWithRoutine(long conversation, AiViewContextDC view_context, long routine, int step);
[FaultContract(typeof(BeWoFault))]
[OperationContract]

View File

@@ -8,6 +8,7 @@ using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts.Feature.AI;
using BS.Shared.DataContracts.Feature.AI.Functions.ServiceRecords;
using DevExpress.Charts.Native;
using DevExpress.DataAccess.Native.Sql;
using System;
using System.Collections.Generic;
@@ -48,8 +49,11 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
public AiConversationMessageDC[] SendNewMessage(long conversation, string message)
=> GetAiService().SendNewMessage(conversation, message);
public AiConversationMessageDC[] ExecuteAiConversationWithMessage(long conversation, AiViewContextDC view_context, long routine, int step)
=> GetAiService().ExecuteAiConversationWithMessage(conversation, view_context, routine, step);
public AiConversationMessageDC[] ExecuteAiConversationWithPrompt(long conversation, AiViewContextDC view_context, long prompt_oid)
=> GetAiService().ExecuteAiConversationWithPrompt(conversation, view_context, prompt_oid);
public AiConversationMessageDC[] ExecuteAiConversationWithRoutine(long conversation, AiViewContextDC view_context, long routine, int step)
=> GetAiService().ExecuteAiConversationWithRoutine(conversation, view_context, routine, step);
public bool CheckContextSize(AiActionType actionType, AiViewContextDC view_context)
=> GetAiService().CheckContextSize(actionType, view_context);

View File

@@ -20,16 +20,16 @@ namespace BeWo.Service.ServiceUtils
{
public static class AiContextLoader
{
public static BaseContextSummary LoadContext(AiActionType actionType, AiViewContextDC view_context)
public static BaseContextSummary LoadContext(AiActionType actionType, AiViewContextDC view_context, int? sample_count = null)
{
switch (actionType)
{
case AiActionType.ServiceRecord:
break;
case AiActionType.ServiceRecordConversation:
return loadServiceRecordConversationContext(view_context.References);
return loadServiceRecordConversationContext(view_context.References, sample_count);
case AiActionType.ServiceRecordDocumentation:
return loadServiceRecordDocumentationContext(view_context.References, view_context.Secondary as string);
return loadServiceRecordDocumentationContext(view_context.References, view_context.Secondary as string, sample_count);
default:
break;
}
@@ -95,20 +95,20 @@ namespace BeWo.Service.ServiceUtils
throw BeWoNotImplementedException.CreateFromEnum(actionType);
}
private static BaseContextSummary loadServiceRecordConversationContext(Dictionary<TableID, long[]> context_reference)
private static BaseContextSummary loadServiceRecordConversationContext(Dictionary<TableID, long[]> context_reference, int? sample_count = null)
{
var customer = loadCompactCustomerDC(context_reference);
var serviceRecords = loadServiceRecordDCs(context_reference);
var serviceRecords = loadServiceRecordDCs(context_reference, sample_count);
var supportConcept = loadSupportConceptDC(context_reference);
var costBearer = supportConcept.CostBearerList.First(x => x.CostBearerOid == context_reference[TableID.CostBearer][0]);
return AiContextSummaryFactory.CreateServiceRecordNavigationContextSummary(serviceRecords, customer, costBearer, supportConcept);
}
private static BaseContextSummary loadServiceRecordDocumentationContext(Dictionary<TableID, long[]> context_reference, string doku_text)
private static BaseContextSummary loadServiceRecordDocumentationContext(Dictionary<TableID, long[]> context_reference, string doku_text, int? sample_count = null)
{
var customer = loadCompactCustomerDC(context_reference);
var serviceRecords = loadServiceRecordDCs(context_reference);
var serviceRecords = loadServiceRecordDCs(context_reference, sample_count);
var supportConcept = loadSupportConceptDC(context_reference);
var costBearer = supportConcept.CostBearerList.First(x => x.CostBearerOid == context_reference[TableID.CostBearer][0]);
@@ -127,8 +127,8 @@ namespace BeWo.Service.ServiceUtils
=> LoadDataContact<CompactCustomerDC_Customer, Customer, CompactCustomerDC>(MapperFactory.CompactCustomerDC_Customer, context_reference);
private static CompactSupportConceptDC loadSupportConceptDC(Dictionary<TableID, long[]> context_reference)
=> LoadDataContact<CompactSupportConceptDC_SupportConcept, SupportConcept, CompactSupportConceptDC>(MapperFactory.CompactSupportConceptDC_SupportConcept, context_reference);
private static IEnumerable<ServiceRecordDC> loadServiceRecordDCs(Dictionary<TableID, long[]> context_reference)
=> LoadDataContacts<ServiceRecordDC_ServiceRecord, ServiceRecord, ServiceRecordDC>(MapperFactory.ServiceRecordDC_ServiceRecord, context_reference);
private static IEnumerable<ServiceRecordDC> loadServiceRecordDCs(Dictionary<TableID, long[]> context_reference, int? sample_count = null)
=> LoadDataContacts<ServiceRecordDC_ServiceRecord, ServiceRecord, ServiceRecordDC>(MapperFactory.ServiceRecordDC_ServiceRecord, context_reference, sample_count);
private static TDC LoadDataContact<TMapper, TEntity, TDC>(TMapper mapper, Dictionary<TableID, long[]> context_reference)
where TMapper : AbstractIDCEntityMapper<TEntity, TDC>
@@ -143,7 +143,7 @@ namespace BeWo.Service.ServiceUtils
return dc;
}
private static IEnumerable<TDC> LoadDataContacts<TMapper, TEntity, TDC>(TMapper mapper, Dictionary<TableID, long[]> context_reference)
private static IEnumerable<TDC> LoadDataContacts<TMapper, TEntity, TDC>(TMapper mapper, Dictionary<TableID, long[]> context_reference, int? sample_count = null)
where TMapper : AbstractIDCEntityMapper<TEntity, TDC>
where TEntity : BeWoEntityBase, new()
where TDC : class, new()
@@ -151,8 +151,13 @@ namespace BeWo.Service.ServiceUtils
var example = new TEntity();
var tid = example.Tid;
var oids = context_reference[tid];
if (sample_count is int count)
oids = context_reference[tid].Take(count).ToArray();
var entities = DAOFactory.GenericDAO.LoadByIDs<TEntity>(oids);
var dcs = mapper.MapToNewDCs(entities);
return dcs;
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using BS.Shared.Interface.Feature.AICore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace BS.Shared.DataContracts.Feature.AI
{
[DataContract]
public class AiModelDC : BeWoDataContract, IComparable<AiModelDC>
public class AiModelDC : BeWoDataContract, IComparable<AiModelDC>, IAiModel
{
public AiModelDC()
{

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace BS.Shared.Interface.Feature.AICore
{
public interface IAiModel
{
AiModelSource ModelSource { get; }
string ModelName { get; }
int Value { get; }
}
}

View File

@@ -437,6 +437,7 @@
<Compile Include="Extensions\TimeIntervalExtensions.cs" />
<Compile Include="Interface\Abstract\IAddressable.cs" />
<Compile Include="Interface\Feature\AICore\IAiConversationMessage.cs" />
<Compile Include="Interface\Feature\AICore\IAiModel.cs" />
<Compile Include="Interface\Feature\AICore\IAiPromptbaustein.cs" />
<Compile Include="Interface\Feature\AICore\IAiPromptbausteinPrompt.cs" />
<Compile Include="Interface\Feature\AICore\IAiPromptbausteinRoutine.cs" />