From 290b9fb084632216300e89bdadbfeb0380724b12 Mon Sep 17 00:00:00 2001 From: icsy7867 Date: Mon, 11 Mar 2024 17:24:18 -0400 Subject: [PATCH] feat(ui): add sources check to not repeat identical sources (#1705) --- private_gpt/ui/ui.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/private_gpt/ui/ui.py b/private_gpt/ui/ui.py index bcc1f67..9b3decf 100644 --- a/private_gpt/ui/ui.py +++ b/private_gpt/ui/ui.py @@ -96,10 +96,15 @@ class PrivateGptUi: if completion_gen.sources: full_response += SOURCES_SEPARATOR cur_sources = Source.curate_sources(completion_gen.sources) - sources_text = "\n\n\n".join( - f"{index}. {source.file} (page {source.page})" - for index, source in enumerate(cur_sources, start=1) - ) + sources_text = "\n\n\n" + used_files = set() + for index, source in enumerate(cur_sources, start=1): + if (source.file + "-" + source.page) not in used_files: + sources_text = ( + sources_text + + f"{index}. {source.file} (page {source.page}) \n\n" + ) + used_files.add(source.file + "-" + source.page) full_response += sources_text yield full_response