Skip to content

Commit

Permalink
add sources, titles and page_content to QueryResult Model
Browse files Browse the repository at this point in the history
  • Loading branch information
KevKibe committed Apr 30, 2024
1 parent 13c181b commit 7642579
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/utils/response_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,28 @@ class QueryResult(BaseModel):
page: Union[float, int] = Field(..., description="The page number of the final result of the query.")
source_documents: List[Document] = Field(..., description="A list of source documents related to the query.")

# Example usage:
@property
def sources(self) -> List[Union[float, int]]:
"""
Returns a list of the sources (page numbers) from the source documents.
"""
return [doc.source for doc in self.source_documents]

@property
def titles(self) -> List[str]:
"""
Returns a list of the titles from the source documents.
"""
return [doc.title for doc in self.source_documents]

@property
def page_contents(self) -> List[str]:
"""
Returns a list of the page contents from the source documents.
"""
return [doc.page_content for doc in self.source_documents]

# Example
# data = {
# 'query': 'how did RAG come up?',
# 'result': 'RAG came up as a language model that is more strongly grounded in '
Expand Down

0 comments on commit 7642579

Please sign in to comment.