add waas服务器支持多comfyui执行器
This commit is contained in:
@@ -1,15 +1,48 @@
|
||||
from dotenv import dotenv_values
|
||||
import json
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from typing import List
|
||||
|
||||
|
||||
class ComfyUIServer(BaseModel):
|
||||
"""定义单个ComfyUI服务器的配置模型。"""
|
||||
http_url: str
|
||||
ws_url: str
|
||||
input_dir: str
|
||||
output_dir: str
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file='./.env', env_file_encoding='utf-8')
|
||||
COMFYUI_URL: str = "ws://127.0.0.1:8188/ws"
|
||||
COMFYUI_HTTP_URL: str = "http://127.0.0.1:8188"
|
||||
COMFYUI_INPUT_DIR: str
|
||||
COMFYUI_OUTPUT_DIR: str
|
||||
"""
|
||||
应用配置类,通过.env文件加载环境变量。
|
||||
"""
|
||||
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
|
||||
|
||||
# [核心改动] 使用JSON字符串来定义一个服务器列表
|
||||
COMFYUI_SERVERS_JSON: str = '[{"http_url": "http://127.0.0.1:8188", "ws_url": "ws://127.0.0.1:8188/ws", "input_dir": "/comfyui/input", "output_dir": "/comfyui/output"}]'
|
||||
|
||||
DB_FILE: str = "/db/workflows_service.sqlite"
|
||||
# S3 和 AWS 配置保持不变
|
||||
S3_BUCKET_NAME: str
|
||||
AWS_ACCESS_KEY_ID: str
|
||||
AWS_SECRET_ACCESS_KEY: str
|
||||
AWS_REGION_NAME: str
|
||||
|
||||
# settings = Settings()
|
||||
@property
|
||||
def SERVERS(self) -> List[ComfyUIServer]:
|
||||
"""
|
||||
解析JSON配置字符串,返回一个经过验证的服务器配置对象列表。
|
||||
"""
|
||||
try:
|
||||
server_list = json.loads(self.COMFYUI_SERVERS_JSON)
|
||||
# 使用Pydantic模型进行验证和类型转换
|
||||
return [ComfyUIServer(**server) for server in server_list]
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError("COMFYUI_SERVERS_JSON 格式无效,必须是有效的JSON数组。")
|
||||
except ValidationError as e:
|
||||
raise ValueError(f"COMFYUI_SERVERS_JSON 中的服务器配置无效: {e}")
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user