Skip to content

Commit

Permalink
handle empty LLM generations
Browse files Browse the repository at this point in the history
  • Loading branch information
jelni committed Dec 30, 2024
1 parent 0ac9ba1 commit 62e13b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/commands/gemini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,18 @@ impl CommandTrait for Gemini {
}
};

let enums::FormattedText::FormattedText(formatted_text) =
functions::parse_markdown(
FormattedText { text, ..Default::default() },
ctx.client_id,
)
.await?;
let formatted_text = if text.is_empty() {
FormattedText { text: "[no text generated]".into(), ..Default::default() }
} else {
let enums::FormattedText::FormattedText(formatted_text) =
functions::parse_markdown(
FormattedText { text, ..Default::default() },
ctx.client_id,
)
.await?;

formatted_text
};

if let Some(message) = message.as_ref() {
ctx.edit_message_formatted_text(message.id, formatted_text).await?;
Expand Down
14 changes: 11 additions & 3 deletions src/commands/groq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ impl CommandTrait for Llama {
write!(text, " [{}]", choice.finish_reason).unwrap();
}

let enums::FormattedText::FormattedText(formatted_text) =
functions::parse_markdown(FormattedText { text, ..Default::default() }, ctx.client_id)
.await?;
let formatted_text = if text.is_empty() {
FormattedText { text: "[no text generated]".into(), ..Default::default() }
} else {
let enums::FormattedText::FormattedText(formatted_text) = functions::parse_markdown(
FormattedText { text, ..Default::default() },
ctx.client_id,
)
.await?;

formatted_text
};

ctx.reply_formatted_text(formatted_text).await?;

Expand Down

0 comments on commit 62e13b6

Please sign in to comment.