19
19
from onyx .connectors .google_drive .section_extraction import HEADING_DELIMITER
20
20
from onyx .connectors .google_utils .resources import get_drive_service
21
21
from onyx .connectors .google_utils .resources import get_google_docs_service
22
+ from onyx .connectors .google_utils .resources import GoogleDocsService
22
23
from onyx .connectors .google_utils .resources import GoogleDriveService
23
24
from onyx .connectors .models import ConnectorFailure
24
25
from onyx .connectors .models import Document
36
37
from onyx .file_processing .extract_file_text import xlsx_to_text
37
38
from onyx .file_processing .file_validation import is_valid_image_type
38
39
from onyx .file_processing .image_utils import store_image_and_create_section
39
- from onyx .utils .lazy import lazy_eval
40
40
from onyx .utils .logger import setup_logger
41
41
from onyx .utils .variable_functionality import (
42
42
fetch_versioned_implementation_with_fallback ,
@@ -146,7 +146,9 @@ def _download_and_extract_sections_basic(
146
146
147
147
# For other file types, download the file
148
148
# Use the correct API call for downloading files
149
- response_call = lazy_eval (lambda : download_request (service , file_id ))
149
+ # lazy evaluation to only download the file if necessary
150
+ def response_call () -> bytes :
151
+ return download_request (service , file_id )
150
152
151
153
# Process based on mime type
152
154
if mime_type == "text/plain" :
@@ -418,13 +420,14 @@ def _convert_drive_item_to_document(
418
420
Main entry point for converting a Google Drive file => Document object.
419
421
"""
420
422
sections : list [TextSection | ImageSection ] = []
423
+
421
424
# Only construct these services when needed
422
- drive_service = lazy_eval (
423
- lambda : get_drive_service (creds , user_email = retriever_email )
424
- )
425
- docs_service = lazy_eval (
426
- lambda : get_google_docs_service (creds , user_email = retriever_email )
427
- )
425
+ def _get_drive_service () -> GoogleDriveService :
426
+ return get_drive_service (creds , user_email = retriever_email )
427
+
428
+ def _get_docs_service () -> GoogleDocsService :
429
+ return get_google_docs_service (creds , user_email = retriever_email )
430
+
428
431
doc_id = "unknown"
429
432
430
433
try :
@@ -438,14 +441,14 @@ def _convert_drive_item_to_document(
438
441
try :
439
442
# get_document_sections is the advanced approach for Google Docs
440
443
doc_sections = get_document_sections (
441
- docs_service = docs_service (),
444
+ docs_service = _get_docs_service (),
442
445
doc_id = file .get ("id" , "" ),
443
446
)
444
447
if doc_sections :
445
448
sections = cast (list [TextSection | ImageSection ], doc_sections )
446
449
if any (SMART_CHIP_CHAR in section .text for section in doc_sections ):
447
450
basic_sections = _download_and_extract_sections_basic (
448
- file , drive_service (), allow_images
451
+ file , _get_drive_service (), allow_images
449
452
)
450
453
sections = align_basic_advanced (basic_sections , doc_sections )
451
454
@@ -470,7 +473,7 @@ def _convert_drive_item_to_document(
470
473
# If we don't have sections yet, use the basic extraction method
471
474
if not sections :
472
475
sections = _download_and_extract_sections_basic (
473
- file , drive_service (), allow_images
476
+ file , _get_drive_service (), allow_images
474
477
)
475
478
476
479
# If we still don't have any sections, skip this file
0 commit comments