mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 16:52:57 +00:00
Additional messages from the chat templates are now used in the chats
This commit is contained in:
parent
527b2076fe
commit
ae678194f8
@ -60,4 +60,18 @@ public static class ExtensionsChatRole
|
||||
|
||||
_ => Icons.Material.Filled.Help,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns the specific name of the role for the chat template.
|
||||
/// </summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public static string ToChatTemplateName(this ChatRole role) => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => "System",
|
||||
ChatRole.USER => "User",
|
||||
ChatRole.AI => "Assistant",
|
||||
|
||||
_ => "Unknown",
|
||||
};
|
||||
}
|
@ -93,7 +93,7 @@ public sealed record ChatThread
|
||||
{
|
||||
|
||||
//
|
||||
// Prepare the prompts using the chatTemplate:
|
||||
// Use the information from the chat template, if provided. Otherwise, use the default system prompt
|
||||
//
|
||||
string systemPromptTextWithChatTemplate;
|
||||
var logMessage = $"Using no chat template for chat thread '{chatThread.Name}'.";
|
||||
@ -125,6 +125,9 @@ public sealed record ChatThread
|
||||
}
|
||||
logger.LogInformation(logMessage);
|
||||
|
||||
//
|
||||
// Add augmented data, if available:
|
||||
//
|
||||
var isAugmentedDataAvailable = !string.IsNullOrWhiteSpace(chatThread.AugmentedData);
|
||||
var systemPromptWithAugmentedData = isAugmentedDataAvailable switch
|
||||
{
|
||||
@ -144,7 +147,7 @@ public sealed record ChatThread
|
||||
|
||||
|
||||
//
|
||||
// Prepare the system prompt:
|
||||
// Add information from profile if available and allowed:
|
||||
//
|
||||
string systemPromptText;
|
||||
logMessage = $"Using no profile for chat thread '{chatThread.Name}'.";
|
||||
|
@ -29,4 +29,16 @@ public class ContentBlock
|
||||
/// Should the content block be hidden from the user?
|
||||
/// </summary>
|
||||
public bool HideFromUser { get; set; }
|
||||
|
||||
public ContentBlock DeepClone()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Time = this.Time,
|
||||
ContentType = this.ContentType,
|
||||
Content = this.Content?.DeepClone(),
|
||||
Role = this.Role,
|
||||
HideFromUser = this.HideFromUser,
|
||||
};
|
||||
}
|
||||
}
|
@ -32,6 +32,18 @@ public sealed class ContentImage : IContent, IImageSource
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent DeepClone()
|
||||
{
|
||||
return new ContentImage
|
||||
{
|
||||
Source = this.Source,
|
||||
InitialRemoteWait = this.InitialRemoteWait,
|
||||
IsStreaming = this.IsStreaming,
|
||||
SourceType = this.SourceType,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -125,6 +125,17 @@ public sealed class ContentText : IContent
|
||||
return chatThread;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent DeepClone()
|
||||
{
|
||||
return new ContentText
|
||||
{
|
||||
Text = this.Text,
|
||||
InitialRemoteWait = this.InitialRemoteWait,
|
||||
IsStreaming = this.IsStreaming,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
@ -43,6 +43,12 @@ public interface IContent
|
||||
/// </summary>
|
||||
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep copy
|
||||
/// </summary>
|
||||
/// <returns>The copy</returns>
|
||||
public IContent DeepClone();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the corresponding ERI content type.
|
||||
/// </summary>
|
||||
|
@ -334,6 +334,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
||||
this.ChatThread = this.ChatThread with
|
||||
{
|
||||
SelectedChatTemplate = this.currentChatTemplate.Id,
|
||||
Blocks = this.currentChatTemplate.AdditionalMessages.Select(x => x.DeepClone()).ToList(),
|
||||
};
|
||||
|
||||
await this.ChatThreadChanged.InvokeAsync(this.ChatThread);
|
||||
@ -440,7 +441,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
||||
DataSourceOptions = this.earlyDataSourceOptions,
|
||||
Name = this.ExtractThreadName(this.userInput),
|
||||
Seed = this.RNG.Next(),
|
||||
Blocks = [],
|
||||
Blocks = this.currentChatTemplate == default ? [] : this.currentChatTemplate.AdditionalMessages.Select(x => x.DeepClone()).ToList(),
|
||||
};
|
||||
|
||||
await this.ChatThreadChanged.InvokeAsync(this.ChatThread);
|
||||
@ -671,7 +672,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
||||
ChatId = Guid.NewGuid(),
|
||||
Name = string.Empty,
|
||||
Seed = this.RNG.Next(),
|
||||
Blocks = [],
|
||||
Blocks = this.currentChatTemplate == default ? [] : this.currentChatTemplate.AdditionalMessages.Select(x => x.DeepClone()).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@
|
||||
<MudSelect Label="Role" @bind-Value="context.Role" Required>
|
||||
@foreach (var role in availableRoles)
|
||||
{
|
||||
<MudSelectItem Value="@role">@role.ToName()</MudSelectItem>
|
||||
<MudSelectItem Value="@role">@role.ToChatTemplateName()</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudTd>
|
||||
|
Loading…
Reference in New Issue
Block a user