diff --git a/src/LLMService.DataProvider.Relational/Data/ChatDbContext.cs b/src/LLMService.DataProvider.Relational/Data/ChatDbContext.cs index c81ed3d..b55d8db 100644 --- a/src/LLMService.DataProvider.Relational/Data/ChatDbContext.cs +++ b/src/LLMService.DataProvider.Relational/Data/ChatDbContext.cs @@ -1,7 +1,12 @@ using LLMService.DataProvider.Relational.Entity; +using LLMService.Shared.Extensions; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Text; +using static LLMService.DataProvider.Relational.Entity.EntityConsts; +using static LLMService.Shared.Models.LLMApiDefaults; namespace LLMService.DataProvider.Relational.Data { @@ -218,12 +223,45 @@ private void _configureChatMessage(EntityTypeBuilder builder) builder.ToTable("ChatMessage"); builder.HasKey(x => x.Id); + builder.Property(x => x.ConversationId) + .IsRequired(true); + builder.Property(x => x.Role) .HasMaxLength(256); - } + // model type comments. + builder.Property(x => x.ModelType) + .HasComment(_getCommentFromEnum()); + // MessageDataType comments. + builder.Property(x => x.DataType) + .HasComment(_getCommentFromEnum()); + + // MessageContentType comments. + builder.Property(x => x.ContentType) + .HasComment(_getCommentFromEnum()); + } + + private static string _getCommentFromEnum() + where TEnum : Enum + { + StringBuilder comments = new(); + var lists = Enum.GetValues(typeof(TEnum)) + .Cast() + .Select(x => new + { + Value = (int)(object)x, + Name = x.ToString(), + DisplayName = x.GetAttribute()?.Name ?? "", + Description = x.GetAttribute()?.Description ?? "", + }); + foreach (var item in lists) + { + comments.Append($"{item.Name} = {item.Value}{(string.IsNullOrEmpty(item.Description) ? "" : $"({item.Description})")} | "); + } + return comments.ToString(); + } #endregion } diff --git a/src/LLMService.DataProvider.Relational/Entity/ChatFolder.cs b/src/LLMService.DataProvider.Relational/Entity/ChatFolder.cs index 84c5072..53a0807 100644 --- a/src/LLMService.DataProvider.Relational/Entity/ChatFolder.cs +++ b/src/LLMService.DataProvider.Relational/Entity/ChatFolder.cs @@ -1,6 +1,4 @@ -using System.ComponentModel.DataAnnotations; - -namespace LLMService.DataProvider.Relational.Entity +namespace LLMService.DataProvider.Relational.Entity { /// /// diff --git a/src/LLMService.DataProvider.Relational/Entity/ChatMessage.cs b/src/LLMService.DataProvider.Relational/Entity/ChatMessage.cs index 150cfdf..c3bfaa8 100644 --- a/src/LLMService.DataProvider.Relational/Entity/ChatMessage.cs +++ b/src/LLMService.DataProvider.Relational/Entity/ChatMessage.cs @@ -1,11 +1,8 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using static LLMService.DataProvider.Relational.Entity.EntityConsts; +using static LLMService.DataProvider.Relational.Entity.EntityConsts; using static LLMService.Shared.Models.LLMApiDefaults; namespace LLMService.DataProvider.Relational.Entity { -#nullable enable /// /// /// @@ -32,14 +29,14 @@ public class ChatMessage: I /// /// The identifier. /// - public TMessageKey Id { get; set; } + public TMessageKey Id { get; set; } /// /// Gets or sets the conversation identifier. /// /// /// The conversation identifier. /// - public TConversationKey? ConversationId { get; set; } + public TConversationKey ConversationId { get; set; } /// /// Gets or sets the tenant identifier. /// @@ -120,5 +117,4 @@ public class ChatMessage: I } -#nullable disable } diff --git a/src/LLMService.DataProvider.Relational/Entity/Conversation.cs b/src/LLMService.DataProvider.Relational/Entity/Conversation.cs index c3ab796..c9ab215 100644 --- a/src/LLMService.DataProvider.Relational/Entity/Conversation.cs +++ b/src/LLMService.DataProvider.Relational/Entity/Conversation.cs @@ -1,6 +1,4 @@ -using System.ComponentModel.DataAnnotations; - -namespace LLMService.DataProvider.Relational.Entity +namespace LLMService.DataProvider.Relational.Entity { /// /// diff --git a/src/LLMService.DataProvider.Relational/Provider/ChatStorage.cs b/src/LLMService.DataProvider.Relational/Provider/ChatStorage.cs index dfb80c9..990cfbd 100644 --- a/src/LLMService.DataProvider.Relational/Provider/ChatStorage.cs +++ b/src/LLMService.DataProvider.Relational/Provider/ChatStorage.cs @@ -1,10 +1,5 @@ using LLMService.DataProvider.Relational.Entity; using LLMService.Shared.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LLMService.DataProvider.Relational.Provider { diff --git a/src/LLMService.DataProvider.Relational/Provider/IChatStorage.cs b/src/LLMService.DataProvider.Relational/Provider/IChatStorage.cs index 8ccbebd..b01895d 100644 --- a/src/LLMService.DataProvider.Relational/Provider/IChatStorage.cs +++ b/src/LLMService.DataProvider.Relational/Provider/IChatStorage.cs @@ -1,9 +1,4 @@ using LLMService.Shared.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LLMService.DataProvider.Relational.Provider {