bizyengine 1.2.26__py3-none-any.whl → 1.2.27__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.
@@ -1122,9 +1122,11 @@ class APIClient:
1122
1122
  print(f"\033[31m[BizyAir]\033[0m Fail to get recent cost: {str(e)}")
1123
1123
  return None, errnos.GET_RECENT_COST
1124
1124
 
1125
- def forward_model_request(self, request_data):
1125
+ def forward_model_request(self, request_data, request_api_key):
1126
1126
  try:
1127
- api_key = get_api_key()
1127
+ api_key = request_api_key
1128
+ if not BIZYAIR_SERVER_MODE:
1129
+ api_key = get_api_key()
1128
1130
  if not api_key:
1129
1131
  return None, errnos.INVALID_API_KEY
1130
1132
 
@@ -1170,9 +1172,11 @@ class APIClient:
1170
1172
  print(f"\033[31m[BizyAir]\033[0m Model API forwarding failed: {str(e)}")
1171
1173
  return None, errnos.MODEL_API_ERROR
1172
1174
 
1173
- async def forward_image_request(self, request_data):
1175
+ async def forward_image_request(self, request_data, request_api_key):
1174
1176
  try:
1175
- api_key = get_api_key()
1177
+ api_key = request_api_key
1178
+ if not BIZYAIR_SERVER_MODE:
1179
+ api_key = get_api_key()
1176
1180
  if not api_key:
1177
1181
  return None, errnos.INVALID_API_KEY
