Skip to content

Commit

Permalink
Fix potentially undefined local variables (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragjn authored Jun 24, 2024
1 parent 92a73c0 commit 427bab5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
12 changes: 7 additions & 5 deletions backend/migration/qdrant_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def migrate_collection(
except Exception as e:
raise e

dest_collection = None
try:
# prepare collection to be created at destination
dest_collection = CreateCollectionDto(
Expand Down Expand Up @@ -130,11 +131,12 @@ def migrate_collection(
)

except Exception as e:
with requests.delete(
url=f"{destination_backend_url.rstrip('/')}/v1/collections/{destination_collection_name}",
json=dest_collection,
) as r:
logger.debug("Destination collection entry deleted: ", r.json())
if dest_collection is not None:
with requests.delete(
url=f"{destination_backend_url.rstrip('/')}/v1/collections/{destination_collection_name}",
json=dest_collection,
) as r:
logger.debug("Destination collection entry deleted: ", r.json())
raise e

logger.debug(
Expand Down
3 changes: 1 addition & 2 deletions backend/migration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def migrate(
dest_client (QdrantBase): Destination client
source_collection_name (str): source collection names to migrate.
destination_collection_name (str): destination collection name.
recreate_on_collision (bool, optional): If True - recreate collection if it exists, otherwise
raise ValueError.
batch_size (int, optional): Batch size for scrolling and uploading vectors. Defaults to 100.
same_qdrant (bool, optional): If both source and dest client point to same qdrant
"""
if _has_custom_shards(source_client, source_collection_name):
raise ValueError(
Expand Down
3 changes: 3 additions & 0 deletions backend/modules/dataloaders/truefoundryloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def load_filtered_data(
download_info = dataset.download(path=dest_dir)
logger.debug(f"Data directory download info: {download_info}")

else:
raise ValueError(f"Unsupported data_source uri type {data_source.uri}")

if download_info:
if os.path.exists(os.path.join(download_info, "files")):
logger.debug("Files directory exists")
Expand Down
7 changes: 3 additions & 4 deletions backend/modules/parsers/multimodalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,14 @@ async def get_chunks(
"""
Asynchronously extracts text from a PDF file and returns it in chunks.
"""

final_texts = []
try:
if not filepath.endswith(".pdf"):
logger.error(
"Invalid file extension. MultiModalParser only supports PDF files."
)
return []

final_texts = list()
# Open the PDF file using pdfplumber
doc = fitz.open(filepath)

Expand All @@ -164,12 +163,12 @@ async def get_chunks(
# Iterate over each page in the PDF
logger.info(f"\n\nLoading all pages...")
for page in doc:
page_number = page.number + 1
try:
page_number = page.number + 1
# Convert the page to an image (RGB mode)
pix = page.get_pixmap(alpha=False)
img = np.frombuffer(pix.samples, dtype=np.uint8).reshape(
pix.h, pix.w, pix.n
(pix.h, pix.w, pix.n)
)

# Convert the image to base64
Expand Down
2 changes: 2 additions & 0 deletions backend/modules/query_controllers/multimodal/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def _get_multi_query_retriever(
base_retriever = self._get_contextual_compression_retriever(
vector_store, retriever_config
)
else:
raise ValueError(f"Unknown retriever_type {retriever_type}")

return MultiQueryRetriever.from_llm(
retriever=base_retriever,
Expand Down
1 change: 0 additions & 1 deletion backend/server/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def query_controller(tag: str = None):
Args:
tag (str, optional): The tag to use for OpenAPI documentation.
prefix (str, optional): The prefix to use for all routes.
Returns:
class: The decorated class.
Expand Down

0 comments on commit 427bab5

Please sign in to comment.