From 989c9fc2d46750dad469b6f8227f9b632fed0af0 Mon Sep 17 00:00:00 2001 From: sdcb Date: Tue, 24 Dec 2024 18:55:44 +0800 Subject: [PATCH] correct span request --- src/BE/Controllers/Chats/Chats/ChatController.cs | 14 ++++++++++++++ .../Chats/Chats/Dtos/FreshChatRequest.cs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/BE/Controllers/Chats/Chats/ChatController.cs b/src/BE/Controllers/Chats/Chats/ChatController.cs index 429c90a2..3b869146 100644 --- a/src/BE/Controllers/Chats/Chats/ChatController.cs +++ b/src/BE/Controllers/Chats/Chats/ChatController.cs @@ -98,6 +98,20 @@ public async Task GeneralChat( return BadRequest(ModelState); } + if (req.SpanIds.Length == 0) + { + return BadRequest("Spans must be provided"); + } + + foreach (int spanId in req.SpanIds) + { + if (spanId >= byte.MinValue && spanId <= byte.MaxValue) + { + continue; + } + return BadRequest("Invalid span id"); + } + // ensure request span id is unique if (req.SpanIds.Distinct().Count() != req.SpanIds.Length) { diff --git a/src/BE/Controllers/Chats/Chats/Dtos/FreshChatRequest.cs b/src/BE/Controllers/Chats/Chats/Dtos/FreshChatRequest.cs index 15174fd6..c15c3047 100644 --- a/src/BE/Controllers/Chats/Chats/Dtos/FreshChatRequest.cs +++ b/src/BE/Controllers/Chats/Chats/Dtos/FreshChatRequest.cs @@ -66,7 +66,7 @@ public override ChatRequest ToChatRequest() public record GeneralChatRequest : BaseChatRequest { [JsonPropertyName("spanIds")] - public required byte[] SpanIds { get; init; } + public required int[] SpanIds { get; init; } [JsonPropertyName("userMessage")] public required MessageContentRequest UserMessage { get; init; } @@ -80,7 +80,7 @@ public override ChatRequest ToChatRequest() { EncryptedChatId = EncryptedChatId, EncryptedMessageId = ParentAssistantMessageId, - Spans = SpanIds.Select(x => new InternalChatSpanRequest() { Id = x }).ToArray(), + Spans = SpanIds.Select(x => new InternalChatSpanRequest() { Id = (byte)x }).ToArray(), UserMessage = UserMessage }; }