From 981f7170f7955100c4a9bf43b88173b3208498f1 Mon Sep 17 00:00:00 2001 From: jel <25802745+jelni@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:45:56 +0100 Subject: [PATCH] acknowledge empty LLM generations --- src/commands/gemini.rs | 18 ++++++++++++------ src/commands/groq.rs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/commands/gemini.rs b/src/commands/gemini.rs index 53f4751..5f1df80 100644 --- a/src/commands/gemini.rs +++ b/src/commands/gemini.rs @@ -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.trim().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?; diff --git a/src/commands/groq.rs b/src/commands/groq.rs index 7127558..bd1c106 100644 --- a/src/commands/groq.rs +++ b/src/commands/groq.rs @@ -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.trim().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?;