format langflow_file_service.py
This commit is contained in:
parent
b19890fa4d
commit
8d1b4f7cf6
1 changed files with 39 additions and 25 deletions
|
|
@ -113,7 +113,9 @@ class LangflowFileService:
|
|||
# Initialize the OpenSearch component tweaks if not already present
|
||||
if "OpenSearchVectorStoreComponent-YnJox" not in tweaks:
|
||||
tweaks["OpenSearchVectorStoreComponent-YnJox"] = {}
|
||||
tweaks["OpenSearchVectorStoreComponent-YnJox"]["docs_metadata"] = metadata_tweaks
|
||||
tweaks["OpenSearchVectorStoreComponent-YnJox"]["docs_metadata"] = (
|
||||
metadata_tweaks
|
||||
)
|
||||
logger.debug(
|
||||
"[LF] Added metadata to tweaks", metadata_count=len(metadata_tweaks)
|
||||
)
|
||||
|
|
@ -192,10 +194,12 @@ class LangflowFileService:
|
|||
extra={
|
||||
"file_id": upload_result.get("id"),
|
||||
"file_path": upload_result.get("path"),
|
||||
}
|
||||
},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("[LF] Upload failed during combined operation", extra={"error": str(e)})
|
||||
logger.error(
|
||||
"[LF] Upload failed during combined operation", extra={"error": str(e)}
|
||||
)
|
||||
raise Exception(f"Upload failed: {str(e)}")
|
||||
|
||||
# Step 2: Prepare for ingestion
|
||||
|
|
@ -207,7 +211,9 @@ class LangflowFileService:
|
|||
final_tweaks = tweaks.copy() if tweaks else {}
|
||||
|
||||
if settings:
|
||||
logger.debug("[LF] Applying ingestion settings", extra={"settings": settings})
|
||||
logger.debug(
|
||||
"[LF] Applying ingestion settings", extra={"settings": settings}
|
||||
)
|
||||
|
||||
# Split Text component tweaks (SplitText-PC36h)
|
||||
if (
|
||||
|
|
@ -218,7 +224,9 @@ class LangflowFileService:
|
|||
if "SplitText-PC36h" not in final_tweaks:
|
||||
final_tweaks["SplitText-PC36h"] = {}
|
||||
if settings.get("chunkSize"):
|
||||
final_tweaks["SplitText-PC36h"]["chunk_size"] = settings["chunkSize"]
|
||||
final_tweaks["SplitText-PC36h"]["chunk_size"] = settings[
|
||||
"chunkSize"
|
||||
]
|
||||
if settings.get("chunkOverlap"):
|
||||
final_tweaks["SplitText-PC36h"]["chunk_overlap"] = settings[
|
||||
"chunkOverlap"
|
||||
|
|
@ -230,9 +238,14 @@ class LangflowFileService:
|
|||
if settings.get("embeddingModel"):
|
||||
if "OpenAIEmbeddings-joRJ6" not in final_tweaks:
|
||||
final_tweaks["OpenAIEmbeddings-joRJ6"] = {}
|
||||
final_tweaks["OpenAIEmbeddings-joRJ6"]["model"] = settings["embeddingModel"]
|
||||
final_tweaks["OpenAIEmbeddings-joRJ6"]["model"] = settings[
|
||||
"embeddingModel"
|
||||
]
|
||||
|
||||
logger.debug("[LF] Final tweaks with settings applied", extra={"tweaks": final_tweaks})
|
||||
logger.debug(
|
||||
"[LF] Final tweaks with settings applied",
|
||||
extra={"tweaks": final_tweaks},
|
||||
)
|
||||
|
||||
# Step 3: Run ingestion
|
||||
try:
|
||||
|
|
@ -246,10 +259,7 @@ class LangflowFileService:
|
|||
except Exception as e:
|
||||
logger.error(
|
||||
"[LF] Ingestion failed during combined operation",
|
||||
extra={
|
||||
"error": str(e),
|
||||
"file_path": file_path
|
||||
}
|
||||
extra={"error": str(e), "file_path": file_path},
|
||||
)
|
||||
# Note: We could optionally delete the uploaded file here if ingestion fails
|
||||
raise Exception(f"Ingestion failed: {str(e)}")
|
||||
|
|
@ -261,7 +271,10 @@ class LangflowFileService:
|
|||
|
||||
if delete_after_ingest and file_id:
|
||||
try:
|
||||
logger.debug("[LF] Deleting file after successful ingestion", extra={"file_id": file_id})
|
||||
logger.debug(
|
||||
"[LF] Deleting file after successful ingestion",
|
||||
extra={"file_id": file_id},
|
||||
)
|
||||
await self.delete_user_file(file_id)
|
||||
delete_result = {"status": "deleted", "file_id": file_id}
|
||||
logger.debug("[LF] File deleted successfully")
|
||||
|
|
@ -269,19 +282,20 @@ class LangflowFileService:
|
|||
delete_error = str(e)
|
||||
logger.warning(
|
||||
"[LF] Failed to delete file after ingestion",
|
||||
extra={
|
||||
"error": delete_error,
|
||||
"file_id": file_id
|
||||
}
|
||||
extra={"error": delete_error, "file_id": file_id},
|
||||
)
|
||||
delete_result = {"status": "delete_failed", "file_id": file_id, "error": delete_error}
|
||||
delete_result = {
|
||||
"status": "delete_failed",
|
||||
"file_id": file_id,
|
||||
"error": delete_error,
|
||||
}
|
||||
|
||||
# Return combined result
|
||||
result = {
|
||||
"status": "success",
|
||||
"upload": upload_result,
|
||||
"ingestion": ingest_result,
|
||||
"message": f"File '{upload_result.get('name')}' uploaded and ingested successfully"
|
||||
"message": f"File '{upload_result.get('name')}' uploaded and ingested successfully",
|
||||
}
|
||||
|
||||
if delete_after_ingest:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue