Refactor settings.py to enhance settings retrieval and improve flow ID handling
This commit updates the settings retrieval function to include new flow IDs for chat and ingestion, replacing the deprecated FLOW_ID. It also improves the logic for exposing edit URLs based on the availability of public URLs, contributing to a more robust and well-documented codebase.
This commit is contained in:
parent
c82c74d76c
commit
83438a7c93
1 changed files with 23 additions and 11 deletions
|
|
@ -1,6 +1,11 @@
|
|||
import os
|
||||
from starlette.responses import JSONResponse
|
||||
from config.settings import LANGFLOW_URL, FLOW_ID, LANGFLOW_PUBLIC_URL
|
||||
from config.settings import (
|
||||
LANGFLOW_URL,
|
||||
LANGFLOW_CHAT_FLOW_ID,
|
||||
LANGFLOW_INGEST_FLOW_ID,
|
||||
LANGFLOW_PUBLIC_URL,
|
||||
)
|
||||
|
||||
|
||||
async def get_settings(request, session_manager):
|
||||
"""Get application settings"""
|
||||
|
|
@ -8,18 +13,25 @@ async def get_settings(request, session_manager):
|
|||
# Return public settings that are safe to expose to frontend
|
||||
settings = {
|
||||
"langflow_url": LANGFLOW_URL,
|
||||
"flow_id": FLOW_ID,
|
||||
"flow_id": LANGFLOW_CHAT_FLOW_ID,
|
||||
"ingest_flow_id": LANGFLOW_INGEST_FLOW_ID,
|
||||
"langflow_public_url": LANGFLOW_PUBLIC_URL,
|
||||
}
|
||||
|
||||
# Only expose edit URL when a public URL is configured
|
||||
if LANGFLOW_PUBLIC_URL and FLOW_ID:
|
||||
settings["langflow_edit_url"] = f"{LANGFLOW_PUBLIC_URL.rstrip('/')}/flow/{FLOW_ID}"
|
||||
|
||||
|
||||
# Only expose edit URLs when a public URL is configured
|
||||
if LANGFLOW_PUBLIC_URL and LANGFLOW_CHAT_FLOW_ID:
|
||||
settings["langflow_edit_url"] = (
|
||||
f"{LANGFLOW_PUBLIC_URL.rstrip('/')}/flow/{LANGFLOW_CHAT_FLOW_ID}"
|
||||
)
|
||||
|
||||
if LANGFLOW_PUBLIC_URL and LANGFLOW_INGEST_FLOW_ID:
|
||||
settings["langflow_ingest_edit_url"] = (
|
||||
f"{LANGFLOW_PUBLIC_URL.rstrip('/')}/flow/{LANGFLOW_INGEST_FLOW_ID}"
|
||||
)
|
||||
|
||||
return JSONResponse(settings)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return JSONResponse(
|
||||
{"error": f"Failed to retrieve settings: {str(e)}"},
|
||||
status_code=500
|
||||
{"error": f"Failed to retrieve settings: {str(e)}"}, status_code=500
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue