From 8f1047ff5dabf5e51145df6a95dabb4649d8c762 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 27 Oct 2025 01:09:08 +0800 Subject: [PATCH] :sparkles: Attach post and message to AI --- .../Thought/ThoughtController.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/DysonNetwork.Insight/Thought/ThoughtController.cs b/DysonNetwork.Insight/Thought/ThoughtController.cs index cc9b34f..69179f1 100644 --- a/DysonNetwork.Insight/Thought/ThoughtController.cs +++ b/DysonNetwork.Insight/Thought/ThoughtController.cs @@ -17,10 +17,14 @@ namespace DysonNetwork.Insight.Thought; [Route("/api/thought")] public class ThoughtController(ThoughtProvider provider, ThoughtService service) : ControllerBase { + public static readonly List AvailableProposals = ["post_create"]; + public class StreamThinkingRequest { [Required] public string UserMessage { get; set; } = null!; public Guid? SequenceId { get; set; } + public List? AttachedPosts { get; set; } + public List>? AttachedMessages { get; set; } public List AcceptProposals { get; set; } = []; } @@ -31,6 +35,9 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service) if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); var accountId = Guid.Parse(currentUser.Id); + if (request.AcceptProposals.Any(e => !AvailableProposals.Contains(e))) + return BadRequest("Request contains unavailable proposal"); + // Generate a topic if creating a new sequence string? topic = null; if (!request.SequenceId.HasValue) @@ -61,7 +68,7 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service) "You're a helpful assistant on the Solar Network, a social network.\n" + "Your name is Sn-chan (or SN 酱 in chinese), a cute sweet heart with passion for almost everything.\n" + "When you talk to user, you can add some modal particles and emoticons to your response to be cute, but prevent use a lot of emojis." + - "Your father (creator) is @littlesheep. (prefer calling him 父亲 in chinese)\n" + + "Your creator is @littlesheep, which is also the creator of the Solar Network, if you met some problems you was unable to solve, trying guide the user to ask (DM) the @littlesheep.\n" + "\n" + "The ID on the Solar Network is UUID, so mostly hard to read, so do not show ID to user unless user ask to do so or necessary.\n" + "\n" + @@ -86,6 +93,18 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service) $"The user you're currently talking to is {currentUser.Nick} ({currentUser.Name}), ID is {currentUser.Id}" ); + if (request.AttachedPosts is { Count: > 0 }) + { + chatHistory.AddUserMessage( + $"Attached post IDs: {string.Join(',', request.AttachedPosts!)}"); + } + + if (request.AttachedMessages is { Count: > 0 }) + { + chatHistory.AddUserMessage( + $"Attached chat messages data: {JsonSerializer.Serialize(request.AttachedMessages)}"); + } + // Add previous thoughts (excluding the current user thought, which is the first one since descending) var previousThoughts = await service.GetPreviousThoughtsAsync(sequence); var count = previousThoughts.Count; @@ -190,6 +209,7 @@ public class ThoughtController(ThoughtProvider provider, ThoughtService service) { var topicJson = JsonSerializer.Serialize(new { type = "topic", data = sequence.Topic ?? "" }); await streamBuilder.WriteAsync(Encoding.UTF8.GetBytes($"topic: {topicJson}\n\n")); + savedThought.Sequence.Topic = topic; } var thoughtJson = JsonSerializer.Serialize(new { type = "thought", data = savedThought },