from pydantic import BaseModel from app.server.chat.schemas import Chunk class Source(BaseModel): file: str page: str text: str class Config: frozen = True @staticmethod def curate_sources(sources: list[Chunk]) -> set["Source"]: curated_sources = set() for chunk in sources: doc_metadata = chunk.document.doc_metadata file_name = doc_metadata.get("file_name", "-") if doc_metadata else "-" 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) return curated_sources