From 643539b548d4edf63e256a2ae3e3569ce36b997f Mon Sep 17 00:00:00 2001 From: Mike Fortman Date: Tue, 9 Sep 2025 11:12:48 -0500 Subject: [PATCH] support for ingest --- frontend/src/app/settings/page.tsx | 48 +++++++++++++++++++----------- src/api/flows.py | 6 ++-- src/services/flows_service.py | 11 ++++--- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/settings/page.tsx b/frontend/src/app/settings/page.tsx index 52d1ca01..e7250394 100644 --- a/frontend/src/app/settings/page.tsx +++ b/frontend/src/app/settings/page.tsx @@ -83,10 +83,14 @@ function KnowledgeSourcesPage() { // Settings state // Note: backend internal Langflow URL is not needed on the frontend - const [flowId, setFlowId] = useState( + const [chatFlowId, setChatFlowId] = useState( "1098eea1-6649-4e1d-aed1-b77249fb8dd0", ); + const [ingestFlowId, setIngestFlowId] = useState( + "5488df7c-b93f-4f87-a446-b67028bc0813", + ); const [langflowEditUrl, setLangflowEditUrl] = useState(""); + const [langflowIngestEditUrl, setLangflowIngestEditUrl] = useState(""); const [publicLangflowUrl, setPublicLangflowUrl] = useState(""); @@ -97,11 +101,17 @@ function KnowledgeSourcesPage() { if (response.ok) { const settings = await response.json(); if (settings.flow_id) { - setFlowId(settings.flow_id); + setChatFlowId(settings.flow_id); + } + if (settings.ingest_flow_id) { + setIngestFlowId(settings.ingest_flow_id); } if (settings.langflow_edit_url) { setLangflowEditUrl(settings.langflow_edit_url); } + if (settings.langflow_ingest_edit_url) { + setLangflowIngestEditUrl(settings.langflow_ingest_edit_url); + } if (settings.langflow_public_url) { setPublicLangflowUrl(settings.langflow_public_url); } @@ -383,7 +393,11 @@ function KnowledgeSourcesPage() { } }, [tasks, prevTasks]); - const handleEditInLangflow = (targetFlowId: string, closeDialog: () => void) => { + const handleEditInLangflow = (flowType: "chat" | "ingest", closeDialog: () => void) => { + // Select the appropriate flow ID and edit URL based on flow type + const targetFlowId = flowType === "ingest" ? ingestFlowId : chatFlowId; + const editUrl = flowType === "ingest" ? langflowIngestEditUrl : langflowEditUrl; + const derivedFromWindow = typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:7860` @@ -394,37 +408,37 @@ function KnowledgeSourcesPage() { "http://localhost:7860" ).replace(/\/$/, ""); const computed = targetFlowId ? `${base}/flow/${targetFlowId}` : base; - const url = langflowEditUrl || computed; + + const url = editUrl || computed; + window.open(url, "_blank"); closeDialog(); // Close immediately after opening Langflow }; - const handleRestoreFlow = (closeDialog: () => void) => { + const handleRestoreRetrievalFlow = (closeDialog: () => void) => { fetch(`/api/reset-flow/retrieval`, { method: "POST", }) .then((response) => response.json()) - .then((data) => { - console.log(data); + .then(() => { closeDialog(); // Close after successful completion }) .catch((error) => { - console.error("Error restoring flow:", error); + console.error("Error restoring retrieval flow:", error); closeDialog(); // Close even on error (could show error toast instead) }); }; - const handleRestoreAgentFlow = (closeDialog: () => void) => { - fetch(`/api/reset-flow/agent`, { + const handleRestoreIngestFlow = (closeDialog: () => void) => { + fetch(`/api/reset-flow/ingest`, { method: "POST", }) .then((response) => response.json()) - .then((data) => { - console.log(data); + .then(() => { closeDialog(); // Close after successful completion }) .catch((error) => { - console.error("Error restoring agent flow:", error); + console.error("Error restoring ingest flow:", error); closeDialog(); // Close even on error (could show error toast instead) }); }; @@ -448,7 +462,7 @@ function KnowledgeSourcesPage() { description="This restores defaults and discards all custom settings and overrides. This can't be undone." confirmText="Restore" variant="destructive" - onConfirm={handleRestoreFlow} + onConfirm={handleRestoreIngestFlow} /> handleEditInLangflow(flowId, closeDialog)} + onConfirm={(closeDialog) => handleEditInLangflow("ingest", closeDialog)} /> @@ -544,7 +558,7 @@ function KnowledgeSourcesPage() { description="This restores defaults and discards all custom settings and overrides. This can't be undone." confirmText="Restore" variant="destructive" - onConfirm={handleRestoreAgentFlow} + onConfirm={handleRestoreRetrievalFlow} /> handleEditInLangflow(flowId, closeDialog)} + onConfirm={(closeDialog) => handleEditInLangflow("chat", closeDialog)} /> diff --git a/src/api/flows.py b/src/api/flows.py index 8343dbe2..8b2be397 100644 --- a/src/api/flows.py +++ b/src/api/flows.py @@ -11,16 +11,16 @@ async def reset_flow_endpoint( request: Request, chat_service, ): - """Reset a Langflow flow by type (nudges or retrieval)""" + """Reset a Langflow flow by type (nudges, retrieval, or ingest)""" # Get flow type from path parameter flow_type = request.path_params.get("flow_type") - if flow_type not in ["nudges", "retrieval"]: + if flow_type not in ["nudges", "retrieval", "ingest"]: return JSONResponse( { "success": False, - "error": "Invalid flow type. Must be 'nudges' or 'retrieval'" + "error": "Invalid flow type. Must be 'nudges', 'retrieval', or 'ingest'" }, status_code=400 ) diff --git a/src/services/flows_service.py b/src/services/flows_service.py index df53a3ec..a73f3027 100644 --- a/src/services/flows_service.py +++ b/src/services/flows_service.py @@ -1,4 +1,4 @@ -from config.settings import NUDGES_FLOW_ID, LANGFLOW_URL, FLOW_ID +from config.settings import NUDGES_FLOW_ID, LANGFLOW_URL, LANGFLOW_CHAT_FLOW_ID, LANGFLOW_INGEST_FLOW_ID import json import os import aiohttp @@ -13,7 +13,7 @@ class FlowsService: """Reset a Langflow flow by uploading the corresponding JSON file Args: - flow_type: Either 'nudges' or 'retrieval' + flow_type: Either 'nudges', 'retrieval', or 'ingest' Returns: dict: Success/error response @@ -27,9 +27,12 @@ class FlowsService: flow_id = NUDGES_FLOW_ID elif flow_type == "retrieval": flow_file = "flows/openrag_agent.json" - flow_id = FLOW_ID + flow_id = LANGFLOW_CHAT_FLOW_ID + elif flow_type == "ingest": + flow_file = "flows/ingestion_flow.json" + flow_id = LANGFLOW_INGEST_FLOW_ID else: - raise ValueError("flow_type must be either 'nudges' or 'retrieval'") + raise ValueError("flow_type must be either 'nudges', 'retrieval', or 'ingest'") # Load flow JSON file try: