feat(ui): maintain score order when curating sources (#1643)

* Update ui.py

Changed 'curated_sources' from a list, in order to maintain score order when returning the curated sources.

* Maintain score order after curating sources
This commit is contained in:
Hoffelhas 2024-03-11 22:27:30 +01:00 committed by GitHub
parent 290b9fb084
commit 410bf7a71f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 3 deletions

View File

@ -44,8 +44,8 @@ class Source(BaseModel):
frozen = True
@staticmethod
def curate_sources(sources: list[Chunk]) -> set["Source"]:
curated_sources = set()
def curate_sources(sources: list[Chunk]) -> list["Source"]:
curated_sources = []
for chunk in sources:
doc_metadata = chunk.document.doc_metadata
@ -54,7 +54,10 @@ class Source(BaseModel):
page_label = doc_metadata.get("page_label", "-") if doc_metadata else "-"
source = Source(file=file_name, page=page_label, text=chunk.text)
curated_sources.add(source)
curated_sources.append(source)
curated_sources = list(
dict.fromkeys(curated_sources).keys()
) # Unique sources only
return curated_sources