mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 10:00:21 +00:00 
			
		
		
		
	Handling of llm provider selection based on configured behavior
This commit is contained in:
		
							parent
							
								
									11b78a7bf3
								
							
						
					
					
						commit
						50c15994ec
					
				@ -64,7 +64,6 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
        // Configure the spellchecking for the user input:
 | 
			
		||||
        this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
 | 
			
		||||
 | 
			
		||||
        this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
 | 
			
		||||
        this.currentProfile = this.SettingsManager.GetPreselectedProfile(Tools.Components.CHAT);
 | 
			
		||||
        var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<ChatThread>(Event.SEND_TO_CHAT).FirstOrDefault();
 | 
			
		||||
        if (deferredContent is not null)
 | 
			
		||||
@ -107,6 +106,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
            this.mustLoadChat = true;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        this.SelectProviderWhenLoadingChat();
 | 
			
		||||
        await base.OnInitializedAsync();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -126,7 +126,10 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
            this.chatThread = await WorkspaceBehaviour.LoadChat(this.loadChat);
 | 
			
		||||
            
 | 
			
		||||
            if(this.chatThread is not null)
 | 
			
		||||
            {
 | 
			
		||||
                this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
 | 
			
		||||
                this.SelectProviderWhenLoadingChat();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.StateHasChanged();
 | 
			
		||||
        }
 | 
			
		||||
@ -394,6 +397,19 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
        this.hasUnsavedChanges = false;
 | 
			
		||||
        this.userInput = string.Empty;
 | 
			
		||||
        
 | 
			
		||||
        switch (this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior)
 | 
			
		||||
        {
 | 
			
		||||
            case AddChatProviderBehavior.ADDED_CHATS_USE_DEFAULT_PROVIDER:
 | 
			
		||||
                this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            default:
 | 
			
		||||
            case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
 | 
			
		||||
                if(this.providerSettings == default)
 | 
			
		||||
                    this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!useSameWorkspace)
 | 
			
		||||
        {
 | 
			
		||||
            this.chatThread = null;
 | 
			
		||||
@ -404,6 +420,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
        {
 | 
			
		||||
            this.chatThread = new()
 | 
			
		||||
            {
 | 
			
		||||
                SelectedProvider = this.providerSettings.Id,
 | 
			
		||||
                WorkspaceId = this.currentWorkspaceId,
 | 
			
		||||
                ChatId = Guid.NewGuid(),
 | 
			
		||||
                Name = string.Empty,
 | 
			
		||||
@ -487,6 +504,8 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
        this.currentWorkspaceId = this.chatThread?.WorkspaceId ?? Guid.Empty;
 | 
			
		||||
        this.currentWorkspaceName = this.chatThread is null ? string.Empty : await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
 | 
			
		||||
        
 | 
			
		||||
        this.SelectProviderWhenLoadingChat();
 | 
			
		||||
        
 | 
			
		||||
        this.userInput = string.Empty;
 | 
			
		||||
        if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)
 | 
			
		||||
        {
 | 
			
		||||
@ -506,6 +525,27 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
 | 
			
		||||
        this.chatThread = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void SelectProviderWhenLoadingChat()
 | 
			
		||||
    {
 | 
			
		||||
        var chatProvider = this.chatThread?.SelectedProvider;
 | 
			
		||||
        switch (this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior)
 | 
			
		||||
        {
 | 
			
		||||
            default:
 | 
			
		||||
            case LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE:
 | 
			
		||||
                this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT, chatProvider);
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            case LoadingChatProviderBehavior.ALWAYS_USE_DEFAULT_CHAT_PROVIDER:
 | 
			
		||||
                this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
 | 
			
		||||
                break;
 | 
			
		||||
            
 | 
			
		||||
            case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
 | 
			
		||||
                if(this.providerSettings == default)
 | 
			
		||||
                    this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #region Overrides of MSGComponentBase
 | 
			
		||||
 | 
			
		||||
    public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user