-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun_converter.py
More file actions
63 lines (48 loc) · 1.68 KB
/
run_converter.py
File metadata and controls
63 lines (48 loc) · 1.68 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Run Converter Script
-------------------
A simple script to demonstrate the conversion of a LangFlow JSON file to LangGraph Python code.
"""
import os
import sys
from rich.console import Console
from rich.syntax import Syntax
from langflow2langgraph.converter import convert_langflow_to_langgraph
def main():
"""
Main function to run the converter on a sample flow.
"""
console = Console()
# Path to the sample flow
sample_path = os.path.join("examples", "sample_flow.json")
# Check if the sample file exists
if not os.path.isfile(sample_path):
console.print(f"[bold red]Error:[/] Sample file '{sample_path}' not found")
return 1
# Convert the sample flow
console.print(f"Converting sample flow: [bold cyan]{sample_path}[/]")
try:
# Generate the code
generated_code = convert_langflow_to_langgraph(sample_path)
# Print the generated code with syntax highlighting
syntax = Syntax(
generated_code,
"python",
theme="monokai",
line_numbers=True,
word_wrap=True
)
console.print(syntax)
# Optionally save the generated code
output_path = "generated_graph.py"
with open(output_path, "w", encoding="utf-8") as f:
f.write(generated_code)
console.print(f"[bold green]Success![/] Generated code saved to [bold cyan]{output_path}[/]")
return 0
except Exception as e:
console.print(f"[bold red]Error:[/] {str(e)}")
return 1
if __name__ == "__main__":
sys.exit(main())