Skip to content

Commit

Permalink
fix chat issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 23, 2024
1 parent ae04337 commit 642671f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/BE/Controllers/Chats/Chats/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ public async Task<IActionResult> 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<byte, short> spanModelMapping = req.Spans.ToDictionary(x => x.Id, x => chat.ChatSpans.First(y => y.SpanId == x.Id).ModelId);
Dictionary<short, UserModel> 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");
}
Expand Down

0 comments on commit 642671f

Please sign in to comment.