Skip to content

Commit dc9ab5d

Browse files
bigcat88gmaOCR
authored andcommitted
convert nodes_qwen.py to V3 schema (comfyanonymous#10049)
1 parent 55f50bf commit dc9ab5d

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

comfy_extras/nodes_qwen.py

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
import node_helpers
22
import comfy.utils
33
import math
4+
from typing_extensions import override
5+
from comfy_api.latest import ComfyExtension, io
46

57

6-
class TextEncodeQwenImageEdit:
8+
class TextEncodeQwenImageEdit(io.ComfyNode):
79
@classmethod
8-
def INPUT_TYPES(s):
9-
return {"required": {
10-
"clip": ("CLIP", ),
11-
"prompt": ("STRING", {"multiline": True, "dynamicPrompts": True}),
12-
},
13-
"optional": {"vae": ("VAE", ),
14-
"image": ("IMAGE", ),}}
10+
def define_schema(cls):
11+
return io.Schema(
12+
node_id="TextEncodeQwenImageEdit",
13+
category="advanced/conditioning",
14+
inputs=[
15+
io.Clip.Input("clip"),
16+
io.String.Input("prompt", multiline=True, dynamic_prompts=True),
17+
io.Vae.Input("vae", optional=True),
18+
io.Image.Input("image", optional=True),
19+
],
20+
outputs=[
21+
io.Conditioning.Output(),
22+
],
23+
)
1524

16-
RETURN_TYPES = ("CONDITIONING",)
17-
FUNCTION = "encode"
18-
19-
CATEGORY = "advanced/conditioning"
20-
21-
def encode(self, clip, prompt, vae=None, image=None):
25+
@classmethod
26+
def execute(cls, clip, prompt, vae=None, image=None) -> io.NodeOutput:
2227
ref_latent = None
2328
if image is None:
2429
images = []
@@ -40,28 +45,30 @@ def encode(self, clip, prompt, vae=None, image=None):
4045
conditioning = clip.encode_from_tokens_scheduled(tokens)
4146
if ref_latent is not None:
4247
conditioning = node_helpers.conditioning_set_values(conditioning, {"reference_latents": [ref_latent]}, append=True)
43-
return (conditioning, )
48+
return io.NodeOutput(conditioning)
4449

4550

46-
class TextEncodeQwenImageEditPlus:
51+
class TextEncodeQwenImageEditPlus(io.ComfyNode):
4752
@classmethod
48-
def INPUT_TYPES(s):
49-
return {"required": {
50-
"clip": ("CLIP", ),
51-
"prompt": ("STRING", {"multiline": True, "dynamicPrompts": True}),
52-
},
53-
"optional": {"vae": ("VAE", ),
54-
"image1": ("IMAGE", ),
55-
"image2": ("IMAGE", ),
56-
"image3": ("IMAGE", ),
57-
}}
58-
59-
RETURN_TYPES = ("CONDITIONING",)
60-
FUNCTION = "encode"
61-
62-
CATEGORY = "advanced/conditioning"
63-
64-
def encode(self, clip, prompt, vae=None, image1=None, image2=None, image3=None):
53+
def define_schema(cls):
54+
return io.Schema(
55+
node_id="TextEncodeQwenImageEditPlus",
56+
category="advanced/conditioning",
57+
inputs=[
58+
io.Clip.Input("clip"),
59+
io.String.Input("prompt", multiline=True, dynamic_prompts=True),
60+
io.Vae.Input("vae", optional=True),
61+
io.Image.Input("image1", optional=True),
62+
io.Image.Input("image2", optional=True),
63+
io.Image.Input("image3", optional=True),
64+
],
65+
outputs=[
66+
io.Conditioning.Output(),
67+
],
68+
)
69+
70+
@classmethod
71+
def execute(cls, clip, prompt, vae=None, image1=None, image2=None, image3=None) -> io.NodeOutput:
6572
ref_latents = []
6673
images = [image1, image2, image3]
6774
images_vl = []
@@ -94,10 +101,17 @@ def encode(self, clip, prompt, vae=None, image1=None, image2=None, image3=None):
94101
conditioning = clip.encode_from_tokens_scheduled(tokens)
95102
if len(ref_latents) > 0:
96103
conditioning = node_helpers.conditioning_set_values(conditioning, {"reference_latents": ref_latents}, append=True)
97-
return (conditioning, )
104+
return io.NodeOutput(conditioning)
105+
106+
107+
class QwenExtension(ComfyExtension):
108+
@override
109+
async def get_node_list(self) -> list[type[io.ComfyNode]]:
110+
return [
111+
TextEncodeQwenImageEdit,
112+
TextEncodeQwenImageEditPlus,
113+
]
98114

99115

100-
NODE_CLASS_MAPPINGS = {
101-
"TextEncodeQwenImageEdit": TextEncodeQwenImageEdit,
102-
"TextEncodeQwenImageEditPlus": TextEncodeQwenImageEditPlus,
103-
}
116+
async def comfy_entrypoint() -> QwenExtension:
117+
return QwenExtension()

0 commit comments

Comments
 (0)