bizyengine 1.2.78__py3-none-any.whl → 1.2.80__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.
@@ -51,6 +51,10 @@ if not BIZYAIR_DEBUG:
51
51
  def _get_request_api_key(request_headers):
52
52
  if BIZYAIR_SERVER_MODE:
53
53
  encrypted_api_key = request_headers.get("Authorization")
54
+ if not encrypted_api_key:
55
+ # 尝试从cookie中读取auth_token
56
+ cookie_str = request_headers.get("Cookie")
57
+ encrypted_api_key = _get_auth_token_from_cookie(cookie_str)
54
58
  return decrypt_apikey(encrypted_api_key)
55
59
  return None, None
56
60
 
@@ -65,6 +69,17 @@ def _get_api_key_from_cookie(cookie_str):
65
69
  return None
66
70
 
67
71
 
72
+ def _get_auth_token_from_cookie(cookie_str):
73
+ if not cookie_str:
74
+ return None
75
+ cookies = cookie_str.split(";")
76
+ for cookie in cookies:
77
+ cookie = cookie.strip()
78
+ if cookie.startswith("auth_token="):
79
+ return cookie[11:]
80
+ return None
81
+
82
+
68
83
  class BizyAirServer:
69
84
  def __init__(self):
70
85
  BizyAirServer.instance = self
@@ -1,11 +1,12 @@
1
1
  import abc
2
+ import asyncio
2
3
  import io
3
4
  import json
4
5
  import logging
5
6
  import time
6
7
  from typing import List, Tuple
7
8
 
8
- import requests
9
+ import aiohttp
9
10
  import torch
10
11
  from bizyairsdk import bytesio_to_image_tensor, common_upscale
11
12
  from comfy_api.latest._input_impl import VideoFromFile
@@ -16,7 +17,7 @@ from bizyengine.core import (
16
17
  register_node,
17
18
  )
18
19
  from bizyengine.core.common import client
19
- from bizyengine.core.common.client import send_request
20
+ from bizyengine.core.common.client import async_send_request, send_request
20
21
  from bizyengine.core.common.env_var import BIZYAIR_X_SERVER
21
22
  from bizyengine.core.nodes_base import PREFIX
22
23
 
@@ -45,24 +46,24 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
45
46
  super().__init_subclass__(**kwargs)
46
47
  register_node(cls, PREFIX)
47
48
 
48
- def api_call(self, **kwargs):
49
+ async def api_call(self, **kwargs):
49
50
  extra_data = pop_api_key_and_prompt_id(kwargs)
50
51
  headers = client.headers(api_key=extra_data["api_key"])
51
52
  prompt_id = extra_data["prompt_id"]
52
53
  headers["X-BIZYAIR-PROMPT-ID"] = prompt_id
53
54
 
54
55
  data, model = self.handle_inputs(headers, prompt_id, **kwargs)
55
- outputs = self.create_task_and_wait_for_completion(data, model, headers)
56
+ outputs = await self.create_task_and_wait_for_completion(data, model, headers)
56
57
  return self.handle_outputs(outputs)
57
58
 
58
- def create_task_and_wait_for_completion(
59
+ async def create_task_and_wait_for_completion(
59
60
  self, data, model, headers
60
61
  ) -> Tuple[List[VideoFromFile], List[torch.Tensor], List[str]]:
61
62
  # 创建任务
62
63
  create_task_url = f"{BIZYAIR_X_SERVER}/trd_api/{model}"
63
64
  json_payload = json.dumps(data).encode("utf-8")
64
65
  logging.debug(f"json_payload: {json_payload}")
65
- create_api_resp = send_request(
66
+ create_api_resp = await async_send_request(
66
67
  url=create_task_url,
67
68
  data=json_payload,
68
69
  headers=headers,
@@ -73,6 +74,9 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
73
74
 
74
75
  # 检查任务创建是否成功
75
76
  if "data" not in create_api_resp or "request_id" not in create_api_resp["data"]:
77
+ logging.error(
78
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} 任务创建失败: {create_api_resp}"
79
+ )
76
80
  raise ValueError(f"Invalid response: {create_api_resp}")
77
81
 
78
82
  # 轮询获取结果,最多等待1小时
@@ -80,32 +84,39 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
80
84
  logging.info(f"{self.NODE_DISPLAY_NAME} task created, request_id: {request_id}")
81
85
  start_time = time.time()
82
86
  status_url = f"{BIZYAIR_X_SERVER}/trd_api/{request_id}"
87
+
83
88
  while time.time() - start_time < 3600:
84
- time.sleep(10)
89
+ await asyncio.sleep(10)
90
+
85
91
  try:
86
- status_api_resp = send_request(
92
+ status_api_resp = await async_send_request(
87
93
  method="GET",
88
94
  url=status_url,
89
95
  headers=headers,
90
96
  )
91
97
  except Exception as e:
92
98
  logging.error(
93
- f"{self.NODE_DISPLAY_NAME} task {request_id} status api error: {e}"
99
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} status api error: {e}"
94
100
  )
95
101
  continue
96
102
 
97
103
  if "data" not in status_api_resp:
98
104
  logging.error(
99
- f"{self.NODE_DISPLAY_NAME} task {request_id} status api resp no data: {status_api_resp}"
105
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} status api resp no data: {status_api_resp}"
100
106
  )
101
107
  continue
102
108
  if "status" not in status_api_resp["data"]:
103
109
  logging.error(
104
- f"{self.NODE_DISPLAY_NAME} task {request_id} status api resp no status: {status_api_resp}"
110
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} status api resp no status: {status_api_resp}"
105
111
  )
