-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rationalize metadata * remove unused file * bug fix * bug fix * removed retiever * s3_keys -> documents * bug fix * fix bug * formatting
- Loading branch information
Showing
11 changed files
with
17 additions
and
194 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +0,0 @@ | ||
from logging import getLogger | ||
|
||
from langchain_core.callbacks import CallbackManagerForRetrieverRun | ||
from langchain_core.documents import Document | ||
from langchain_core.retrievers import BaseRetriever | ||
|
||
from redbox.models.chain import RedboxState | ||
from typing import Any | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class DjangoFileRetriever(BaseRetriever): | ||
file_manager: Any = None | ||
|
||
def _get_relevant_documents( | ||
self, query: RedboxState, *, run_manager: CallbackManagerForRetrieverRun | ||
) -> list[Document]: | ||
selected_files = set(query.request.s3_keys) | ||
permitted_files = set(query.request.permitted_s3_keys) | ||
|
||
if not selected_files <= permitted_files: | ||
logger.warning( | ||
"User has selected files they aren't permitted to access: \n" | ||
f"{", ".join(selected_files - permitted_files)}" | ||
) | ||
|
||
file_names = list(selected_files & permitted_files) | ||
|
||
files = self.file_manager.filter(original_file__in=file_names, text__isnull=False) | ||
|
||
return [ | ||
Document( | ||
page_content=file.text, | ||
metadata={"uri": file.original_file.name}, | ||
) | ||
for file in files | ||
] | ||
|
||
|
||
def retriever_runnable(retriever: BaseRetriever): | ||
def _run(state: RedboxState): | ||
state.documents = retriever.invoke(state) | ||
return state | ||
|
||
return _run | ||
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters