Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98b7a853cf |
+65
-34
@@ -1,14 +1,54 @@
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
|
||||
from .wavespeed_api.client import WaveSpeedClient
|
||||
|
||||
PACK_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
CUSTOM_NODES_DIR = os.path.dirname(PACK_DIR)
|
||||
|
||||
|
||||
def _from_ini(path):
|
||||
if not os.path.isfile(path):
|
||||
return ""
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path)
|
||||
return config.get("API", "api_key", fallback="").strip()
|
||||
|
||||
|
||||
def _from_official_pack():
|
||||
"""The key saved by WaveSpeed's own ComfyUI pack, so one key serves both."""
|
||||
path = os.path.join(CUSTOM_NODES_DIR, "wavespeed-comfyui", "config.json")
|
||||
if not os.path.isfile(path):
|
||||
return ""
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
return str(json.load(f).get("api_key") or "").strip()
|
||||
except (OSError, ValueError):
|
||||
return ""
|
||||
|
||||
|
||||
def resolve_api_key(widget_value):
|
||||
"""Returns (key, where it came from). First non-empty source wins."""
|
||||
sources = [
|
||||
("the api_key field on this node", lambda: (widget_value or "").strip()),
|
||||
("comfyui-sf-nodes/config.ini", lambda: _from_ini(os.path.join(PACK_DIR, "config.ini"))),
|
||||
("the WAVESPEED_API_KEY environment variable", lambda: os.environ.get("WAVESPEED_API_KEY", "").strip()),
|
||||
("the official WaveSpeed pack's config.json", _from_official_pack),
|
||||
]
|
||||
for label, read in sources:
|
||||
key = read()
|
||||
if key:
|
||||
return key, label
|
||||
return "", None
|
||||
|
||||
|
||||
class SFWaveSpeedClient:
|
||||
"""
|
||||
WaveSpeed AI API Client Node
|
||||
|
||||
This node creates a client for connecting to the WaveSpeed AI API.
|
||||
Leave api_key empty to reuse a key saved elsewhere — see the tooltip.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@@ -18,7 +58,19 @@ class SFWaveSpeedClient:
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"api_key": ("STRING", {"multiline": False, "default": ""}),
|
||||
"api_key": (
|
||||
"STRING",
|
||||
{
|
||||
"multiline": False,
|
||||
"default": "",
|
||||
"tooltip": (
|
||||
"Leave empty (recommended) to use, in order: comfyui-sf-nodes/config.ini, "
|
||||
"the WAVESPEED_API_KEY environment variable, or the key already saved by "
|
||||
"WaveSpeed's official ComfyUI pack. A key typed here is saved into the "
|
||||
"workflow file, so it travels with any workflow you share."
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -34,44 +86,23 @@ class SFWaveSpeedClient:
|
||||
Create a WaveSpeed AI API client
|
||||
|
||||
Args:
|
||||
api_key: WaveSpeed AI API key
|
||||
api_key: WaveSpeed AI API key; empty to look it up elsewhere
|
||||
|
||||
Returns:
|
||||
WaveSpeedAPI: WaveSpeed AI API client
|
||||
dict holding the resolved key and where it came from
|
||||
"""
|
||||
wavespeed_api_key = ""
|
||||
|
||||
if api_key == "":
|
||||
# Try to read from config.ini
|
||||
try:
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
config_path = os.path.join(parent_dir, "config.ini")
|
||||
|
||||
if os.path.exists(config_path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path)
|
||||
wavespeed_api_key = config.get("API", "api_key", fallback="")
|
||||
|
||||
if not wavespeed_api_key:
|
||||
# Try environment variable
|
||||
wavespeed_api_key = os.environ.get("WAVESPEED_API_KEY", "")
|
||||
|
||||
if not wavespeed_api_key:
|
||||
raise ValueError(
|
||||
"API_KEY is empty. Please provide an API key or set it in config.ini"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(f"Unable to find API_KEY: {str(e)}")
|
||||
|
||||
else:
|
||||
wavespeed_api_key = api_key
|
||||
|
||||
return ({"api_key": wavespeed_api_key},)
|
||||
key, source = resolve_api_key(api_key)
|
||||
if not key:
|
||||
raise ValueError(
|
||||
"No WaveSpeed API key found. Enter one on this node, add it to "
|
||||
"comfyui-sf-nodes/config.ini, set WAVESPEED_API_KEY, or save it in "
|
||||
"WaveSpeed's official ComfyUI pack."
|
||||
)
|
||||
# Never log the key itself — only where it was found.
|
||||
print(f"[SF WaveSpeed Client] Using the API key from {source}.")
|
||||
return ({"api_key": key, "source": source},)
|
||||
|
||||
|
||||
# Node registration
|
||||
NODE_CLASS_MAPPINGS = {"SFWaveSpeedClient": SFWaveSpeedClient}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {"SFWaveSpeedClient": "SF WaveSpeed Client"}
|
||||
|
||||
@@ -187,7 +187,17 @@ class SFWaveSpeedTripoP2ImageTo3D:
|
||||
model_seed=-1, texture_seed=-1, timeout_seconds=900):
|
||||
api = WaveSpeedClient(api_key=client["api_key"])
|
||||
|
||||
image_url = api.upload_file(tensor2images(image)[0])
|
||||
try:
|
||||
image_url = api.upload_file(tensor2images(image)[0])
|
||||
except Exception as e:
|
||||
if "401" in str(e):
|
||||
source = client.get("source", "the SF WaveSpeed Client node")
|
||||
raise RuntimeError(
|
||||
f"WaveSpeed rejected the API key, which came from {source}. "
|
||||
f"Check it on wavespeed.ai under API Keys, or clear the api_key field "
|
||||
f"on SF WaveSpeed Client to fall back to a key saved elsewhere."
|
||||
) from e
|
||||
raise
|
||||
payload = build_payload(
|
||||
image_url, quad, face_limit, texture, pbr, texture_version, delight,
|
||||
auto_size, export_uv, export_orientation, model_seed, texture_seed,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "comfyui-sf-nodes"
|
||||
description = "Custom nodes for ComfyUI including LLM Chat with support for Claude, Gemini, and OpenAI models, WaveSpeed AI image/video generation, VertexAI integration, and workflow utilities"
|
||||
version = "1.6.0"
|
||||
version = "1.6.1"
|
||||
license = { file = "LICENSE" }
|
||||
dependencies = [
|
||||
"requests>=2.31.0",
|
||||
|
||||
Reference in New Issue
Block a user