Skip to content

Commit

Permalink
feat:db context settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuridea committed Mar 5, 2024
1 parent 437c1e0 commit c2be716
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
42 changes: 40 additions & 2 deletions src/LLMService.DataProvider.Relational/Data/ChatDbContext.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -218,12 +223,45 @@ private void _configureChatMessage(EntityTypeBuilder<TMessage> 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<LLM_ModelType>());

// MessageDataType comments.
builder.Property(x => x.DataType)
.HasComment(_getCommentFromEnum<MessageDataType>());

// MessageContentType comments.
builder.Property(x => x.ContentType)
.HasComment(_getCommentFromEnum<MessageContentType>());
}

private static string _getCommentFromEnum<TEnum>()
where TEnum : Enum
{
StringBuilder comments = new();
var lists = Enum.GetValues(typeof(TEnum))
.Cast<TEnum>()
.Select(x => new
{
Value = (int)(object)x,
Name = x.ToString(),
DisplayName = x.GetAttribute<DisplayAttribute>()?.Name ?? "",
Description = x.GetAttribute<DescriptionAttribute>()?.Description ?? "",
});
foreach (var item in lists)
{
comments.Append($"{item.Name} = {item.Value}{(string.IsNullOrEmpty(item.Description) ? "" : $"({item.Description})")} | ");
}
return comments.ToString();
}

#endregion
}
Expand Down
4 changes: 1 addition & 3 deletions src/LLMService.DataProvider.Relational/Entity/ChatFolder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel.DataAnnotations;

namespace LLMService.DataProvider.Relational.Entity
namespace LLMService.DataProvider.Relational.Entity
{
/// <summary>
///
Expand Down
10 changes: 3 additions & 7 deletions src/LLMService.DataProvider.Relational/Entity/ChatMessage.cs
Original file line number Diff line number Diff line change
@@ -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
/// <summary>
///
/// </summary>
Expand All @@ -32,14 +29,14 @@ public class ChatMessage<TMessageKey, TConversationKey, TTenantKey, TUserKey>: I
/// <value>
/// The identifier.
/// </value>
public TMessageKey Id { get; set; }
public TMessageKey Id { get; set; }
/// <summary>
/// Gets or sets the conversation identifier.
/// </summary>
/// <value>
/// The conversation identifier.
/// </value>
public TConversationKey? ConversationId { get; set; }
public TConversationKey ConversationId { get; set; }
/// <summary>
/// Gets or sets the tenant identifier.
/// </summary>
Expand Down Expand Up @@ -120,5 +117,4 @@ public class ChatMessage<TMessageKey, TConversationKey, TTenantKey, TUserKey>: I


}
#nullable disable
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ComponentModel.DataAnnotations;

namespace LLMService.DataProvider.Relational.Entity
namespace LLMService.DataProvider.Relational.Entity
{
/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down

0 comments on commit c2be716

Please sign in to comment.