diff --git a/src/BE/Controllers/Chats/Chats/ChatController.cs b/src/BE/Controllers/Chats/Chats/ChatController.cs index 88b26585..a268dd10 100644 --- a/src/BE/Controllers/Chats/Chats/ChatController.cs +++ b/src/BE/Controllers/Chats/Chats/ChatController.cs @@ -67,17 +67,20 @@ public async Task StartConversationStreamed( } // ensure chat.ChatSpan contains all span ids that in request, otherwise return error - if (req.Spans.Any(x => !chat.ChatSpans.Any(y => y.SpanId == x.Id))) + if (req.MessageId == null) { - return BadRequest("Invalid span id"); + if (req.Spans.Any(x => !chat.ChatSpans.Any(y => y.SpanId == x.Id))) + { + return BadRequest("Invalid span id"); + } } // get span id -> model id mapping but request only contains span id, so we need to get model id from chat.ChatSpan Dictionary spanModelMapping = req.Spans.ToDictionary(x => x.Id, x => chat.ChatSpans.First(y => y.SpanId == x.Id).ModelId); Dictionary userModels = await userModelManager.GetUserModels(currentUser.Id, [.. spanModelMapping.Values], cancellationToken); - // ensure all model ids are valid - if (userModels.Count != spanModelMapping.Count) + // ensure spanModelMapping contains all userModels + if (spanModelMapping.Values.Any(x => !userModels.ContainsKey(x))) { return BadRequest("Invalid span model"); }