File size: 1,262 Bytes
c209999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import json
from src.graph.workflow import build_sandbox_graph
from src.graph.state import SandboxState
from src.config import MAX_RETRIES


def run_sandbox(user_prompt: str) -> dict:
    graph = build_sandbox_graph(max_retries=MAX_RETRIES)

    initial: SandboxState = {
        "user_prompt": user_prompt,
        "script": None,
        "requirements": [],
        "explanation": None,
        "sandbox_result": None,
        "error_analysis": None,
        "correction_strategy": None,
        "retry_count": 0,
        "max_retries": MAX_RETRIES,
        "trace": [],
        "final_output": None,
        "final_error": None,
        "files": {},
    }

    result = graph.invoke(initial)

    return {
        "success": result.get("final_error") is None,
        "output": result.get("final_output"),
        "error": result.get("final_error"),
        "retries_used": result.get("retry_count", 0),
        "trace": result.get("trace", []),
        "files": result.get("files", {}),
    }


def main():
    if len(sys.argv) < 2:
        print("Usage: python -m src.main '<prompt>'")
        sys.exit(1)

    prompt = sys.argv[1]
    result = run_sandbox(prompt)

    print(json.dumps(result, indent=2))


if __name__ == "__main__":
    main()