From f9a007c6a85899d31a9b38baf40fcad5daa0673d Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:25:23 -0700 Subject: [PATCH] Properly filter out failed web search downloads from attachments --- modules/web_search.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/web_search.py b/modules/web_search.py index a1e47253..2b6c6c40 100644 --- a/modules/web_search.py +++ b/modules/web_search.py @@ -38,7 +38,7 @@ def download_web_page(url, timeout=5): return text except Exception as e: logger.error(f"Error downloading {url}: {e}") - return f"[Error downloading content from {url}: {str(e)}]" + return "" def perform_web_search(query, num_pages=3, max_workers=5): @@ -74,9 +74,7 @@ def perform_web_search(query, num_pages=3, max_workers=5): 'url': url, 'content': content } - except Exception as e: - logger.error(f"Error downloading {url}: {e}") - # Include failed downloads with empty content + except Exception: search_results[index] = { 'title': title, 'url': url, @@ -108,7 +106,7 @@ def add_web_search_attachments(history, row_idx, user_message, search_query, sta return # Filter out failed downloads before adding attachments - successful_results = [result for result in search_results if result['content'] and result['content'].strip()] + successful_results = [result for result in search_results if result['content'].strip()] if not successful_results: logger.warning("No successful downloads to add as attachments") @@ -130,7 +128,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(successful_results)} successful 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}")