mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-24 09:22:32 +08:00
[Partner Nodes] GPTImage: fix price badges, add new resolutions (#13519)
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run
Some checks are pending
Python Linting / Run Ruff (push) Waiting to run
Python Linting / Run Pylint (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Waiting to run
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Waiting to run
Execution Tests / test (macos-latest) (push) Waiting to run
Execution Tests / test (ubuntu-latest) (push) Waiting to run
Execution Tests / test (windows-latest) (push) Waiting to run
Test server launches without errors / test (push) Waiting to run
Unit Tests / test (macos-latest) (push) Waiting to run
Unit Tests / test (ubuntu-latest) (push) Waiting to run
Unit Tests / test (windows-2022) (push) Waiting to run
* fix(api-nodes): fixed price badges, add new resolutions Signed-off-by: bigcat88 <bigcat88@icloud.com> * proper calculate the total run cost when "n > 1" Signed-off-by: bigcat88 <bigcat88@icloud.com> --------- Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
parent
749d5b4e8d
commit
3cdc0d523f
@ -357,6 +357,10 @@ def calculate_tokens_price_image_1_5(response: OpenAIImageGenerationResponse) ->
|
|||||||
return ((response.usage.input_tokens * 8.0) + (response.usage.output_tokens * 32.0)) / 1_000_000.0
|
return ((response.usage.input_tokens * 8.0) + (response.usage.output_tokens * 32.0)) / 1_000_000.0
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_tokens_price_image_2_0(response: OpenAIImageGenerationResponse) -> float | None:
|
||||||
|
return ((response.usage.input_tokens * 8.0) + (response.usage.output_tokens * 30.0)) / 1_000_000.0
|
||||||
|
|
||||||
|
|
||||||
class OpenAIGPTImage1(IO.ComfyNode):
|
class OpenAIGPTImage1(IO.ComfyNode):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -401,7 +405,17 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
IO.Combo.Input(
|
IO.Combo.Input(
|
||||||
"size",
|
"size",
|
||||||
default="auto",
|
default="auto",
|
||||||
options=["auto", "1024x1024", "1024x1536", "1536x1024"],
|
options=[
|
||||||
|
"auto",
|
||||||
|
"1024x1024",
|
||||||
|
"1024x1536",
|
||||||
|
"1536x1024",
|
||||||
|
"2048x2048",
|
||||||
|
"2048x1152",
|
||||||
|
"1152x2048",
|
||||||
|
"3840x2160",
|
||||||
|
"2160x3840",
|
||||||
|
],
|
||||||
tooltip="Image size",
|
tooltip="Image size",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
@ -427,7 +441,7 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
),
|
),
|
||||||
IO.Combo.Input(
|
IO.Combo.Input(
|
||||||
"model",
|
"model",
|
||||||
options=["gpt-image-1", "gpt-image-1.5", 'gpt-image-2'],
|
options=["gpt-image-1", "gpt-image-1.5", "gpt-image-2"],
|
||||||
default="gpt-image-2",
|
default="gpt-image-2",
|
||||||
optional=True,
|
optional=True,
|
||||||
),
|
),
|
||||||
@ -442,23 +456,36 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
],
|
],
|
||||||
is_api_node=True,
|
is_api_node=True,
|
||||||
price_badge=IO.PriceBadge(
|
price_badge=IO.PriceBadge(
|
||||||
depends_on=IO.PriceBadgeDepends(widgets=["quality", "n"]),
|
depends_on=IO.PriceBadgeDepends(widgets=["quality", "n", "model"]),
|
||||||
expr="""
|
expr="""
|
||||||
(
|
(
|
||||||
$ranges := {
|
$ranges := {
|
||||||
"low": [0.011, 0.02],
|
"gpt-image-1": {
|
||||||
"medium": [0.046, 0.07],
|
"low": [0.011, 0.02],
|
||||||
"high": [0.167, 0.3]
|
"medium": [0.042, 0.07],
|
||||||
|
"high": [0.167, 0.25]
|
||||||
|
},
|
||||||
|
"gpt-image-1.5": {
|
||||||
|
"low": [0.009, 0.02],
|
||||||
|
"medium": [0.034, 0.062],
|
||||||
|
"high": [0.133, 0.22]
|
||||||
|
},
|
||||||
|
"gpt-image-2": {
|
||||||
|
"low": [0.0048, 0.012],
|
||||||
|
"medium": [0.041, 0.112],
|
||||||
|
"high": [0.165, 0.43]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
$range := $lookup($ranges, widgets.quality);
|
$range := $lookup($lookup($ranges, widgets.model), widgets.quality);
|
||||||
$n := widgets.n;
|
$nRaw := widgets.n;
|
||||||
|
$n := ($nRaw != null and $nRaw != 0) ? $nRaw : 1;
|
||||||
($n = 1)
|
($n = 1)
|
||||||
? {"type":"range_usd","min_usd": $range[0], "max_usd": $range[1]}
|
? {"type":"range_usd","min_usd": $range[0], "max_usd": $range[1], "format": {"approximate": true}}
|
||||||
: {
|
: {
|
||||||
"type":"range_usd",
|
"type":"range_usd",
|
||||||
"min_usd": $range[0],
|
"min_usd": $range[0] * $n,
|
||||||
"max_usd": $range[1],
|
"max_usd": $range[1] * $n,
|
||||||
"format": { "suffix": " x " & $string($n) & "/Run" }
|
"format": { "suffix": "/Run", "approximate": true }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
""",
|
""",
|
||||||
@ -483,12 +510,18 @@ class OpenAIGPTImage1(IO.ComfyNode):
|
|||||||
if mask is not None and image is None:
|
if mask is not None and image is None:
|
||||||
raise ValueError("Cannot use a mask without an input image")
|
raise ValueError("Cannot use a mask without an input image")
|
||||||
|
|
||||||
|
if model in ("gpt-image-1", "gpt-image-1.5"):
|
||||||
|
if size not in ("auto", "1024x1024", "1024x1536", "1536x1024"):
|
||||||
|
raise ValueError(f"Resolution {size} is only supported by GPT Image 2 model")
|
||||||
|
|
||||||
if model == "gpt-image-1":
|
if model == "gpt-image-1":
|
||||||
price_extractor = calculate_tokens_price_image_1
|
price_extractor = calculate_tokens_price_image_1
|
||||||
elif model == "gpt-image-1.5":
|
elif model == "gpt-image-1.5":
|
||||||
price_extractor = calculate_tokens_price_image_1_5
|
price_extractor = calculate_tokens_price_image_1_5
|
||||||
elif model == "gpt-image-2":
|
elif model == "gpt-image-2":
|
||||||
price_extractor = calculate_tokens_price_image_1_5
|
price_extractor = calculate_tokens_price_image_2_0
|
||||||
|
if background == "transparent":
|
||||||
|
raise ValueError("Transparent background is not supported for GPT Image 2 model")
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown model: {model}")
|
raise ValueError(f"Unknown model: {model}")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user