Skip to content

Commit

Permalink
Safety check before generating a prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
novosadkry committed Jul 10, 2024
1 parent 6d0179b commit d15312c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions NOVAxis/Modules/Chat/ChatModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public async Task CmdAiReply(IUserMessage message)

var reply = await RequestAiReply(message);

if (reply is null)
{
await FollowupAsync("Pro tuhle zprávu nelze vytvořit odpověď.", ephemeral: true);
return;
}

var id = InteractionCache.Store(message);
var components = AiReplyComponents(id).Build();

Expand Down Expand Up @@ -89,6 +95,19 @@ await interaction.UpdateAsync(x =>

var reply = await RequestAiReply(message);

if (reply is null)
{
InteractionCache.Remove(id);

await interaction.ModifyOriginalResponseAsync(x =>
{
x.Content = "Pro tuhle zprávu nelze vytvořit odpověď.";
x.Components = AiReplyComponents(id, disabled: true).Build();
});

return;
}

await interaction.ModifyOriginalResponseAsync(x =>
{
x.Content = reply;
Expand Down Expand Up @@ -137,6 +156,9 @@ where AllowedContentTypes.Contains(attachment.ContentType)
});
}

if (promptMessage.Content.Count == 0)
return null;

var request = new MessageParameters
{
MaxTokens = 128,
Expand Down

0 comments on commit d15312c

Please sign in to comment.