Merge branch 'main' of https://github.com/langflow-ai/openrag into page-style-alignment
This commit is contained in:
commit
2b9bbd7d09
3 changed files with 28 additions and 5 deletions
|
|
@ -56,6 +56,7 @@ async def run_ingestion(
|
|||
payload = await request.json()
|
||||
file_ids = payload.get("file_ids")
|
||||
file_paths = payload.get("file_paths") or []
|
||||
file_metadata = payload.get("file_metadata") or [] # List of {filename, mimetype, size}
|
||||
session_id = payload.get("session_id")
|
||||
tweaks = payload.get("tweaks") or {}
|
||||
settings = payload.get("settings", {})
|
||||
|
|
@ -66,6 +67,21 @@ async def run_ingestion(
|
|||
{"error": "Provide file_paths or file_ids"}, status_code=400
|
||||
)
|
||||
|
||||
# Build file_tuples from file_metadata if provided, otherwise use empty strings
|
||||
file_tuples = []
|
||||
for i, file_path in enumerate(file_paths):
|
||||
if i < len(file_metadata):
|
||||
meta = file_metadata[i]
|
||||
filename = meta.get("filename", "")
|
||||
mimetype = meta.get("mimetype", "application/octet-stream")
|
||||
# For files already uploaded, we don't have content, so use empty bytes
|
||||
file_tuples.append((filename, b"", mimetype))
|
||||
else:
|
||||
# Extract filename from path if no metadata provided
|
||||
import os
|
||||
filename = os.path.basename(file_path)
|
||||
file_tuples.append((filename, b"", "application/octet-stream"))
|
||||
|
||||
# Convert UI settings to component tweaks using exact component IDs
|
||||
if settings:
|
||||
logger.debug("Applying ingestion settings", settings=settings)
|
||||
|
|
@ -114,6 +130,7 @@ async def run_ingestion(
|
|||
|
||||
result = await langflow_file_service.run_ingestion_flow(
|
||||
file_paths=file_paths or [],
|
||||
file_tuples=file_tuples,
|
||||
jwt_token=jwt_token,
|
||||
session_id=session_id,
|
||||
tweaks=tweaks,
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ class LangflowConnectorService:
|
|||
|
||||
ingestion_result = await self.langflow_service.run_ingestion_flow(
|
||||
file_paths=[langflow_file_path],
|
||||
file_tuples=[file_tuple],
|
||||
jwt_token=jwt_token,
|
||||
tweaks=tweaks,
|
||||
owner=owner_user_id,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class LangflowFileService:
|
|||
async def run_ingestion_flow(
|
||||
self,
|
||||
file_paths: List[str],
|
||||
file_tuples: list[tuple[str, str, str]],
|
||||
jwt_token: str,
|
||||
session_id: Optional[str] = None,
|
||||
tweaks: Optional[Dict[str, Any]] = None,
|
||||
|
|
@ -67,7 +68,6 @@ class LangflowFileService:
|
|||
owner_name: Optional[str] = None,
|
||||
owner_email: Optional[str] = None,
|
||||
connector_type: Optional[str] = None,
|
||||
file_tuples: Optional[list[tuple[str, str, str]]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Trigger the ingestion flow with provided file paths.
|
||||
|
|
@ -135,14 +135,19 @@ class LangflowFileService:
|
|||
# To compute the file size in bytes, use len() on the file content (which should be bytes)
|
||||
file_size_bytes = len(file_tuples[0][1]) if file_tuples and len(file_tuples[0]) > 1 else 0
|
||||
# Avoid logging full payload to prevent leaking sensitive data (e.g., JWT)
|
||||
|
||||
# Extract file metadata if file_tuples is provided
|
||||
filename = str(file_tuples[0][0]) if file_tuples and len(file_tuples) > 0 else ""
|
||||
mimetype = str(file_tuples[0][2]) if file_tuples and len(file_tuples) > 0 and len(file_tuples[0]) > 2 else ""
|
||||
|
||||
headers={
|
||||
"X-Langflow-Global-Var-JWT": str(jwt_token),
|
||||
"X-Langflow-Global-Var-OWNER": str(owner),
|
||||
"X-Langflow-Global-Var-OWNER_NAME": str(owner_name),
|
||||
"X-Langflow-Global-Var-OWNER_EMAIL": str(owner_email),
|
||||
"X-Langflow-Global-Var-CONNECTOR_TYPE": str(connector_type),
|
||||
"X-Langflow-Global-Var-FILENAME": str(file_tuples[0][0]),
|
||||
"X-Langflow-Global-Var-MIMETYPE": str(file_tuples[0][2]),
|
||||
"X-Langflow-Global-Var-FILENAME": filename,
|
||||
"X-Langflow-Global-Var-MIMETYPE": mimetype,
|
||||
"X-Langflow-Global-Var-FILESIZE": str(file_size_bytes),
|
||||
}
|
||||
logger.info(f"[LF] Headers {headers}")
|
||||
|
|
@ -271,14 +276,14 @@ class LangflowFileService:
|
|||
try:
|
||||
ingest_result = await self.run_ingestion_flow(
|
||||
file_paths=[file_path],
|
||||
file_tuples=[file_tuple],
|
||||
jwt_token=jwt_token,
|
||||
session_id=session_id,
|
||||
tweaks=final_tweaks,
|
||||
jwt_token=jwt_token,
|
||||
owner=owner,
|
||||
owner_name=owner_name,
|
||||
owner_email=owner_email,
|
||||
connector_type=connector_type,
|
||||
file_tuples=[file_tuple],
|
||||
)
|
||||
logger.debug("[LF] Ingestion completed successfully")
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue