-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_api_test.py
More file actions
63 lines (50 loc) · 2.11 KB
/
Copy pathdemo_api_test.py
File metadata and controls
63 lines (50 loc) · 2.11 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
import asyncio
import json
import logging
import uuid
import sys
from pathlib import Path
# Add project root to sys.path so we can import backend
sys.path.append(str(Path(__file__).parent.parent))
import backend.graph.graph as graph_module
from backend.job_manager import create_job
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
log = logging.getLogger("demo_api_test")
async def run_demo():
log.info("Starting Demo API Test...")
# Initialize the graph
await graph_module.init_graph()
target_url = sys.argv[1] if len(sys.argv) > 1 else "https://jsonplaceholder.typicode.com"
job_id, initial_state = create_job(
target_url=target_url,
language="python",
page_content="",
page_links=[]
)
log.info(f"Created Job: {job_id}")
log.info("Running graph. This will hit the real API and LangGraph...")
try:
config = {"configurable": {"thread_id": job_id}}
# We use astream to stream the state updates node by node
async for output in graph_module.compiled_graph.astream(initial_state, config):
for node, state_update in output.items():
log.info(f"--- Node '{node}' completed ---")
if "messages" in state_update and state_update["messages"]:
last_msg = state_update["messages"][-1]
log.info(f"Message from {node}: {last_msg.content}")
# Final state
final_state = await graph_module.compiled_graph.aget_state(config)
log.info("=== Final SDK Files ===")
files = final_state.values.get("sdk_files", {})
if files:
for file_path, content in files.items():
log.info(f"File: {file_path} ({len(content)} chars)")
else:
log.warning("No SDK files generated!")
except Exception as e:
log.error(f"Error during graph execution: {e}", exc_info=True)
finally:
await graph_module.teardown_graph()
log.info("Teardown complete.")
if __name__ == "__main__":
asyncio.run(run_demo())