40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Push canonical backend/flows/*.json into Langflow via API (no restart)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from app.flows.langflow_client import LangflowClient, LangflowError
|
|
from app.settings import settings
|
|
|
|
|
|
async def main() -> None:
|
|
base = os.environ.get("LANGFLOW_URL", "http://localhost:7860")
|
|
key = settings.langflow_api_key or os.environ.get("LANGFLOW_API_KEY", "")
|
|
print(f"Langflow: {base} key_len={len(key)}")
|
|
client = LangflowClient(base, api_key=key)
|
|
try:
|
|
flows = await client.list_flows()
|
|
print(f"existing: {len(flows)} flows")
|
|
for f in flows[:20]:
|
|
print(" -", f.get("name"), f.get("id"))
|
|
except LangflowError as exc:
|
|
print(f"list failed: {exc}")
|
|
return
|
|
flows_dir = Path(settings.flows_dir)
|
|
for path in sorted(flows_dir.glob("*.json")):
|
|
if path.name.startswith("."):
|
|
continue
|
|
doc = json.loads(path.read_text(encoding="utf-8"))
|
|
try:
|
|
result = await client.upsert_flow(doc)
|
|
print(f"pushed {path.name} id={result.get('id', 'ok')}")
|
|
except LangflowError as exc:
|
|
print(f"push {path.name} failed: {exc}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|