mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 04:20:20 +00:00 
			
		
		
		
	Refactored language extensions
This commit is contained in:
		
							parent
							
								
									cb4fc33bdb
								
							
						
					
					
						commit
						8555b3a7cb
					
				@ -81,7 +81,7 @@ public partial class AssistantTextSummarizer : AssistantBaseCore
 | 
				
			|||||||
        this.CreateChatThread();
 | 
					        this.CreateChatThread();
 | 
				
			||||||
        var time = this.AddUserRequest(
 | 
					        var time = this.AddUserRequest(
 | 
				
			||||||
            $"""
 | 
					            $"""
 | 
				
			||||||
                {this.selectedTargetLanguage.Prompt(this.customTargetLanguage)}
 | 
					                {this.selectedTargetLanguage.PromptSummarizing(this.customTargetLanguage)}
 | 
				
			||||||
                {this.selectedComplexity.Prompt(this.expertInField)}
 | 
					                {this.selectedComplexity.Prompt(this.expertInField)}
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                Please summarize the following text:
 | 
					                Please summarize the following text:
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +0,0 @@
 | 
				
			|||||||
using AIStudio.Tools;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace AIStudio.Components.Pages.TextSummarizer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public static class CommonLanguagePrompts
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public static string Prompt(this CommonLanguages language, string customLanguage) => language switch
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        CommonLanguages.AS_IS => "Do not change the language of the text.",
 | 
					 | 
				
			||||||
        CommonLanguages.OTHER => $"Output your summary in {customLanguage}.",
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        _ => $"Output your summary in {language.Name()} ({language}).",
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -18,7 +18,7 @@ else
 | 
				
			|||||||
    <MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
 | 
					    <MudTextField T="string" Disabled="@this.isAgentRunning" @bind-Text="@this.inputText" Validation="@this.ValidatingText" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Label="Your input" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<EnumSelection T="CommonLanguages" NameFunc="@(language => this.GetDisplayName(language))" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidatingTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
 | 
					<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidatingTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
 | 
				
			||||||
<MudSelect T="Provider" @bind-Value="@this.providerSettings" Disabled="@this.isAgentRunning" Validation="@this.ValidatingProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-3 rounded-lg" Variant="Variant.Outlined">
 | 
					<MudSelect T="Provider" @bind-Value="@this.providerSettings" Disabled="@this.isAgentRunning" Validation="@this.ValidatingProvider" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Apps" Margin="Margin.Dense" Label="Provider" Class="mb-3 rounded-lg" Variant="Variant.Outlined">
 | 
				
			||||||
    @foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
 | 
					    @foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -67,12 +67,6 @@ public partial class AssistantTranslation : AssistantBaseCore
 | 
				
			|||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private string GetDisplayName(CommonLanguages language) => language switch
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        CommonLanguages.AS_IS => "Please select the target language",
 | 
					 | 
				
			||||||
        _ => language.Name()
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private async Task TranslateText(bool force)
 | 
					    private async Task TranslateText(bool force)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!this.inputIsValid)
 | 
					        if (!this.inputIsValid)
 | 
				
			||||||
@ -85,7 +79,7 @@ public partial class AssistantTranslation : AssistantBaseCore
 | 
				
			|||||||
        this.CreateChatThread();
 | 
					        this.CreateChatThread();
 | 
				
			||||||
        var time = this.AddUserRequest(
 | 
					        var time = this.AddUserRequest(
 | 
				
			||||||
            $"""
 | 
					            $"""
 | 
				
			||||||
                {this.selectedTargetLanguage.Prompt(this.customTargetLanguage)}
 | 
					                {this.selectedTargetLanguage.PromptTranslation(this.customTargetLanguage)}
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                The given text is:
 | 
					                The given text is:
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +0,0 @@
 | 
				
			|||||||
using AIStudio.Tools;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace AIStudio.Components.Pages.Translation;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public static class CommonLanguageExtension
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public static string Prompt(this CommonLanguages language, string customLanguage) => language switch
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        CommonLanguages.OTHER => $"Translate the text in {customLanguage}.",
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        _ => $"Translate the given text in {language.Name()} ({language}).",
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -19,4 +19,27 @@ public static class CommonLanguageExtensions
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
        _ => "Other",
 | 
					        _ => "Other",
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static string PromptSummarizing(this CommonLanguages language, string customLanguage) => language switch
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        CommonLanguages.AS_IS => "Do not change the language of the text.",
 | 
				
			||||||
 | 
					        CommonLanguages.OTHER => $"Output your summary in {customLanguage}.",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _ => $"Output your summary in {language.Name()} ({language}).",
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static string PromptTranslation(this CommonLanguages language, string customLanguage) => language switch
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        CommonLanguages.OTHER => $"Translate the text in {customLanguage}.",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _ => $"Translate the given text in {language.Name()} ({language}).",
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static string NameSelecting(this CommonLanguages language)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if(language is CommonLanguages.AS_IS)
 | 
				
			||||||
 | 
					            return "Please select the target language";
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return language.Name();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user