-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload_nodes_execute_api.py
More file actions
48 lines (42 loc) · 1.45 KB
/
Copy pathpreload_nodes_execute_api.py
File metadata and controls
48 lines (42 loc) · 1.45 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
import requests
import json
server_url = "http://127.0.0.1:8188"
# 加载节点配置
with open("preload_nodes_sample_api.json", "r") as f:
nodes_config = json.load(f)
# 按依赖顺序注册和执行节点
execution_order = ["4", "5", "6", "7", "3", "8", "9"] # 按依赖顺序排列节点ID
# 先注册所有节点
for node_id in nodes_config:
node_data = nodes_config[node_id]
# 使用正确的API格式 - 注意与服务器端定义匹配
register_data = {
"node_id": node_id,
"node_data": node_data
}
register_response = requests.post(
f"{server_url}/api/node/register",
json=register_data
)
print(f"Node {node_id} registration: {register_response.status_code}")
if register_response.status_code != 200:
print(register_response.text)
# 按顺序执行节点
for node_id in execution_order:
node_data = nodes_config[node_id]
response = requests.post(
f"{server_url}/api/node/execute/{node_id}",
json={"node_data": node_data} # 包装在node_data字段中
)
print(f"Node {node_id} executed: {response.status_code}")
try:
print(response.json())
except:
print("Could not parse JSON response")
# 如果是最后一个节点(SaveImage),获取输出
if node_id == "9":
try:
result = response.json()
print(f"Final result: {result}")
except:
print("Could not parse JSON response")