Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/single_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
EXECUTOR_TYPE = 'thread'
EXECUTOR_MAX_WORKERS = 30
SESSION_TYPE = 'filesystem'
VERSION = "0.250.220"
VERSION = "0.250.221"
IS_DEVELOPMENT = is_development_env_enabled()

SESSION_COOKIE_SAMESITE = os.getenv('SESSION_COOKIE_SAMESITE', 'Lax')
Expand Down
80 changes: 80 additions & 0 deletions application/single_app/functions_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from functions_debug import debug_print
from config import *
from functions_office_media import extract_office_embedded_images

Check warning on line 13 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains dynamic execution, persistence, or system access marker. Recommendation%3A Do not execute changed lifecycle scripts or installers while this finding is unresolved.
import functions_settings
from functions_settings import *
from functions_logging import *
Expand Down Expand Up @@ -607,6 +608,85 @@
raise e


def resolve_extraction_engine_for_mode(extraction_mode, settings):
"""Resolve which engine backs the given extraction mode, plus a human-readable reason."""
if extraction_mode != 'layout':
return functions_settings.EXTRACTION_ENGINE_DOCUMENT_INTELLIGENCE, ''
return functions_settings.resolve_enhanced_extraction_engine(settings)


def extract_content_with_extraction_engine(
file_path,
extraction_mode,
extraction_engine=None,
settings=None,
pages=None,
):
"""Extract page content with the engine that backs the requested extraction mode.

Standard extraction always uses Document Intelligence ``prebuilt-read``. Enhanced extraction
prefers Azure AI Content Understanding, but always falls back to Document Intelligence
``prebuilt-layout`` so a Content Understanding outage never blocks ingestion.

Returns ``(pages_data, engine_used, fallback_reason)``.
"""
resolved_settings = settings if settings is not None else get_settings()

Check warning on line 633 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains secret or sensitive data source marker. Recommendation%3A Pair this source with any nearby network, logging, serialization, or process execution sink before approving.
if extraction_engine is None:
extraction_engine, _ = resolve_extraction_engine_for_mode(extraction_mode, resolved_settings)

if (
extraction_mode != 'layout'
or extraction_engine != functions_settings.EXTRACTION_ENGINE_CONTENT_UNDERSTANDING
):
return (
extract_content_with_azure_di(file_path, extraction_mode=extraction_mode, pages=pages),
functions_settings.EXTRACTION_ENGINE_DOCUMENT_INTELLIGENCE,
'',
)

from functions_content_understanding import extract_content_with_content_understanding

try:

Check warning on line 649 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains security control, sanitization, or audit marker. Recommendation%3A Confirm the change does not weaken auth, CSRF, CSP, XSS defenses, settings sanitization, redaction, audit logging, or tests.
content_understanding_pages = extract_content_with_content_understanding(
file_path,
pages=pages,
settings=resolved_settings,
)
if content_understanding_pages:
return (
content_understanding_pages,
functions_settings.EXTRACTION_ENGINE_CONTENT_UNDERSTANDING,
'',
)
fallback_reason = (
'Content Understanding returned no content, so Document Intelligence Layout was used'
)
log_event(

Check warning on line 664 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains security control, sanitization, or audit marker. Recommendation%3A Confirm the change does not weaken auth, CSRF, CSP, XSS defenses, settings sanitization, redaction, audit logging, or tests.
f"[EXTRACTION_ENGINE] Content Understanding returned no content for "
f"{os.path.basename(file_path)}; falling back to Document Intelligence Layout.",
level=logging.WARNING,
)
except Exception as content_understanding_error:

Check warning on line 669 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains security control, sanitization, or audit marker. Recommendation%3A Confirm the change does not weaken auth, CSRF, CSP, XSS defenses, settings sanitization, redaction, audit logging, or tests.
# The reason is persisted and rendered in workspace tooltips, so keep it short.

Check warning on line 670 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains AI, plugin, agent, or workspace boundary marker. Recommendation%3A Check whether prompts, chat history, uploaded documents, embeddings, citations, settings, or identity can cross a new boundary.
error_summary = " ".join(str(content_understanding_error).split())[:240]
fallback_reason = (
f'Content Understanding failed ({error_summary}), '
'so Document Intelligence Layout was used'
)
log_event(

Check warning on line 676 in application/single_app/functions_content.py

View workflow job for this annotation

GitHub Actions / malicious-pr-security-review

Important - Changed line contains security control, sanitization, or audit marker. Recommendation%3A Confirm the change does not weaken auth, CSRF, CSP, XSS defenses, settings sanitization, redaction, audit logging, or tests.
f"[EXTRACTION_ENGINE] Content Understanding failed for "
f"{os.path.basename(file_path)}: {content_understanding_error}. "
"Falling back to Document Intelligence Layout.",
level=logging.WARNING,
)

return (
extract_content_with_azure_di(file_path, extraction_mode='layout', pages=pages),
functions_settings.EXTRACTION_ENGINE_DOCUMENT_INTELLIGENCE,
fallback_reason,
)


def extract_table_file(file_path, file_ext):
try:
if file_ext == '.csv':
Expand Down
Loading
Loading