mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-11 06:08:19 +00:00
Added the informal address to the BeyondFacts Lab (#1176)
This commit is contained in:
1 parent
b6c3fbb5db
commit
e77645f44c
48 files changed
+1254
-160
No files matched your search
@@ -40,6 +40,8 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
Some texts are longer notes in Markdown, with headings, paragraphs, or lists. Keep their
|
||||
Markdown and their line breaks exactly as they are, and translate only the words.
|
||||
|
||||
{I18NAddressPrompt.Section(this.SystemPromptLanguage(), this.translatesInformalVariant, this.formalTranslationOfText)}
|
||||
|
||||
# Target Audience
|
||||
The app is intended for everyone, not just IT specialists or scientists. When translating,
|
||||
make sure the texts are easy for everyone to understand.
|
||||
@@ -124,6 +126,16 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
private Dictionary<string, string> localizedContent = [];
|
||||
private StringBuilder finalLuaCode = new();
|
||||
private string? activeSystemPromptLanguage;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the text translated now is the informal variant of a text; see I18NAddressPrompt.
|
||||
/// </summary>
|
||||
private bool translatesInformalVariant;
|
||||
|
||||
/// <summary>
|
||||
/// The formal translation of the text translated now, when it is an informal variant and has one.
|
||||
/// </summary>
|
||||
private string? formalTranslationOfText;
|
||||
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
|
||||
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
|
||||
private static readonly AssistantSessionStateKey<bool> IS_LOADING_STATE_KEY = new(nameof(isLoading));
|
||||
@@ -362,7 +374,8 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
if (this.selectedTargetLanguage is not CommonLanguages.EN_US)
|
||||
{
|
||||
// Phase 1: Translate added content
|
||||
await this.Phase1TranslateAddedContent(addedContentSnapshot);
|
||||
var translatedBefore = selectedLanguageContentSnapshot.ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value, StringComparer.Ordinal);
|
||||
await this.Phase1TranslateAddedContent(addedContentSnapshot, translatedBefore);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -407,6 +420,8 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
finally
|
||||
{
|
||||
this.activeSystemPromptLanguage = null;
|
||||
this.translatesInformalVariant = false;
|
||||
this.formalTranslationOfText = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,12 +429,15 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
/// Translates the added text content from a stable snapshot.
|
||||
/// </summary>
|
||||
/// <param name="addedContentSnapshot">The added text entries captured when the job started.</param>
|
||||
/// <param name="translatedBefore">The texts of the language plugin, whose formal translations the informal variants start from.</param>
|
||||
/// <returns>A task that completes when all added text entries were translated or cancellation was requested.</returns>
|
||||
private async Task Phase1TranslateAddedContent(KeyValuePair<string, string>[] addedContentSnapshot)
|
||||
private async Task Phase1TranslateAddedContent(KeyValuePair<string, string>[] addedContentSnapshot, IReadOnlyDictionary<string, string> translatedBefore)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
var minimumTime = TimeSpan.FromMilliseconds(500);
|
||||
foreach (var keyValuePair in addedContentSnapshot)
|
||||
|
||||
// The informal variants start from the formal translations, so those come first:
|
||||
foreach (var keyValuePair in I18NAddressPrompt.FormalFirst(addedContentSnapshot))
|
||||
{
|
||||
if(this.CancellationTokenSource!.IsCancellationRequested)
|
||||
break;
|
||||
@@ -433,8 +451,11 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
|
||||
stopwatch.Start();
|
||||
|
||||
//
|
||||
// Translate one text at a time:
|
||||
// Translate one text at a time. Its own chat thread gets the system prompt
|
||||
// with the form of address of this text:
|
||||
//
|
||||
this.translatesInformalVariant = I18NAddressVariant.TryGetFormalKey(keyValuePair.Key, out _);
|
||||
this.formalTranslationOfText = this.translatesInformalVariant ? I18NAddressPrompt.FindFormalTranslation(keyValuePair.Key, this.localizedContent, translatedBefore) : null;
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(keyValuePair.Value);
|
||||
this.localizedContent.Add(keyValuePair.Key, await this.AddAIResponseAsync(time));
|
||||
|
||||
Reference in new issue
Block a user