Skip to content

Commit 290b9fb

Browse files
authored
feat(ui): add sources check to not repeat identical sources (#1705)
1 parent 1b03b36 commit 290b9fb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

private_gpt/ui/ui.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ def yield_deltas(completion_gen: CompletionGen) -> Iterable[str]:
9696
if completion_gen.sources:
9797
full_response += SOURCES_SEPARATOR
9898
cur_sources = Source.curate_sources(completion_gen.sources)
99-
sources_text = "\n\n\n".join(
100-
f"{index}. {source.file} (page {source.page})"
101-
for index, source in enumerate(cur_sources, start=1)
102-
)
99+
sources_text = "\n\n\n"
100+
used_files = set()
101+
for index, source in enumerate(cur_sources, start=1):
102+
if (source.file + "-" + source.page) not in used_files:
103+
sources_text = (
104+
sources_text
105+
+ f"{index}. {source.file} (page {source.page}) \n\n"
106+
)
107+
used_files.add(source.file + "-" + source.page)
103108
full_response += sources_text
104109
yield full_response
105110

0 commit comments

Comments
 (0)