Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
app-python-comfyui/comfy_api_nodes/nodes_bytedance_llm.py at master · code/app-python-comfyui · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
code
app-python-comfyui
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
app-python-comfyui
/
comfy_api_nodes
/
nodes_bytedance_llm.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
245 lines (220 loc) · 8.68 KB
master
Breadcrumbs
app-python-comfyui
/
comfy_api_nodes
/
nodes_bytedance_llm.py
Copy path
Top
File metadata and controls
Code
Blame
245 lines (220 loc) · 8.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
"""API Nodes for ByteDance Seed LLM via the BytePlus ModelArk Responses API.
See: https://docs.byteplus.com/en/docs/ModelArk/1585128
"""
from
typing_extensions
import
override
from
comfy_api
.
latest
import
IO
,
ComfyExtension
,
Input
from
comfy_api_nodes
.
apis
.
bytedance_llm
import
(
BytePlusInputImage
,
BytePlusInputMessage
,
BytePlusInputText
,
BytePlusInputVideo
,
BytePlusMessageContent
,
BytePlusResponseCreateRequest
,
BytePlusResponseObject
,
)
from
comfy_api_nodes
.
util
import
(
ApiEndpoint
,
get_number_of_images
,
sync_op
,
upload_images_to_comfyapi
,
upload_video_to_comfyapi
,
validate_string
,
)
BYTEPLUS_RESPONSES_ENDPOINT
=
"/proxy/byteplus/api/v3/responses"
SEED_MAX_IMAGES
=
20
SEED_MAX_VIDEOS
=
4
SEED_MODELS
:
dict
[
str
,
str
]
=
{
"Seed 2.0 Pro"
:
"seed-2-0-pro-260328"
,
"Seed 2.0 Lite"
:
"seed-2-0-lite-260228"
,
"Seed 2.0 Mini"
:
"seed-2-0-mini-260215"
,
}
def
_seed_model_inputs
(
max_images
:
int
=
SEED_MAX_IMAGES
,
max_videos
:
int
=
SEED_MAX_VIDEOS
):
return
[
IO
.
Autogrow
.
Input
(
"images"
,
template
=
IO
.
Autogrow
.
TemplateNames
(
IO
.
Image
.
Input
(
"image"
),
names
=
[
f"image_
{
i
}
"
for
i
in
range
(
1
,
max_images
+
1
)],
min
=
0
,
),
tooltip
=
f"Optional image(s) to use as context for the model. Up to
{
max_images
}
images."
,
),
IO
.
Autogrow
.
Input
(
"videos"
,
template
=
IO
.
Autogrow
.
TemplateNames
(
IO
.
Video
.
Input
(
"video"
),
names
=
[
f"video_
{
i
}
"
for
i
in
range
(
1
,
max_videos
+
1
)],
min
=
0
,
),
tooltip
=
f"Optional video(s) to use as context for the model. Up to
{
max_videos
}
videos."
,
),
IO
.
Float
.
Input
(
"temperature"
,
default
=
1.0
,
min
=
0.0
,
max
=
2.0
,
step
=
0.01
,
tooltip
=
"Controls randomness. 0.0 is deterministic, higher values are more random."
,
advanced
=
True
,
),
]
def
_get_text_from_response
(
response
:
BytePlusResponseObject
)
->
str
:
"""Extract concatenated text from all assistant message output_text blocks."""
if
not
response
.
output
:
return
""
chunks
:
list
[
str
]
=
[]
for
item
in
response
.
output
:
if
item
.
type
!=
"message"
or
not
item
.
content
:
continue
for
block
in
item
.
content
:
if
block
.
type
==
"output_text"
and
block
.
text
:
chunks
.
append
(
block
.
text
)
elif
block
.
type
==
"refusal"
and
block
.
refusal
:
raise
ValueError
(
f"Model refused to respond:
{
block
.
refusal
}
"
)
return
"
\n
"
.
join
(
chunks
)
async
def
_build_image_content_blocks
(
cls
:
type
[
IO
.
ComfyNode
],
image_tensors
:
list
[
Input
.
Image
],
)
->
list
[
BytePlusInputImage
]:
urls
=
await
upload_images_to_comfyapi
(
cls
,
image_tensors
,
max_images
=
SEED_MAX_IMAGES
,
wait_label
=
"Uploading reference images"
,
)
return
[
BytePlusInputImage
(
image_url
=
url
)
for
url
in
urls
]
async
def
_build_video_content_blocks
(
cls
:
type
[
IO
.
ComfyNode
],
videos
:
list
[
Input
.
Video
],
)
->
list
[
BytePlusInputVideo
]:
blocks
:
list
[
BytePlusInputVideo
]
=
[]
total
=
len
(
videos
)
for
idx
,
video
in
enumerate
(
videos
):
label
=
"Uploading reference video"
if
total
>
1
:
label
=
f"
{
label
}
(
{
idx
+
1
}
/
{
total
}
)"
url
=
await
upload_video_to_comfyapi
(
cls
,
video
,
wait_label
=
label
)
blocks
.
append
(
BytePlusInputVideo
(
video_url
=
url
))
return
blocks
class
ByteDanceSeedNode
(
IO
.
ComfyNode
):
"""Generate text responses from a ByteDance Seed 2.0 model."""
@
classmethod
def
define_schema
(
cls
):
return
IO
.
Schema
(
node_id
=
"ByteDanceSeedNode"
,
display_name
=
"ByteDance Seed"
,
category
=
"partner/text/ByteDance"
,
essentials_category
=
"Text Generation"
,
description
=
"Generate text responses with ByteDance's Seed 2.0 models. "
"Provide a text prompt and optionally one or more images or videos for multimodal context."
,
inputs
=
[
IO
.
String
.
Input
(
"prompt"
,
multiline
=
True
,
default
=
""
,
tooltip
=
"Text input to the model."
,
),
IO
.
DynamicCombo
.
Input
(
"model"
,
options
=
[
IO
.
DynamicCombo
.
Option
(
label
,
_seed_model_inputs
())
for
label
in
SEED_MODELS
],
tooltip
=
"The Seed model used to generate the response."
,
),
IO
.
Int
.
Input
(
"seed"
,
default
=
0
,
min
=
0
,
max
=
2147483647
,
control_after_generate
=
True
,
tooltip
=
"Seed controls whether the node should re-run; "
"results are non-deterministic regardless of seed."
,
),
IO
.
String
.
Input
(
"system_prompt"
,
multiline
=
True
,
default
=
""
,
optional
=
True
,
advanced
=
True
,
tooltip
=
"Foundational instructions that dictate the model's behavior."
,
),
],
outputs
=
[
IO
.
String
.
Output
()],
hidden
=
[
IO
.
Hidden
.
auth_token_comfy_org
,
IO
.
Hidden
.
api_key_comfy_org
,
IO
.
Hidden
.
unique_id
,
],
is_api_node
=
True
,
price_badge
=
IO
.
PriceBadge
(
depends_on
=
IO
.
PriceBadgeDepends
(
widgets
=
[
"model"
]),
expr
=
"""
(
$m := widgets.model;
$contains($m, "mini") ? {
"type": "list_usd",
"usd": [0.00025, 0.0009],
"format": { "approximate": true, "separator": "-", "suffix": " per 1K tokens" }
}
: $contains($m, "lite") ? {
"type": "list_usd",
"usd": [0.0003, 0.002],
"format": { "approximate": true, "separator": "-", "suffix": " per 1K tokens" }
}
: $contains($m, "pro") ? {
"type": "list_usd",
"usd": [0.0005, 0.003],
"format": { "approximate": true, "separator": "-", "suffix": " per 1K tokens" }
}
: {"type":"text", "text":"Token-based"}
)
"""
,
),
)
@
classmethod
async
def
execute
(
cls
,
prompt
:
str
,
model
:
dict
,
seed
:
int
,
system_prompt
:
str
=
""
,
)
->
IO
.
NodeOutput
:
validate_string
(
prompt
,
strip_whitespace
=
True
,
min_length
=
1
)
model_label
=
model
[
"model"
]
temperature
=
model
[
"temperature"
]
model_id
=
SEED_MODELS
[
model_label
]
image_tensors
:
list
[
Input
.
Image
]
=
[
t
for
t
in
(
model
.
get
(
"images"
)
or
{}).
values
()
if
t
is
not
None
]
if
sum
(
get_number_of_images
(
t
)
for
t
in
image_tensors
)
>
SEED_MAX_IMAGES
:
raise
ValueError
(
f"Up to
{
SEED_MAX_IMAGES
}
images are supported per request."
)
video_inputs
:
list
[
Input
.
Video
]
=
[
v
for
v
in
(
model
.
get
(
"videos"
)
or
{}).
values
()
if
v
is
not
None
]
if
len
(
video_inputs
)
>
SEED_MAX_VIDEOS
:
raise
ValueError
(
f"Up to
{
SEED_MAX_VIDEOS
}
videos are supported per request."
)
content
:
list
[
BytePlusMessageContent
]
=
[]
if
image_tensors
:
content
.
extend
(
await
_build_image_content_blocks
(
cls
,
image_tensors
))
if
video_inputs
:
content
.
extend
(
await
_build_video_content_blocks
(
cls
,
video_inputs
))
content
.
append
(
BytePlusInputText
(
text
=
prompt
))
response
=
await
sync_op
(
cls
,
ApiEndpoint
(
path
=
BYTEPLUS_RESPONSES_ENDPOINT
,
method
=
"POST"
),
response_model
=
BytePlusResponseObject
,
data
=
BytePlusResponseCreateRequest
(
model
=
model_id
,
input
=
[
BytePlusInputMessage
(
role
=
"user"
,
content
=
content
)],
instructions
=
system_prompt
or
None
,
temperature
=
temperature
,
store
=
False
,
stream
=
False
,
),
)
if
response
.
error
:
raise
ValueError
(
f"Seed API error (
{
response
.
error
.
code
}
):
{
response
.
error
.
message
}
"
)
result
=
_get_text_from_response
(
response
)
if
not
result
:
raise
ValueError
(
"Empty response from Seed model."
)
return
IO
.
NodeOutput
(
result
)
class
ByteDanceLLMExtension
(
ComfyExtension
):
@
override
async
def
get_node_list
(
self
)
->
list
[
type
[
IO
.
ComfyNode
]]:
return
[
ByteDanceSeedNode
]
async
def
comfy_entrypoint
()
->
ByteDanceLLMExtension
:
return
ByteDanceLLMExtension
()
You can’t perform that action at this time.