Merge branch 'main' of gitee.com:wg123/video-gen into main
This commit is contained in:
@@ -48,40 +48,70 @@ async def get_credit_ratios(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
async def get_ratios_for_engine_type(gen_type: str, engine_ids: list):
|
||||
for engine_id in engine_ids:
|
||||
import json
|
||||
|
||||
async def get_engine_with_ratios(gen_type: str, engines: list):
|
||||
for engine in engines:
|
||||
result = await db.execute(
|
||||
select(CreditRatio)
|
||||
.where(CreditRatio.gen_type == gen_type)
|
||||
.where(CreditRatio.model_config_id == engine_id)
|
||||
.where(CreditRatio.model_config_id == engine.id)
|
||||
)
|
||||
ratios = result.scalars().all()
|
||||
if ratios:
|
||||
return [CreditRatioOut.model_validate(r) for r in ratios]
|
||||
return []
|
||||
|
||||
ratios_out = [CreditRatioOut.model_validate(r) for r in ratios]
|
||||
engine_info = {
|
||||
"id": engine.id,
|
||||
"name": engine.name,
|
||||
"provider": engine.provider,
|
||||
"ratios": ratios_out,
|
||||
}
|
||||
if gen_type == "video":
|
||||
try:
|
||||
supported_ratios = json.loads(engine.supported_ratios) if engine.supported_ratios else []
|
||||
except Exception:
|
||||
supported_ratios = []
|
||||
try:
|
||||
supported_resolutions = json.loads(engine.supported_resolutions) if engine.supported_resolutions else []
|
||||
except Exception:
|
||||
supported_resolutions = []
|
||||
try:
|
||||
supported_durations = json.loads(engine.supported_durations) if engine.supported_durations else []
|
||||
except Exception:
|
||||
supported_durations = []
|
||||
engine_info.update({
|
||||
"supported_ratios": supported_ratios,
|
||||
"supported_resolutions": supported_resolutions,
|
||||
"supported_durations": supported_durations,
|
||||
"max_duration": engine.max_duration,
|
||||
"max_image_count": engine.max_image_count,
|
||||
"max_video_count": engine.max_video_count,
|
||||
})
|
||||
return engine_info
|
||||
return None
|
||||
|
||||
video_engines_result = await db.execute(
|
||||
select(VideoEngine.id)
|
||||
select(VideoEngine)
|
||||
.where(VideoEngine.is_active == True)
|
||||
.order_by(VideoEngine.priority.desc())
|
||||
)
|
||||
video_engine_ids = video_engines_result.scalars().all()
|
||||
|
||||
video_engines = video_engines_result.scalars().all()
|
||||
|
||||
image_engines_result = await db.execute(
|
||||
select(ImageEngine.id)
|
||||
select(ImageEngine)
|
||||
.where(ImageEngine.is_active == True)
|
||||
.order_by(ImageEngine.priority.desc())
|
||||
)
|
||||
image_engine_ids = image_engines_result.scalars().all()
|
||||
|
||||
image_engines = image_engines_result.scalars().all()
|
||||
|
||||
grouped = {}
|
||||
|
||||
video_ratios = await get_ratios_for_engine_type("video", video_engine_ids)
|
||||
if video_ratios:
|
||||
grouped["video"] = video_ratios
|
||||
|
||||
image_ratios = await get_ratios_for_engine_type("image", image_engine_ids)
|
||||
if image_ratios:
|
||||
grouped["image"] = image_ratios
|
||||
|
||||
|
||||
video_data = await get_engine_with_ratios("video", video_engines)
|
||||
if video_data:
|
||||
grouped["video"] = video_data
|
||||
|
||||
image_data = await get_engine_with_ratios("image", image_engines)
|
||||
if image_data:
|
||||
grouped["image"] = image_data
|
||||
|
||||
return grouped
|
||||
|
||||
@@ -49,5 +49,7 @@ async def list_active_engines(
|
||||
"supported_ratios": ratios,
|
||||
"supported_resolutions": resolutions,
|
||||
"supported_durations": durations,
|
||||
"max_image_count": e.max_image_count,
|
||||
"max_video_count": e.max_video_count,
|
||||
})
|
||||
return {"items": items}
|
||||
|
||||
@@ -17,6 +17,8 @@ class VideoEngine(Base, TimestampMixin):
|
||||
supported_resolutions: Mapped[str] = mapped_column(String(256), default='["480p","720p","1080p"]')
|
||||
supported_durations: Mapped[str] = mapped_column(String(256), nullable=True, default='[4,5,6,7,8,9,10,11,12,13,14,15]')
|
||||
max_duration: Mapped[int] = mapped_column(Integer, default=15)
|
||||
max_image_count: Mapped[int] = mapped_column(Integer, default=5)
|
||||
max_video_count: Mapped[int] = mapped_column(Integer, default=2)
|
||||
generate_url: Mapped[str | None] = mapped_column(String(512), nullable=True, default="")
|
||||
query_url: Mapped[str | None] = mapped_column(String(512), nullable=True, default="")
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
|
||||
@@ -13,6 +13,8 @@ class VideoEngineCreate(BaseModel):
|
||||
supported_resolutions: str = Field(default='["480p","720p","1080p"]')
|
||||
supported_durations: str = Field(default='[4,5,6,7,8,9,10,11,12,13,14,15]')
|
||||
max_duration: int = Field(default=15)
|
||||
max_image_count: int = Field(default=5)
|
||||
max_video_count: int = Field(default=2)
|
||||
generate_url: str = Field(default="", max_length=512)
|
||||
query_url: str = Field(default="", max_length=512)
|
||||
is_active: bool = True
|
||||
@@ -33,6 +35,8 @@ class VideoEnginePublic(BaseModel):
|
||||
supported_ratios: list[str] = []
|
||||
supported_resolutions: list[str] = []
|
||||
supported_durations: list[int] = []
|
||||
max_image_count: int = 5
|
||||
max_video_count: int = 2
|
||||
|
||||
|
||||
class VideoEngineListResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user