106
112
  continue
107
113
  status = status_api_resp["data"]["status"]
114
+ logging.debug(f"{self.NODE_DISPLAY_NAME} task {request_id} 状态: {status}")
115
+
108
116
  if status == "failed":
117
+ logging.error(
118
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} 失败: {status_api_resp}"
119
+ )
109
120
  raise ValueError(
110
121
  f"{self.NODE_DISPLAY_NAME} task {request_id} failed: {status_api_resp}"
111
122
  )
@@ -114,6 +125,9 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
114
125
 
115
126
  # 成功,获取输出结果
116
127
  if "outputs" not in status_api_resp["data"]:
128
+ logging.error(
129
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} 无输出: {status_api_resp}"
130
+ )
117
131
  raise ValueError(
118
132
  f"{self.NODE_DISPLAY_NAME} task {request_id} no outputs: {status_api_resp}"
119
133
  )
@@ -126,24 +140,31 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
126
140
  texts = []
127
141
  outputs = status_api_resp["data"]["outputs"]
128
142
  try:
129
- if "videos" in outputs:
130
- for video_url in outputs["videos"]:
131
- video_resp = requests.get(video_url, stream=True, timeout=3600)
132
- video_resp.raise_for_status() # 2xx 会抛异常
133
- videos.append(VideoFromFile(io.BytesIO(video_resp.content)))
134
- if "images" in outputs:
135
- for image_url in outputs["images"]:
136
- image_resp = requests.get(image_url, stream=True, timeout=3600)
137
- image_resp.raise_for_status() # 非 2xx 会抛异常
138
- images.append(
139
- bytesio_to_image_tensor(io.BytesIO(image_resp.content))
140
- )
143
+ async with aiohttp.ClientSession(
144
+ timeout=aiohttp.ClientTimeout(total=3600)
145
+ ) as session:
146
+ if "videos" in outputs:
147
+ for idx, video_url in enumerate(outputs["videos"]):
148
+ async with session.get(video_url) as video_resp:
149
+ video_resp.raise_for_status()
150
+ video_content = await video_resp.read()
151
+ videos.append(VideoFromFile(io.BytesIO(video_content)))
152
+
153
+ if "images" in outputs:
154
+ for idx, image_url in enumerate(outputs["images"]):
155
+ async with session.get(image_url) as image_resp:
156
+ image_resp.raise_for_status()
157
+ image_content = await image_resp.read()
158
+ images.append(
159
+ bytesio_to_image_tensor(io.BytesIO(image_content))
160
+ )
161
+
141
162
  if "texts" in outputs:
142
163
  for text in outputs["texts"]:
143
164
  texts.append(text)
144
165
  except Exception as e:
145
166
  logging.error(
146
- f"{self.NODE_DISPLAY_NAME} task {request_id} handle outputs error: {e}"
167
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} handle outputs error: {e}"
147
168
  )
