mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-12-16 17:42:58 +08:00
fix(api-nodes): edge cases in responses for Gemini models (#10860)
This commit is contained in:
parent
f66183a541
commit
3bd71554a2
@ -113,9 +113,9 @@ class GeminiGenerationConfig(BaseModel):
|
|||||||
maxOutputTokens: int | None = Field(None, ge=16, le=8192)
|
maxOutputTokens: int | None = Field(None, ge=16, le=8192)
|
||||||
seed: int | None = Field(None)
|
seed: int | None = Field(None)
|
||||||
stopSequences: list[str] | None = Field(None)
|
stopSequences: list[str] | None = Field(None)
|
||||||
temperature: float | None = Field(1, ge=0.0, le=2.0)
|
temperature: float | None = Field(None, ge=0.0, le=2.0)
|
||||||
topK: int | None = Field(40, ge=1)
|
topK: int | None = Field(None, ge=1)
|
||||||
topP: float | None = Field(0.95, ge=0.0, le=1.0)
|
topP: float | None = Field(None, ge=0.0, le=1.0)
|
||||||
|
|
||||||
|
|
||||||
class GeminiImageConfig(BaseModel):
|
class GeminiImageConfig(BaseModel):
|
||||||
|
|||||||
@ -104,14 +104,14 @@ def get_parts_by_type(response: GeminiGenerateContentResponse, part_type: Litera
|
|||||||
List of response parts matching the requested type.
|
List of response parts matching the requested type.
|
||||||
"""
|
"""
|
||||||
if response.candidates is None:
|
if response.candidates is None:
|
||||||
if response.promptFeedback.blockReason:
|
if response.promptFeedback and response.promptFeedback.blockReason:
|
||||||
feedback = response.promptFeedback
|
feedback = response.promptFeedback
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})"
|
f"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})"
|
||||||
)
|
)
|
||||||
raise NotImplementedError(
|
raise ValueError(
|
||||||
"Gemini returned no response candidates. "
|
"Gemini API returned no response candidates. If you are using the `IMAGE` modality, "
|
||||||
"Please report to ComfyUI repository with the example of workflow to reproduce this."
|
"try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed."
|
||||||
)
|
)
|
||||||
parts = []
|
parts = []
|
||||||
for part in response.candidates[0].content.parts:
|
for part in response.candidates[0].content.parts:
|
||||||
@ -182,6 +182,7 @@ def calculate_tokens_price(response: GeminiGenerateContentResponse) -> float | N
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
final_price = response.usageMetadata.promptTokenCount * input_tokens_price
|
final_price = response.usageMetadata.promptTokenCount * input_tokens_price
|
||||||
|
if response.usageMetadata.candidatesTokensDetails:
|
||||||
for i in response.usageMetadata.candidatesTokensDetails:
|
for i in response.usageMetadata.candidatesTokensDetails:
|
||||||
if i.modality == Modality.IMAGE:
|
if i.modality == Modality.IMAGE:
|
||||||
final_price += output_image_tokens_price * i.tokenCount # for Nano Banana models
|
final_price += output_image_tokens_price * i.tokenCount # for Nano Banana models
|
||||||
@ -645,7 +646,7 @@ class GeminiImage2(IO.ComfyNode):
|
|||||||
options=["auto", "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"],
|
options=["auto", "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"],
|
||||||
default="auto",
|
default="auto",
|
||||||
tooltip="If set to 'auto', matches your input image's aspect ratio; "
|
tooltip="If set to 'auto', matches your input image's aspect ratio; "
|
||||||
"if no image is provided, generates a 1:1 square.",
|
"if no image is provided, a 16:9 square is usually generated.",
|
||||||
),
|
),
|
||||||
IO.Combo.Input(
|
IO.Combo.Input(
|
||||||
"resolution",
|
"resolution",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user