Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions comfy_api_nodes/apis/typesafe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Literal

from pydantic import BaseModel, Field


class TypeSafeImageAsset(BaseModel):
type: Literal["image"] = "image"
format: Literal["jpg"] = "jpg"
data_base64: str = Field(...)


class TypeSafeNoulQuestion(BaseModel):
type: Literal["noul"] = "noul"
instructions: str = Field(...)


class TypeSafeChoiceQuestion(BaseModel):
type: Literal["choice"] = "choice"
instructions: str = Field(...)
criteria: dict[str, str] = Field(...)


class TypeSafeScoreQuestion(BaseModel):
type: Literal["score"] = "score"
instructions: str = Field(...)
criteria: list[str] = Field(...)


class TypeSafeSystemOneRequest(BaseModel):
model: str = Field(...)
state: dict[str, str | list[str]] = Field(...)
questions: dict[str, TypeSafeNoulQuestion | TypeSafeChoiceQuestion | TypeSafeScoreQuestion] = Field(...)
assets: dict[str, TypeSafeImageAsset] | None = Field(None)


class TypeSafeAnswer(BaseModel):
type: str = Field(...)
noul: float | None = Field(None)
choice: str | None = Field(None)
score: float | None = Field(None)
confidence: float | None = Field(None)


class TypeSafeSystemOneResponse(BaseModel):
model: str = Field(...)
answers: dict[str, TypeSafeAnswer] = Field(...)
4 changes: 2 additions & 2 deletions comfy_api_nodes/nodes_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,8 @@ def _parse_decision_options(options: str) -> list[str]:
raise ValueError(f"The option on line {number} is longer than 128 characters.")
if not name.isprintable():
raise ValueError(f"The option on line {number} contains an invisible or control character.")
if name in names:
raise ValueError(f"The option '{name}' is listed twice.")
if list(map(str.casefold, name)) in (list(map(str.casefold, n)) for n in names):
raise ValueError(f"The option '{name}' is listed twice. Options must differ by more than letter case.")
names.append(name)
if not 2 <= len(names) <= 255:
raise ValueError(f"Give 2 to 255 options, one per line. Got {len(names)}.")
Expand Down
9 changes: 5 additions & 4 deletions comfy_api_nodes/nodes_heygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ async def execute(

def _parse_decision_options(options: str) -> list[str]:
names: list[str] = []
folded: dict[str, str] = {}
folded: dict[tuple[str, ...], str] = {}
for number, line in enumerate(options.splitlines(), 1):
name = line.strip()
if not name:
Expand All @@ -1924,9 +1924,10 @@ def _parse_decision_options(options: str) -> list[str]:
raise ValueError(f"The option on line {number} contains an invisible or control character.")
if name in names:
raise ValueError(f"The option '{name}' is listed twice.")
if name.casefold() in folded:
raise ValueError(f"The options '{folded[name.casefold()]}' and '{name}' differ only in letter case.")
folded[name.casefold()] = name
key = tuple(map(str.casefold, name))
if key in folded:
raise ValueError(f"The options '{folded[key]}' and '{name}' differ only in letter case.")
folded[key] = name
names.append(name)
if not 2 <= len(names) <= 255:
raise ValueError(f"Give 2 to 255 options, one per line. Got {len(names)}.")
Expand Down
Loading
Loading