mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-24 18:43:36 +08:00
fix(api-nodes): add support for "thought_image" in Nano Banana 2 and corrected price badges (#13038)
This commit is contained in:
parent
b941913f1d
commit
06957022d4
@ -67,6 +67,7 @@ class GeminiPart(BaseModel):
|
|||||||
inlineData: GeminiInlineData | None = Field(None)
|
inlineData: GeminiInlineData | None = Field(None)
|
||||||
fileData: GeminiFileData | None = Field(None)
|
fileData: GeminiFileData | None = Field(None)
|
||||||
text: str | None = Field(None)
|
text: str | None = Field(None)
|
||||||
|
thought: bool | None = Field(None)
|
||||||
|
|
||||||
|
|
||||||
class GeminiTextPart(BaseModel):
|
class GeminiTextPart(BaseModel):
|
||||||
|
|||||||
@ -63,7 +63,7 @@ GEMINI_IMAGE_2_PRICE_BADGE = IO.PriceBadge(
|
|||||||
$m := widgets.model;
|
$m := widgets.model;
|
||||||
$r := widgets.resolution;
|
$r := widgets.resolution;
|
||||||
$isFlash := $contains($m, "nano banana 2");
|
$isFlash := $contains($m, "nano banana 2");
|
||||||
$flashPrices := {"1k": 0.0696, "2k": 0.0696, "4k": 0.123};
|
$flashPrices := {"1k": 0.0696, "2k": 0.1014, "4k": 0.154};
|
||||||
$proPrices := {"1k": 0.134, "2k": 0.134, "4k": 0.24};
|
$proPrices := {"1k": 0.134, "2k": 0.134, "4k": 0.24};
|
||||||
$prices := $isFlash ? $flashPrices : $proPrices;
|
$prices := $isFlash ? $flashPrices : $proPrices;
|
||||||
{"type":"usd","usd": $lookup($prices, $r), "format":{"suffix":"/Image","approximate":true}}
|
{"type":"usd","usd": $lookup($prices, $r), "format":{"suffix":"/Image","approximate":true}}
|
||||||
@ -188,10 +188,12 @@ def get_text_from_response(response: GeminiGenerateContentResponse) -> str:
|
|||||||
return "\n".join([part.text for part in parts])
|
return "\n".join([part.text for part in parts])
|
||||||
|
|
||||||
|
|
||||||
async def get_image_from_response(response: GeminiGenerateContentResponse) -> Input.Image:
|
async def get_image_from_response(response: GeminiGenerateContentResponse, thought: bool = False) -> Input.Image:
|
||||||
image_tensors: list[Input.Image] = []
|
image_tensors: list[Input.Image] = []
|
||||||
parts = get_parts_by_type(response, "image/*")
|
parts = get_parts_by_type(response, "image/*")
|
||||||
for part in parts:
|
for part in parts:
|
||||||
|
if (part.thought is True) != thought:
|
||||||
|
continue
|
||||||
if part.inlineData:
|
if part.inlineData:
|
||||||
image_data = base64.b64decode(part.inlineData.data)
|
image_data = base64.b64decode(part.inlineData.data)
|
||||||
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
|
||||||
@ -931,6 +933,11 @@ class GeminiNanoBanana2(IO.ComfyNode):
|
|||||||
outputs=[
|
outputs=[
|
||||||
IO.Image.Output(),
|
IO.Image.Output(),
|
||||||
IO.String.Output(),
|
IO.String.Output(),
|
||||||
|
IO.Image.Output(
|
||||||
|
display_name="thought_image",
|
||||||
|
tooltip="First image from the model's thinking process. "
|
||||||
|
"Only available with thinking_level HIGH and IMAGE+TEXT modality.",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
hidden=[
|
hidden=[
|
||||||
IO.Hidden.auth_token_comfy_org,
|
IO.Hidden.auth_token_comfy_org,
|
||||||
@ -992,7 +999,11 @@ class GeminiNanoBanana2(IO.ComfyNode):
|
|||||||
response_model=GeminiGenerateContentResponse,
|
response_model=GeminiGenerateContentResponse,
|
||||||
price_extractor=calculate_tokens_price,
|
price_extractor=calculate_tokens_price,
|
||||||
)
|
)
|
||||||
return IO.NodeOutput(await get_image_from_response(response), get_text_from_response(response))
|
return IO.NodeOutput(
|
||||||
|
await get_image_from_response(response),
|
||||||
|
get_text_from_response(response),
|
||||||
|
await get_image_from_response(response, thought=True),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GeminiExtension(ComfyExtension):
|
class GeminiExtension(ComfyExtension):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user