148
169
  raise ValueError(
149
170
  f"{self.NODE_DISPLAY_NAME} task {request_id} handle outputs error: {e}, please download the outputs manually, outputs: {outputs}"
@@ -151,6 +172,9 @@ class BizyAirTrdApiBaseNode(BizyAirMiscBaseNode, TrdBase):
151
172
 
152
173
  return (videos, images, texts)
153
174
 
175
+ logging.error(
176
+ f"[BizyAir-Async] {self.NODE_DISPLAY_NAME} task {request_id} 超时"
177
+ )
154
178
  raise ValueError(
155
179
  f"{self.NODE_DISPLAY_NAME} task timed out, request ID: {request_id}"
156
180
  )
@@ -1,4 +1,5 @@
1
1
  import importlib
2
+ import inspect
2
3
  import logging
3
4
  import warnings
4
5
  from functools import wraps
@@ -117,13 +118,28 @@ def register_node(cls, prefix):
117
118
 
118
119
 
119
120
  def ensure_unique_id(org_func, original_has_unique_id=False):
120
- @wraps(org_func)
121
- def new_func(self, **kwargs):
122
- if original_has_unique_id:
123
- self._assigned_id = kwargs.get("unique_id", "UNIQUE_ID")
124
- elif "unique_id" in kwargs:
125
- self._assigned_id = kwargs.pop("unique_id")
126
- return org_func(self, **kwargs)
121
+ # 检测原函数是否是异步函数
122
+ is_async = inspect.iscoroutinefunction(org_func)
123
+
124
+ if is_async:
125
+ # 异步函数包装
126
+ @wraps(org_func)
127
+ async def new_func(self, **kwargs):
128
+ if original_has_unique_id:
129
+ self._assigned_id = kwargs.get("unique_id", "UNIQUE_ID")
130
+ elif "unique_id" in kwargs:
131
+ self._assigned_id = kwargs.pop("unique_id")
132
+ return await org_func(self, **kwargs)
133
+
134
+ else:
135
+ # 同步函数包装(保持原有逻辑)
136
+ @wraps(org_func)
137
+ def new_func(self, **kwargs):
138
+ if original_has_unique_id:
139
+ self._assigned_id = kwargs.get("unique_id", "UNIQUE_ID")
140
+ elif "unique_id" in kwargs:
141
+ self._assigned_id = kwargs.pop("unique_id")
142
+ return org_func(self, **kwargs)
127
143
 
128
144
  return new_func
129
145
 
bizyengine/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.78
1
+ 1.2.80
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bizyengine
3
- Version: 1.2.78
3
+ Version: 1.2.80
4
4
  Summary: [a/BizyAir](https://github.com/siliconflow/BizyAir) Comfy Nodes that can run in any environment.
5
5
  Author-email: SiliconFlow <yaochi@siliconflow.cn>
6
6
  Project-URL: Repository, https://github.com/siliconflow/BizyAir
@@ -1,5 +1,5 @@
1
1
  bizyengine/__init__.py,sha256=GP9V-JM07fz7uv_qTB43QEA2rKdrVJxi5I7LRnn_3ZQ,914
2
- bizyengine/version.txt,sha256=NX2wLXhZUvOyCjFSI-YuxHfGMoPfQKB09K-V0V_vrUo,6
2
+ bizyengine/version.txt,sha256=jPMuwo0YkWz0z6ipvf5yo6r6zf129yvctPDotxDmQ6g,6
3
3
  bizyengine/bizy_server/__init__.py,sha256=SP9oSblnPo4KQyh7yOGD26YCskFAcQHAZy04nQBNRIw,200
4
4
  bizyengine/bizy_server/api_client.py,sha256=vNBUkFNMjPI_F_wAGiN-ydCZO8oLdgyWBlMY1DQbHOk,43685
5
5
  bizyengine/bizy_server/errno.py,sha256=8dzmtlqq0wBJguHAXKEDb_uUYUQ7qlZQK6FxOpMxqLg,17328
@@ -7,7 +7,7 @@ bizyengine/bizy_server/error_handler.py,sha256=MGrfO1AEqbfEgMWPL8B6Ypew_zHiQAdYG
7
7
  bizyengine/bizy_server/execution.py,sha256=ayaEf6eGJKQsVZV-1_UlGlvwwmlH7FEek31Uq-MbUjA,1644
8
8
  bizyengine/bizy_server/profile.py,sha256=f4juAzJ73gCm0AhagYpt9WnG8HEI6xze_U96-omBLqU,3044
9
9
  bizyengine/bizy_server/resp.py,sha256=iOFT5Ud7VJBP2uqkojJIgc3y2ifMjjEXoj0ewneL9lc,710
10
- bizyengine/bizy_server/server.py,sha256=cOoOEm7PtPUL38cnrxlG8VN83XEdyiwdNqbU-p4EUO4,58640
10
+ bizyengine/bizy_server/server.py,sha256=5wreS4aMPLec8VCBpEk3XEHl7i_cyW3r8CZtZMmb3zQ,59127
11
11
  bizyengine/bizy_server/stream_response.py,sha256=H2XHqlVRtQMhgdztAuG7l8-iV_Pm42u2x6WJ0gNVIW0,9654
12
12
  bizyengine/bizy_server/utils.py,sha256=t3y3ZTDzFa8K4wXlzgLVaFNCizgylsKsd9K3rLL4sGw,3986
13
13
  bizyengine/bizyair_extras/__init__.py,sha256=9iPmEyR7F1IXbUaBNS90ivW9ul18GcuWFxRfFv2ieAw,1011
@@ -56,7 +56,7 @@ bizyengine/bizyair_extras/third_party_api/nodes_sora.py,sha256=_-O37uRi5QHqJZqlJ
56
56
  bizyengine/bizyair_extras/third_party_api/nodes_veo3.py,sha256=LzZl-9iLMe5IzEAXYUVkb8RUPLAfZloTPxRgGcY7Hsg,6703
57
57
  bizyengine/bizyair_extras/third_party_api/nodes_vidu.py,sha256=-Eo2su0-t9qNPa5J4Qt3fx8xM9NjFHmgl19gMcTU7nM,10012
58
58
  bizyengine/bizyair_extras/third_party_api/nodes_wan_api.py,sha256=GNc616NNsXcZYtojO2XTHwU3AFiprX6tFJ7qu3s2jgc,14508
59
- bizyengine/bizyair_extras/third_party_api/trd_nodes_base.py,sha256=xu1q3cMprsfhjQPTQvzS2HqkrteWAgBx-nzqqGsy4gA,7945
59
+ bizyengine/bizyair_extras/third_party_api/trd_nodes_base.py,sha256=TeT6orrXv-G8sHzR9q8HqC4hPEgsbtUOJYJpX6-aM1g,9061
60
60
  bizyengine/bizyair_extras/utils/aliyun_oss.py,sha256=H6wGZq1DqP7BHJ_frBJVvUVttgXprJprOnxytePIuos,3050
61
61
  bizyengine/bizyair_extras/utils/audio.py,sha256=cCmX080jtxsHFa7mCgn13R6cyfqE-1Gq37ZnRJdZNU8,3183
62
62
  bizyengine/bizybot/__init__.py,sha256=NINN_7QECKQwtAwKPBTrrSiAK6KbxaZCkIvJ-e1J1xk,262
@@ -73,7 +73,7 @@ bizyengine/bizybot/mcp/routing.py,sha256=COgeao02y-oIiHpcXEZGl2cccgcR1u343BEcJ95
73
73
  bizyengine/core/__init__.py,sha256=EygpO-kvl5-4rk44rP8_s0GBDd_TF7FMvrl2exBSWWM,378
74
74
  bizyengine/core/data_types.py,sha256=2f7QqqZvhKmXw3kZV1AvXuPTda34b4wXQE9tyO8nUSM,1595
75
75
  bizyengine/core/image_utils.py,sha256=vJt42FcEDD8-fQumuogZM1XXwgYseSQ79_9Qzu9YTQk,409
76
- bizyengine/core/nodes_base.py,sha256=5cmBMdhGe9CMQrd1doZTrqE-7Z8XXrsTFEuh9N68bvY,9098
76
+ bizyengine/core/nodes_base.py,sha256=tq6TZpko3SxdnCasMoRxoI1qSFmMPTxaONNgx7bOo48,9679
77
77
  bizyengine/core/nodes_io.py,sha256=VhwRwYkGp0g3Mh0hx1OSwNZbV06NEV13w2aODSiAm5M,2832
78
78
  bizyengine/core/commands/__init__.py,sha256=82yRdMT23RTiZPkFW_G3fVa-fj3-TUAXnj6cnGA3xRA,22
79
79
  bizyengine/core/commands/base.py,sha256=TYH9lhr033B2roBLPkWkxcvoz_fW3cdzx_bvP_FI7dg,635
@@ -104,7 +104,7 @@ bizyengine/misc/route_sam.py,sha256=-bMIR2QalfnszipGxSxvDAHGJa5gPSrjkYPb5baaRg4,
104
104
  bizyengine/misc/segment_anything.py,sha256=wNKYwlYPMszfwj23524geFZJjZaG4eye65SGaUnh77I,8941
105
105
  bizyengine/misc/supernode.py,sha256=STN9gaxfTSErH8OiHeZa47d8z-G9S0I7fXuJvHQOBFM,4532
106
106
  bizyengine/misc/utils.py,sha256=GMRWKhOP-MCueVyCO-doflb7dH5dM32DyLcSPEVOXWA,13333
107
- bizyengine-1.2.78.dist-info/METADATA,sha256=ojYvqvOYFk5hNUltqCws4o4BE_PPhuJuMKTdUlGpE-A,735
108
- bizyengine-1.2.78.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
109
- bizyengine-1.2.78.dist-info/top_level.txt,sha256=2zapzqxX-we5cRyJkGf9bd5JinRtXp3-_uDI-xCAnc0,11
110
- bizyengine-1.2.78.dist-info/RECORD,,
107
+ bizyengine-1.2.80.dist-info/METADATA,sha256=1TBmpEReFNxvv5XWdlyW-P3cUqULI2XXGygxnt3tifU,735
108
+ bizyengine-1.2.80.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
109
+ bizyengine-1.2.80.dist-info/top_level.txt,sha256=2zapzqxX-we5cRyJkGf9bd5JinRtXp3-_uDI-xCAnc0,11
110
+ bizyengine-1.2.80.dist-info/RECORD,,