Skip to content

Commit

Permalink
Code(API::ChatSession) Extend ChatSession with AssistantId
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutak1337 committed Jun 10, 2024
1 parent 8cde423 commit aa7d7c0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
internal class ChatSessionDocument : IIdentifiable<Guid>
{
public Guid Id { get; set; }
public Guid AssistantId { get; set; }
public string Title { get; set; } = string.Empty;
public string Metaprompt { get; set; } = string.Empty;
public HashSet<string> ActivePlugins { get; set; } = new();
public string AvatarUrl { get; set; } = string.Empty;
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
internal class ChatSession
{
public Guid Id { get; set; }
public Guid AssistantId { get; set; }
public string Title { get; set; }
public string Metaprompt { get; set; }
public HashSet<string> ActivePlugins { get; set; } = new();
public string AvatarUrl { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }

public ChatSession(Guid id, string title, string metaprompt, HashSet<string> activePlugins, string avatarUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt)
public ChatSession(Guid id, Guid assistantId, string title, string metaprompt, HashSet<string> activePlugins, DateTimeOffset createdAt, DateTimeOffset updatedAt)
{
Id = id;
AssistantId = assistantId;
Title = title;
Metaprompt = metaprompt;
ActivePlugins = activePlugins;
AvatarUrl = avatarUrl;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
}

public static ChatSession Create(Guid id, string title, string metaprompt, HashSet<string> activePlugins, string avatarUrl, DateTimeOffset createdAt, DateTimeOffset updatedAt)
=> new(id, title, metaprompt, activePlugins, avatarUrl, createdAt, updatedAt);
public static ChatSession Create(Guid id, Guid assistantId, string title, string metaprompt, HashSet<string> activePlugins, DateTimeOffset createdAt, DateTimeOffset updatedAt)
=> new(id, assistantId, title, metaprompt, activePlugins, createdAt, updatedAt);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace StellarChat.Server.Api.Features.Chat.CreateChatSession;

internal sealed record CreateChatSession([Required] Guid ChatId, string Title, string AvatarUrl) : ICommand;
internal sealed record CreateChatSession([Required] Guid ChatId, Guid AssistantId, string Title) : ICommand;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async ValueTask<Unit> Handle(CreateChatSession command, CancellationToken
// TODO: Retrieve activePlugins and metaprompt from settings
var activePlugins = new HashSet<string>();

var chatSession = ChatSession.Create(command.ChatId, command.Title, metaprompt: "", activePlugins, command.AvatarUrl, createdAt: now, updatedAt: now);
var chatSession = ChatSession.Create(command.ChatId, command.AssistantId, command.Title, metaprompt: "", activePlugins, createdAt: now, updatedAt: now);

await _chatSessionRepository.AddAsync(chatSession);
_logger.LogInformation($"Chat session with ID: '{chatSession.Id}' has been created.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace StellarChat.Shared.Contracts.Chat;

public record CreateChatSessionRequest([property: JsonIgnore] Guid? ChatId, string Title, string AvatarUrl);
public record CreateChatSessionRequest([property: JsonIgnore] Guid? ChatId, Guid AssistantId, string Title);

0 comments on commit aa7d7c0

Please sign in to comment.