1178
1182
  headers = {
@@ -739,6 +739,126 @@ class BizyAirServer:
739
739
  err.data = {"error": valid[1], "node_errors": valid[3]}
740
740
  return ErrResponse(err)
741
741
 
742
+ @self.prompt_server.routes.post(f"/{MODEL_API}/chat")
743
+ async def chat_completions(request):
744
+ request_api_key, err = _get_request_api_key(request.headers)
745
+ if err:
746
+ return ErrResponse(err)
747
+
748
+ response = None # 确保变量在退出前定义
749
+ resp = None # 响应对象引用
750
+ req_id = f"req-{id(request)}" # 为请求生成唯一ID
751
+
752
+ try:
753
+ # 解析请求数据
754
+ request_data = await request.json()
755
+
756
+ # 转发请求到模型服务
757
+ with self.api_client.forward_model_request(
758
+ request_data, request_api_key
759
+ ) as response:
760
+ # 创建并准备流式响应
761
+ resp = aiohttp.web.StreamResponse(
762
+ status=200,
763
+ reason="OK",
764
+ headers={
765
+ "Content-Type": "text/event-stream",
766
+ "Cache-Control": "no-cache",
767
+ "Connection": "keep-alive",
768
+ "X-Accel-Buffering": "no", # 禁用Nginx缓冲
769
+ },
770
+ )
771
+ await resp.prepare(request)
772
+
773
+ # 开始流式传输
774
+ any_chunk_sent = False # 跟踪是否发送了任何数据块
775
+ try:
776
+ for bytes in response.iter_bytes(1024):
777
+ if bytes:
778
+ await resp.write(bytes)
779
+ any_chunk_sent = True
780
+ await resp.drain() # 确保数据被立即发送
781
+ except Exception as e:
782
+ print(
783
+ f"\033[31m[聊天请求-{req_id}]\033[0m 流式传输错误: {str(e)}"
784
+ )
785
+ # 如果尚未发送任何数据块,尝试发送错误信息
786
+ if not any_chunk_sent and not resp.prepared:
787
+ return ErrResponse(errnos.MODEL_API_ERROR)
788
+ elif not any_chunk_sent:
789
+ try:
790
+ error_msg = json.dumps(
791
+ {"error": f"流式传输错误: {str(e)}"}
792
+ )
793
+ await resp.write(
794
+ f"data: {error_msg}\n\n".encode("utf-8")
795
+ )
796
+ await resp.write(b"data: [DONE]\n\n")
797
+ except Exception as write_err:
798
+ print(
799
+ f"\033[31m[聊天请求-{req_id}]\033[0m 写入错误消息时出错: {str(write_err)}"
800
+ )
801
+
802
+ try:
803
+ await resp.write_eof()
804
+ except Exception as e:
805
+ print(
806
+ f"\033[31m[聊天请求-{req_id}]\033[0m 结束响应时出错: {str(e)}"
807
+ )
808
+
809
+ return resp
810
+
811
+ except openai.APIConnectionError as e:
812
+ print("The server could not be reached")
813
+ print(
814
+ e.__cause__
815
+ ) # an underlying Exception, likely raised within httpx.
816
+ except openai.RateLimitError:
817
+ print("A 429 status code was received; we should back off a bit.")
818
+ except openai.APIStatusError as e:
819
+ print("Another non-200-range status code was received")
820
+ print(e.status_code)
821
+ print(e.response)
822
+ except Exception as e:
823
+ print(
824
+ f"\033[31m[聊天请求-{req_id}]\033[0m 处理请求时发生错误: {str(e)}"
825
+ )
826
+ # 如果响应已经准备好,尝试发送错误信息
827
+ if resp and resp.prepared:
828
+ try:
829
+ error_msg = json.dumps({"error": f"服务器错误: {str(e)}"})
830
+ await resp.write(f"data: {error_msg}\n\n".encode("utf-8"))
831
+ await resp.write(b"data: [DONE]\n\n")
832
+ await resp.write_eof()
833
+ except:
834
+ pass
835
+ return resp
836
+
837
+ return ErrResponse(errnos.MODEL_API_ERROR)
838
+
839
+ @self.prompt_server.routes.post(f"/{MODEL_API}/images")
840
+ async def image_generations(request):
841
+ try:
842
+ request_api_key, err = _get_request_api_key(request.headers)
843
+ if err:
844
+ return ErrResponse(err)
845
+
846
+ # 解析请求数据
847
+ request_data = await request.json()
848
+
849
+ # 转发图像生成请求
850
+ result, err = await self.api_client.forward_image_request(
851
+ request_data, request_api_key
852
+ )
853
+ if err is not None:
854
+ return ErrResponse(err)
855
+
856
+ # 返回结果
857
+ return OKResponse(result)
858
+
859
+ except Exception:
860
+ return ErrResponse(errnos.MODEL_API_ERROR)
861
+
742
862
  # 服务器模式独占
743
863
  if BIZYAIR_SERVER_MODE:
744
864
  return
@@ -1129,114 +1249,6 @@ class BizyAirServer:
1129
1249
 
1130
1250
  return OKResponse(resp)
1131
1251
 
1132
- @self.prompt_server.routes.post(f"/{MODEL_API}/chat")
1133
- async def chat_completions(request):
1134
- response = None # 确保变量在退出前定义
1135
- resp = None # 响应对象引用
1136
- req_id = f"req-{id(request)}" # 为请求生成唯一ID
1137
-
1138
- try:
1139
- # 解析请求数据
1140
- request_data = await request.json()
1141
-
1142
- # 转发请求到模型服务
1143
- with self.api_client.forward_model_request(request_data) as response:
1144
- # 创建并准备流式响应
1145
- resp = aiohttp.web.StreamResponse(
1146
- status=200,
1147
- reason="OK",
1148
- headers={
1149
- "Content-Type": "text/event-stream",
1150
- "Cache-Control": "no-cache",
1151
- "Connection": "keep-alive",
1152
- "X-Accel-Buffering": "no", # 禁用Nginx缓冲
1153
- },
1154
- )
1155
- await resp.prepare(request)
1156
-
1157
- # 开始流式传输
1158
- any_chunk_sent = False # 跟踪是否发送了任何数据块
1159
- try:
1160
- for bytes in response.iter_bytes(1024):
1161
- if bytes:
1162
- await resp.write(bytes)
1163
- any_chunk_sent = True
1164
- await resp.drain() # 确保数据被立即发送
1165
- except Exception as e:
1166
- print(
1167
- f"\033[31m[聊天请求-{req_id}]\033[0m 流式传输错误: {str(e)}"
1168
- )
1169
- # 如果尚未发送任何数据块,尝试发送错误信息
1170
- if not any_chunk_sent and not resp.prepared:
1171
- return ErrResponse(errnos.MODEL_API_ERROR)
1172
- elif not any_chunk_sent:
1173
- try:
1174
- error_msg = json.dumps(
1175
- {"error": f"流式传输错误: {str(e)}"}
1176
- )
1177
- await resp.write(
1178
- f"data: {error_msg}\n\n".encode("utf-8")
1179
- )
1180
- await resp.write(b"data: [DONE]\n\n")
1181
- except Exception as write_err:
1182
- print(
1183
- f"\033[31m[聊天请求-{req_id}]\033[0m 写入错误消息时出错: {str(write_err)}"
1184
- )
1185
-
1186
- try:
1187
- await resp.write_eof()
1188
- except Exception as e:
1189
- print(
1190
- f"\033[31m[聊天请求-{req_id}]\033[0m 结束响应时出错: {str(e)}"
1191
- )
1192
-
1193
- return resp
1194
-
1195
- except openai.APIConnectionError as e:
1196
- print("The server could not be reached")
1197
- print(
1198
- e.__cause__
1199
- ) # an underlying Exception, likely raised within httpx.
1200
- except openai.RateLimitError:
1201
- print("A 429 status code was received; we should back off a bit.")
1202
- except openai.APIStatusError as e:
1203
- print("Another non-200-range status code was received")
1204
- print(e.status_code)
1205
- print(e.response)
1206
- except Exception as e:
1207
- print(
1208
- f"\033[31m[聊天请求-{req_id}]\033[0m 处理请求时发生错误: {str(e)}"
1209
- )
1210
- # 如果响应已经准备好,尝试发送错误信息
1211
- if resp and resp.prepared:
1212
- try:
1213
- error_msg = json.dumps({"error": f"服务器错误: {str(e)}"})
1214
- await resp.write(f"data: {error_msg}\n\n".encode("utf-8"))
1215
- await resp.write(b"data: [DONE]\n\n")
1216
- await resp.write_eof()
1217
- except:
1218
- pass
1219
- return resp
1220
-
1221
- return ErrResponse(errnos.MODEL_API_ERROR)
1222
-
1223
- @self.prompt_server.routes.post(f"/{MODEL_API}/images")
1224
- async def image_generations(request):
1225
- try:
1226
- # 解析请求数据
1227
- request_data = await request.json()
1228
-
1229
- # 转发图像生成请求
1230
- result, err = await self.api_client.forward_image_request(request_data)
1231
- if err is not None:
1232
- return ErrResponse(err)
1233
-
1234
- # 返回结果
1235
- return OKResponse(result)
1236
-
1237
- except Exception:
1238
- return ErrResponse(errnos.MODEL_API_ERROR)
1239
-
1240
1252
  async def send_json(self, event, data, sid=None):
1241
1253
  message = {"type": event, "data": data}
1242
1254
 
bizyengine/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.26
1
+ 1.2.27
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bizyengine
3
- Version: 1.2.26
3
+ Version: 1.2.27
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,13 +1,13 @@
1
1
  bizyengine/__init__.py,sha256=GP9V-JM07fz7uv_qTB43QEA2rKdrVJxi5I7LRnn_3ZQ,914
2
- bizyengine/version.txt,sha256=XmSQdL2rcd2Ni6nWmucswtJ_1MSf4wAxT_j0jRYjkdU,7
2
+ bizyengine/version.txt,sha256=hPsbIxO28ragdKYMcOjrjXZov_fwllVD_xQUQMCih60,6
3
3
  bizyengine/bizy_server/__init__.py,sha256=SP9oSblnPo4KQyh7yOGD26YCskFAcQHAZy04nQBNRIw,200
4
- bizyengine/bizy_server/api_client.py,sha256=qY1hQ11AeDf5m647qrYvn3YPBzP6Yaw8n2Z9hTk5Wtg,43624
4
+ bizyengine/bizy_server/api_client.py,sha256=t6cwob7hs993oy5WdFcjKtIzfi3S_eUhODdDVv_Hedo,43822
5
5
  bizyengine/bizy_server/errno.py,sha256=Q-U96XnZQCuPH_44Om8wnc2-Kh7qFqwLKtox27msU54,16095
6
6
  bizyengine/bizy_server/error_handler.py,sha256=MGrfO1AEqbfEgMWPL8B6Ypew_zHiQAdYGlhN9bZohrY,167
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=XWGO8gdTtIgwTO_WQNEYOumBVVN4SUYqohKmKmwFe0o,53130
10
+ bizyengine/bizy_server/server.py,sha256=9zCDdtK-0FwA6VYCBhrur99WQs2geNvA2jlfncMnSj0,53520
11
11
  bizyengine/bizy_server/stream_response.py,sha256=H2XHqlVRtQMhgdztAuG7l8-iV_Pm42u2x6WJ0gNVIW0,9654
12
12
  bizyengine/bizy_server/utils.py,sha256=CIoRrCy8Wv4D9FDdr_QtNP03AjWw8M6GSm2QcrVJl6Y,3739
13
13
  bizyengine/bizyair_extras/__init__.py,sha256=EjyLEdLpPm5I4Z25YmnoK4PYQDmsEyXtCXQt9UDGmi0,1009
@@ -77,7 +77,7 @@ bizyengine/misc/route_sam.py,sha256=-bMIR2QalfnszipGxSxvDAHGJa5gPSrjkYPb5baaRg4,
77
77
  bizyengine/misc/segment_anything.py,sha256=wNKYwlYPMszfwj23524geFZJjZaG4eye65SGaUnh77I,8941
78
78
  bizyengine/misc/supernode.py,sha256=STN9gaxfTSErH8OiHeZa47d8z-G9S0I7fXuJvHQOBFM,4532
79
79
  bizyengine/misc/utils.py,sha256=deQjBgLAkxIr-NaOMm77TcgBT3ExAp0MFm5ehUJ3CGs,6829
80
- bizyengine-1.2.26.dist-info/METADATA,sha256=MFyKRe1Yh8HQLoRl2UB3Ass0xyMfd27yUsGx0Yqphmc,675
81
- bizyengine-1.2.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
- bizyengine-1.2.26.dist-info/top_level.txt,sha256=2zapzqxX-we5cRyJkGf9bd5JinRtXp3-_uDI-xCAnc0,11
83
- bizyengine-1.2.26.dist-info/RECORD,,
80
+ bizyengine-1.2.27.dist-info/METADATA,sha256=ok50MkdSb5QqGRuIQMF7dR44VipfqVZKqm1RzZcAWaU,675
81
+ bizyengine-1.2.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
+ bizyengine-1.2.27.dist-info/top_level.txt,sha256=2zapzqxX-we5cRyJkGf9bd5JinRtXp3-_uDI-xCAnc0,11
83
+ bizyengine-1.2.27.dist-info/RECORD,,