63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from comfy_api.latest import ComfyExtension, io
|
||
|
||
class ConfigOptions(io.ComfyNode):
|
||
"""
|
||
这个节点用于覆盖 API 的配置参数(api_url、api_key、api_protocol、timeout)
|
||
"""
|
||
|
||
@classmethod
|
||
def define_schema(cls) -> io.Schema:
|
||
return io.Schema(
|
||
node_id="YCYY_API_Config_Options",
|
||
display_name="API Config Options",
|
||
category="YCYY/API/utils",
|
||
inputs=[
|
||
io.String.Input(
|
||
id="api_url",
|
||
multiline=True,
|
||
tooltip="Override the API URL"
|
||
),
|
||
io.String.Input(
|
||
id="api_key",
|
||
default="",
|
||
multiline=True,
|
||
tooltip="Override the API key"
|
||
),
|
||
io.Combo.Input(
|
||
id="api_protocol",
|
||
options=["openai-completions", "openai-responses", "anthropic-messages"],
|
||
default="openai-completions",
|
||
tooltip="Override the API protocol"
|
||
),
|
||
io.Int.Input(
|
||
id="timeout",
|
||
default=120,
|
||
min=1,
|
||
max=600,
|
||
tooltip="Override the request timeout in seconds"
|
||
)
|
||
],
|
||
outputs=[
|
||
io.AnyType.Output(
|
||
id="config_options",
|
||
display_name="config_options",
|
||
tooltip="Override configuration options"
|
||
)
|
||
],
|
||
description="This node provides override API config options."
|
||
)
|
||
|
||
@classmethod
|
||
def execute(cls, api_url, api_key, api_protocol, timeout) -> io.NodeOutput:
|
||
# 验证和清理输入
|
||
api_url = api_url.strip() if api_url else ""
|
||
api_key = api_key.strip() if api_key else ""
|
||
|
||
config_options = {
|
||
"api_url": api_url,
|
||
"api_key": api_key,
|
||
"api_protocol": api_protocol,
|
||
"timeout": timeout
|
||
}
|
||
|
||
return io.NodeOutput(config_options) |