langflow_file_id init
This commit is contained in:
parent
6612388586
commit
1abb74a8ac
1 changed files with 34 additions and 32 deletions
|
|
@ -72,27 +72,28 @@ class LangflowConnectorService:
|
||||||
document.mimetype or "application/octet-stream",
|
document.mimetype or "application/octet-stream",
|
||||||
)
|
)
|
||||||
|
|
||||||
upload_result = await self.langflow_service.upload_user_file(
|
langflow_file_id = None # Initialize to track if upload succeeded
|
||||||
file_tuple, jwt_token
|
|
||||||
)
|
|
||||||
langflow_file_id = upload_result["id"]
|
|
||||||
langflow_file_path = upload_result["path"]
|
|
||||||
|
|
||||||
logger.debug(
|
|
||||||
"File uploaded to Langflow",
|
|
||||||
file_id=langflow_file_id,
|
|
||||||
path=langflow_file_path,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Step 2: Run ingestion flow with the uploaded file
|
|
||||||
logger.debug(
|
|
||||||
"Running Langflow ingestion flow", file_path=langflow_file_path
|
|
||||||
)
|
|
||||||
|
|
||||||
# Use the same tweaks pattern as LangflowFileService
|
|
||||||
tweaks = {} # Let Langflow handle the ingestion with default settings
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
upload_result = await self.langflow_service.upload_user_file(
|
||||||
|
file_tuple, jwt_token
|
||||||
|
)
|
||||||
|
langflow_file_id = upload_result["id"]
|
||||||
|
langflow_file_path = upload_result["path"]
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
"File uploaded to Langflow",
|
||||||
|
file_id=langflow_file_id,
|
||||||
|
path=langflow_file_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Step 2: Run ingestion flow with the uploaded file
|
||||||
|
logger.debug(
|
||||||
|
"Running Langflow ingestion flow", file_path=langflow_file_path
|
||||||
|
)
|
||||||
|
|
||||||
|
# Use the same tweaks pattern as LangflowFileService
|
||||||
|
tweaks = {} # Let Langflow handle the ingestion with default settings
|
||||||
|
|
||||||
ingestion_result = await self.langflow_service.run_ingestion_flow(
|
ingestion_result = await self.langflow_service.run_ingestion_flow(
|
||||||
file_paths=[langflow_file_path],
|
file_paths=[langflow_file_path],
|
||||||
jwt_token=jwt_token,
|
jwt_token=jwt_token,
|
||||||
|
|
@ -126,18 +127,19 @@ class LangflowConnectorService:
|
||||||
error=str(e),
|
error=str(e),
|
||||||
)
|
)
|
||||||
# Try to clean up Langflow file if upload succeeded but processing failed
|
# Try to clean up Langflow file if upload succeeded but processing failed
|
||||||
try:
|
if langflow_file_id is not None:
|
||||||
await self.langflow_service.delete_user_file(langflow_file_id)
|
try:
|
||||||
logger.debug(
|
await self.langflow_service.delete_user_file(langflow_file_id)
|
||||||
"Cleaned up Langflow file after error",
|
logger.debug(
|
||||||
file_id=langflow_file_id,
|
"Cleaned up Langflow file after error",
|
||||||
)
|
file_id=langflow_file_id,
|
||||||
except Exception as cleanup_error:
|
)
|
||||||
logger.warning(
|
except Exception as cleanup_error:
|
||||||
"Failed to cleanup Langflow file",
|
logger.warning(
|
||||||
file_id=langflow_file_id,
|
"Failed to cleanup Langflow file",
|
||||||
error=str(cleanup_error),
|
file_id=langflow_file_id,
|
||||||
)
|
error=str(cleanup_error),
|
||||||
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _get_file_extension(self, mimetype: str) -> str:
|
def _get_file_extension(self, mimetype: str) -> str:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue