Merge remote-tracking branch 'origin/main' into feat/new-onboarding
This commit is contained in:
commit
a2fb385a1f
1 changed files with 45 additions and 78 deletions
65
src/main.py
65
src/main.py
|
|
@ -335,32 +335,13 @@ async def _ingest_default_documents_langflow(services, file_paths):
|
||||||
"""Ingest default documents using Langflow upload-ingest-delete pipeline."""
|
"""Ingest default documents using Langflow upload-ingest-delete pipeline."""
|
||||||
langflow_file_service = services["langflow_file_service"]
|
langflow_file_service = services["langflow_file_service"]
|
||||||
session_manager = services["session_manager"]
|
session_manager = services["session_manager"]
|
||||||
|
task_service = services["task_service"]
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Using Langflow ingestion pipeline for default documents",
|
"Using Langflow ingestion pipeline for default documents",
|
||||||
file_count=len(file_paths),
|
file_count=len(file_paths),
|
||||||
)
|
)
|
||||||
|
|
||||||
success_count = 0
|
|
||||||
error_count = 0
|
|
||||||
|
|
||||||
for file_path in file_paths:
|
|
||||||
try:
|
|
||||||
logger.debug("Processing file with Langflow pipeline", file_path=file_path)
|
|
||||||
|
|
||||||
# Read file content
|
|
||||||
with open(file_path, "rb") as f:
|
|
||||||
content = f.read()
|
|
||||||
|
|
||||||
# Create file tuple for upload
|
|
||||||
filename = os.path.basename(file_path)
|
|
||||||
# Determine content type based on file extension
|
|
||||||
content_type, _ = mimetypes.guess_type(filename)
|
|
||||||
if not content_type:
|
|
||||||
content_type = "application/octet-stream"
|
|
||||||
|
|
||||||
file_tuple = (filename, content, content_type)
|
|
||||||
|
|
||||||
# Use AnonymousUser details for default documents
|
# Use AnonymousUser details for default documents
|
||||||
from session_manager import AnonymousUser
|
from session_manager import AnonymousUser
|
||||||
|
|
||||||
|
|
@ -392,40 +373,26 @@ async def _ingest_default_documents_langflow(services, file_paths):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use langflow upload_and_ingest_file method with JWT token
|
# Create a langflow upload task for trackable progress
|
||||||
result = await langflow_file_service.upload_and_ingest_file(
|
task_id = await task_service.create_langflow_upload_task(
|
||||||
file_tuple=file_tuple,
|
user_id=None, # Anonymous user
|
||||||
session_id=None, # No session for default documents
|
file_paths=file_paths,
|
||||||
tweaks=default_tweaks, # Add anonymous user metadata
|
langflow_file_service=langflow_file_service,
|
||||||
settings=None, # Use default ingestion settings
|
session_manager=session_manager,
|
||||||
jwt_token=effective_jwt, # Use JWT token (anonymous if needed)
|
jwt_token=effective_jwt,
|
||||||
delete_after_ingest=True, # Clean up after ingestion
|
|
||||||
owner=None,
|
|
||||||
owner_name=anonymous_user.name,
|
owner_name=anonymous_user.name,
|
||||||
owner_email=anonymous_user.email,
|
owner_email=anonymous_user.email,
|
||||||
connector_type="system_default",
|
session_id=None, # No session for default documents
|
||||||
|
tweaks=default_tweaks,
|
||||||
|
settings=None, # Use default ingestion settings
|
||||||
|
delete_after_ingest=True, # Clean up after ingestion
|
||||||
|
replace_duplicates=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Successfully ingested file via Langflow",
|
"Started Langflow ingestion task for default documents",
|
||||||
file_path=file_path,
|
task_id=task_id,
|
||||||
result_status=result.get("status"),
|
file_count=len(file_paths),
|
||||||
)
|
|
||||||
success_count += 1
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
"Failed to ingest file via Langflow",
|
|
||||||
file_path=file_path,
|
|
||||||
error=str(e),
|
|
||||||
)
|
|
||||||
error_count += 1
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
"Langflow ingestion completed",
|
|
||||||
success_count=success_count,
|
|
||||||
error_count=error_count,
|
|
||||||
total_files=len(file_paths),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue