-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlanggraph2langflow.py
More file actions
48 lines (37 loc) · 1.34 KB
/
Copy pathlanggraph2langflow.py
File metadata and controls
48 lines (37 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
LangFlow to LangGraph Converter
-------------------------------
This script converts LangFlow JSON exports to LangGraph Python code.
"""
import sys
from pathlib import Path
# Import from the modular package
from langflow2langgraph.converter import convert_langflow_to_langgraph, LangGraphConversionError
def main():
"""Main entry point for the script"""
if len(sys.argv) < 2:
print("Usage: python langgraph2langflow.py <input_file> [output_file]")
return 1
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else None
try:
# Convert the file
print(f"Converting {input_file}...")
result = convert_langflow_to_langgraph(input_file, output_file)
# If no output file specified, print to stdout
if not output_file:
print("\nGenerated LangGraph code:")
print("=" * 40)
print(result)
print("=" * 40)
print("\nNote: No output file specified. Use a second argument to save to a file.")
else:
print(f"Successfully converted {input_file} to {output_file}")
return 0
except LangGraphConversionError as e:
print(f"Error: {str(e)}")
return 1
if __name__ == "__main__":
sys.exit(main())