From 379dd01ca7770484bbd0798252665935a0bbfa05 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:32:07 -0700 Subject: [PATCH] Filter out failed web search downloads from attachments --- modules/web_search.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/web_search.py b/modules/web_search.py index 1f670349..a1e47253 100644 --- a/modules/web_search.py +++ b/modules/web_search.py @@ -107,6 +107,13 @@ def add_web_search_attachments(history, row_idx, user_message, search_query, sta logger.warning("No search results found") return + # Filter out failed downloads before adding attachments + successful_results = [result for result in search_results if result['content'] and result['content'].strip()] + + if not successful_results: + logger.warning("No successful downloads to add as attachments") + return + # Add search results as attachments key = f"user_{row_idx}" if key not in history['metadata']: @@ -114,7 +121,7 @@ def add_web_search_attachments(history, row_idx, user_message, search_query, sta if "attachments" not in history['metadata'][key]: history['metadata'][key]["attachments"] = [] - for result in search_results: + for result in successful_results: attachment = { "name": result['title'], "type": "text/html", @@ -123,7 +130,7 @@ def add_web_search_attachments(history, row_idx, user_message, search_query, sta } history['metadata'][key]["attachments"].append(attachment) - logger.info(f"Added {len(search_results)} web search results as attachments") + logger.info(f"Added {len(successful_results)} successful web search results as attachments") except Exception as e: logger.error(f"Error in web search: {e}")