bizydraft 0.1.26__py3-none-any.whl → 0.1.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bizydraft might be problematic. Click here for more details.
- bizydraft/server.py +20 -4
- bizydraft/workflow_io.py +101 -0
- {bizydraft-0.1.26.dist-info → bizydraft-0.1.28.dist-info}/METADATA +1 -1
- {bizydraft-0.1.26.dist-info → bizydraft-0.1.28.dist-info}/RECORD +6 -5
- {bizydraft-0.1.26.dist-info → bizydraft-0.1.28.dist-info}/WHEEL +0 -0
- {bizydraft-0.1.26.dist-info → bizydraft-0.1.28.dist-info}/top_level.txt +0 -0
bizydraft/server.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from typing import Union
|
|
2
3
|
|
|
3
4
|
from loguru import logger
|
|
5
|
+
from .workflow_io import parse_workflow_io
|
|
4
6
|
|
|
5
7
|
try:
|
|
6
8
|
from server import PromptServer
|
|
@@ -10,8 +12,7 @@ except ImportError:
|
|
|
10
12
|
)
|
|
11
13
|
exit(1)
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
from .resp import OKResponse, ErrResponse
|
|
15
|
+
from .resp import OKResponse, ErrResponse, JsonResponse
|
|
15
16
|
|
|
16
17
|
_API_PREFIX = "bizyair"
|
|
17
18
|
_SERVER_MODE_HC_FLAG = True
|
|
@@ -32,7 +33,7 @@ class BizyDraftServer:
|
|
|
32
33
|
|
|
33
34
|
def setup_routes(self):
|
|
34
35
|
@self.prompt_server.routes.get(f"/{_API_PREFIX}/are_you_alive")
|
|
35
|
-
async def are_you_alive(request):
|
|
36
|
+
async def are_you_alive(request) -> Union[OKResponse, ErrResponse]:
|
|
36
37
|
if _SERVER_MODE_HC_FLAG:
|
|
37
38
|
return OKResponse()
|
|
38
39
|
return ErrResponse(500)
|
|
@@ -40,7 +41,22 @@ class BizyDraftServer:
|
|
|
40
41
|
@self.prompt_server.routes.post(
|
|
41
42
|
f"/{_API_PREFIX}/are_you_alive_{BIZYAIR_MAGIC_STRING}"
|
|
42
43
|
)
|
|
43
|
-
async def toggle_are_you_alive(request):
|
|
44
|
+
async def toggle_are_you_alive(request) -> OKResponse:
|
|
44
45
|
global _SERVER_MODE_HC_FLAG
|
|
45
46
|
_SERVER_MODE_HC_FLAG = not _SERVER_MODE_HC_FLAG
|
|
46
47
|
return OKResponse()
|
|
48
|
+
|
|
49
|
+
@self.prompt_server.routes.post(f"/{_API_PREFIX}/workflow_io")
|
|
50
|
+
async def workflow_io(request) -> Union[JsonResponse, ErrResponse]:
|
|
51
|
+
try:
|
|
52
|
+
data = await request.json()
|
|
53
|
+
except Exception as e:
|
|
54
|
+
logger.error(f"解析 request.json() 失败: {e}")
|
|
55
|
+
return ErrResponse(400)
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
response = parse_workflow_io(data)
|
|
59
|
+
return JsonResponse(200, response)
|
|
60
|
+
except Exception as e:
|
|
61
|
+
logger.error(f"parse_workflow_io 处理失败: {e}")
|
|
62
|
+
return ErrResponse(500)
|
bizydraft/workflow_io.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Set
|
|
2
|
+
|
|
3
|
+
BASIC_TYPES = (int, float, str, bool)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def is_basic_type(val: Any) -> bool:
|
|
7
|
+
return isinstance(val, BASIC_TYPES)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_input_params(prompt: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
11
|
+
"""
|
|
12
|
+
遍历所有节点inputs,保留基础类型参数。
|
|
13
|
+
返回格式:[{node_id, class_type, param_name, param_value}]
|
|
14
|
+
"""
|
|
15
|
+
input_params = []
|
|
16
|
+
for node_id, node in prompt.items():
|
|
17
|
+
class_type = node.get("class_type")
|
|
18
|
+
for k, v in node.get("inputs", {}).items():
|
|
19
|
+
if is_basic_type(v):
|
|
20
|
+
input_params.append(
|
|
21
|
+
{
|
|
22
|
+
"node_id": node_id,
|
|
23
|
+
"class_type": class_type,
|
|
24
|
+
"param_name": k,
|
|
25
|
+
"param_value": v,
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
return input_params
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_leaf_nodes_from_prompt(prompt: Dict[str, Any]) -> Set[str]:
|
|
32
|
+
"""
|
|
33
|
+
仅通过prompt参数推断叶子节点(即没有被其他节点inputs引用的节点)。
|
|
34
|
+
返回节点id集合(字符串)。
|
|
35
|
+
"""
|
|
36
|
+
referenced = set()
|
|
37
|
+
for node_id, node in prompt.items():
|
|
38
|
+
for v in node.get("inputs", {}).values():
|
|
39
|
+
# 如果是引用(如["4", 1]),则v为list且第一个元素为节点id
|
|
40
|
+
if isinstance(v, list) and len(v) > 0 and isinstance(v[0], str):
|
|
41
|
+
referenced.add(v[0])
|
|
42
|
+
all_nodes = set(prompt.keys())
|
|
43
|
+
leaf_nodes = all_nodes - referenced
|
|
44
|
+
return leaf_nodes
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def summarize_params(
|
|
48
|
+
input_params: List[Dict[str, Any]], exclude_node_ids: Set[str]
|
|
49
|
+
) -> List[Dict[str, Any]]:
|
|
50
|
+
"""
|
|
51
|
+
按节点类型和参数名整理参数信息,便于输出。
|
|
52
|
+
exclude_node_ids: 需要从inputs中排除的节点id集合
|
|
53
|
+
"""
|
|
54
|
+
summary = {}
|
|
55
|
+
for param in input_params:
|
|
56
|
+
node_id = param["node_id"]
|
|
57
|
+
if node_id in exclude_node_ids:
|
|
58
|
+
continue
|
|
59
|
+
key = (param["class_type"], node_id)
|
|
60
|
+
if key not in summary:
|
|
61
|
+
summary[key] = {
|
|
62
|
+
"name": param["class_type"],
|
|
63
|
+
"displayName": param["class_type"],
|
|
64
|
+
"nodeId": node_id,
|
|
65
|
+
"params": [],
|
|
66
|
+
}
|
|
67
|
+
summary[key]["params"].append(
|
|
68
|
+
{
|
|
69
|
+
"name": param["param_name"],
|
|
70
|
+
"displayName": param["param_name"],
|
|
71
|
+
"type": type(param["param_value"]).__name__.upper(),
|
|
72
|
+
"defaultValue": param["param_value"],
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
return list(summary.values())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def parse_workflow_io(request_data) -> Dict[str, Any]:
|
|
79
|
+
prompt = request_data.get("prompt", {})
|
|
80
|
+
|
|
81
|
+
# 1. 输出参数(推断叶子节点)
|
|
82
|
+
leaf_nodes = get_leaf_nodes_from_prompt(prompt)
|
|
83
|
+
output_nodes = []
|
|
84
|
+
for node_id in leaf_nodes:
|
|
85
|
+
node = prompt[node_id]
|
|
86
|
+
class_type = node.get("class_type")
|
|
87
|
+
output_nodes.append(
|
|
88
|
+
{
|
|
89
|
+
"nodeId": node_id,
|
|
90
|
+
"name": class_type,
|
|
91
|
+
"displayName": class_type,
|
|
92
|
+
"params": [],
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# 2. 输入参数(排除已作为输出的节点)
|
|
97
|
+
input_params = get_input_params(prompt)
|
|
98
|
+
input_summary = summarize_params(input_params, exclude_node_ids=leaf_nodes)
|
|
99
|
+
|
|
100
|
+
# 3. 构造response_body.json格式
|
|
101
|
+
return {"data": {"inputs": input_summary, "outputs": output_nodes}}
|
|
@@ -4,7 +4,8 @@ bizydraft/hijack_routes.py,sha256=MlietlmTU-Lj7evZo5yZE-ghQJZ9_1vdpyHXAXYfoFw,74
|
|
|
4
4
|
bizydraft/postload.py,sha256=YfiFjJ7MLN6WNar19lLdAL_3IPr5GyI3G4rbZIiAgXU,562
|
|
5
5
|
bizydraft/prestartup_patch.py,sha256=Rh_D-rEUmPaojSrl8CEBMAhSgwtLSm6gH2Mzmk5NCuQ,316
|
|
6
6
|
bizydraft/resp.py,sha256=8INvKOe5Dgai3peKfqKjrhUoYeuXWXn358w30-_cY-A,369
|
|
7
|
-
bizydraft/server.py,sha256=
|
|
7
|
+
bizydraft/server.py,sha256=0Um4lA_UZN-SRD_nW0lo0pekI6hPNuDgQjKB21ZsXcw,2102
|
|
8
|
+
bizydraft/workflow_io.py,sha256=lqLWhqNs5uJZ0IlTGyoEfBk6WjsWm0Btl6bQY-nldLo,3364
|
|
8
9
|
bizydraft/static/js/handleStyle.js,sha256=P2DNMiKHr--ekn3CGNOAHU46OJCCsifejxw97kLmb7Q,1676
|
|
9
10
|
bizydraft/static/js/hookLoadImage.js,sha256=GklOwfIkXhSfCFrHBz4pPqaSnBiKjegbpDknrzvXYOc,5767
|
|
10
11
|
bizydraft/static/js/main.js,sha256=cZ-7wR9T8aNLzIrTjc-g9xVZf7z6TXWl1zhP_wXSSVo,150
|
|
@@ -12,7 +13,7 @@ bizydraft/static/js/postEvent.js,sha256=lXo35DUiBmzGFMtOL2ULcjbCscNb5eAZ98_eX7en
|
|
|
12
13
|
bizydraft/static/js/socket.js,sha256=vewGQLgdJSrjvqptEDxLirZRXZUjWTJDmDdjs4mbf4k,2436
|
|
13
14
|
bizydraft/static/js/tool.js,sha256=Ejyb5GiFhuoCp5_dBvu2suagbxGHCkR2Lg_4rMKN2ls,756
|
|
14
15
|
bizydraft/static/js/uploadFile.js,sha256=5OjLLaCHZkobLltNs27K5GgZBFHZJowBwS-oakLoNW4,4985
|
|
15
|
-
bizydraft-0.1.
|
|
16
|
-
bizydraft-0.1.
|
|
17
|
-
bizydraft-0.1.
|
|
18
|
-
bizydraft-0.1.
|
|
16
|
+
bizydraft-0.1.28.dist-info/METADATA,sha256=gj7ghFoGT71u0GqpFG-lMtXaRGE7spfbvug-GuLW2yY,73
|
|
17
|
+
bizydraft-0.1.28.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
bizydraft-0.1.28.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
|
|
19
|
+
bizydraft-0.1.28.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|