diff --git a/billbum_modified.py b/billbum_modified.py index 6a7a45b..49bfefc 100644 --- a/billbum_modified.py +++ b/billbum_modified.py @@ -1,4 +1,5 @@ import tenacity +import openai from openai import OpenAI import random import base64 @@ -211,7 +212,7 @@ class BillBum_Modified_Dalle_API_Node: FUNCTION = "get_dalle_3_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(5)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(5), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_dalle_3_image(self, prompt, model, size, quality, n, api_url, api_key,seed, style): random.seed(seed) client = OpenAI( @@ -290,7 +291,7 @@ class BillBum_Modified_LLM_API_Node: FUNCTION = "get_llm_response" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_llm_response(self, prompt, model, api_url, api_key, system_prompt, temperature, use_meta_prompt, seed): random.seed(seed) @@ -353,7 +354,7 @@ class BillBum_Modified_LLM_ForceStream_Mode: FUNCTION = "get_llm_stream_response" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_llm_stream_response(self, prompt, model, api_url, api_key, system_prompt, temperature, enable_thinking, seed): random.seed(seed) @@ -433,7 +434,7 @@ class BillBum_Modified_VisionLM_API_Node: FUNCTION = "get_vlm_response" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_vlm_response(self, prompt, model, api_url, api_key, system_prompt, image, use_jailbreak, seed): if system_prompt == "" and use_jailbreak: @@ -589,7 +590,7 @@ class BillBum_NonSysPrompt_VLM_API_Node: FUNCTION = "get_vlm_nsp_response" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_vlm_nsp_response(self, prompt, model, api_url, api_key, system_prompt, image, use_jailbreak, seed): if system_prompt == "" and use_jailbreak: @@ -797,7 +798,7 @@ class BillBum_Modified_SD3_API_Node: FUNCTION = "get_sd3_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def get_sd3_image(self, prompt, negative_prompt, model, aspect_ratio, seed, api_url, api_key, style_preset): random.seed(seed) @@ -869,7 +870,7 @@ class BillBum_Modified_Flux_API_Node_imgInput: FUNCTION = "get_fluxpro_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def get_fluxpro_image(self, prompt, model, aspect_ratio, width, height, image_strength, seed, api_url, api_key, image_prompt = None): def get_b64_url(image_prompt): with torch.no_grad(): @@ -997,7 +998,7 @@ class BillBum_Modified_Recraft_API_Node: FUNCTION = "get_recraft_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=4, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=4, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def get_recraft_image(self, prompt, size, model, seed, api_url, api_key, style_type,): random.seed(seed) @@ -1055,7 +1056,7 @@ class BillBum_Modified_Image_API_Call_Node: FUNCTION = "get_json_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def get_json_image(self, payload, api_url, api_key): url = api_url @@ -1262,7 +1263,7 @@ class BillBum_Modified_Ideogram_API_Node: FUNCTION = "get_ideogram_image" CATEGORY = "BillBum_API" - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def get_ideogram_image(self, model, prompt, negative_prompt, aspect_ratio, seed, api_url, api_key, style_type, magic_prompt_option,): random.seed(seed) diff --git a/nodes4doubao.py b/nodes4doubao.py index 16f4f9a..fd17cba 100644 --- a/nodes4doubao.py +++ b/nodes4doubao.py @@ -236,7 +236,7 @@ class seedream_api_node: image = Image.open(io.BytesIO(image_data)) return pil2tensor(image) - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=2, max=20), stop=tenacity.stop_after_attempt(3), reraise=True) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=2, max=20), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def generate_image(self, model, prompt, size, api_url, api_key, story_mode, image=None): headers = { "Content-Type": "application/json", diff --git a/nodes4hypr.py b/nodes4hypr.py index afa9a0b..17ef54c 100644 --- a/nodes4hypr.py +++ b/nodes4hypr.py @@ -83,7 +83,7 @@ class HyprLab_Image_API_Node: encoded_images.append(f"data:image/png;base64,{encoded}") return encoded_images - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3)) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def generate_image(self, prompt, seed, model, api_url, api_key, resolution, aspect_ratio, image_input=None): headers = { diff --git a/nodes4tuzi.py b/nodes4tuzi.py index 7a297dd..5ad239e 100644 --- a/nodes4tuzi.py +++ b/nodes4tuzi.py @@ -1,4 +1,5 @@ import tenacity +import openai import random from openai import OpenAI import io @@ -94,7 +95,7 @@ class BillBum_Modified_StreamResponse_LLM_API: encoded_images.append(encoded) return encoded_images - @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), reraise=True) + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=5, max=30), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((openai.APIConnectionError, openai.RateLimitError, openai.APITimeoutError, openai.InternalServerError)), reraise=True) def get_llm_stream_response( self, prompt, @@ -179,6 +180,7 @@ class Url2Image: FUNCTION = "get_url_image" CATEGORY = "BillBum_API/Utils" + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=2, max=15), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def _load_image_bytes(self, entry: str) -> bytes: if entry.startswith("data:"): _, base64_data = entry.split(",", 1) @@ -268,6 +270,7 @@ class LoadVideoFromUrlComfyIO(comfyio.ComfyNode): return ".mp4" @staticmethod + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=3, max=20), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout)), reraise=True) def _download_to_temp(url: str, suffix: str) -> str: with requests.get(url, stream=True, timeout=30) as resp: resp.raise_for_status() @@ -328,6 +331,7 @@ class LoadVideoFromUrlVHS: FUNCTION = "load_video" CATEGORY = "BillBum_API/Utils" + @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1.25, min=3, max=20), stop=tenacity.stop_after_attempt(3), retry=tenacity.retry_if_exception_type((requests.exceptions.ConnectionError, requests.exceptions.Timeout, ConnectionError)), reraise=True) def _download_video(self, url: str) -> str: if not url.startswith(("http://", "https://")): raise ValueError("仅支持 http/https URL。") diff --git a/pyproject.toml b/pyproject.toml index 3e89a3b..c4a0997 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_billbum_api_nodes" description = "New Support Seedance2.0 api Now!!! API call node for Third-party platforms both official and local. Support VLMs LLMs Dalle3 Flux-Pro(Support kontext, banana etc... now!! and new Support gpt-image-1!!). And some little tools: img to b64 url, b64 url to img, b64 url to b64 data, reg text to word and ',' only, etc." -version = "1.2.2" +version = "1.2.3" license = {file = "LICENSE"} dependencies = ["tenacity", "openai", "pillow", "requests", "numpy", "tiktoken", "urlextract"]