修复chat生成参数提交错误BUG|模型引擎积分设置关联开发优化成功|视频/图片生成引擎API开发完成
This commit is contained in:
@@ -651,6 +651,30 @@ async def delete_image_engine(
|
||||
return {"message": "ok"}
|
||||
|
||||
|
||||
|
||||
|
||||
async def _validate_credit_ratio_engine(db: AsyncSession, req: CreditRatioCreate) -> None:
|
||||
"""校验积分规则绑定的引擎是否存在。
|
||||
|
||||
CreditRatio.model_config_id 为兼容旧字段名,当前实际保存引擎ID:
|
||||
- gen_type=image 时对应 image_engines.id
|
||||
- gen_type=video 时对应 video_engines.id
|
||||
"""
|
||||
gen_type = (req.gen_type or "").lower().strip()
|
||||
engine_id = (req.model_config_id or "").strip()
|
||||
if gen_type not in ("image", "video"):
|
||||
raise HTTPException(status_code=400, detail="gen_type 仅支持 image 或 video")
|
||||
if not engine_id:
|
||||
raise HTTPException(status_code=400, detail="model_config_id 不能为空,当前字段用于保存图片/视频引擎ID")
|
||||
|
||||
model = ImageEngine if gen_type == "image" else VideoEngine
|
||||
result = await db.execute(select(model).where(model.id == engine_id).limit(1))
|
||||
engine = result.scalar_one_or_none()
|
||||
if not engine:
|
||||
detail = "图片积分规则绑定的图片引擎不存在" if gen_type == "image" else "视频积分规则绑定的视频引擎不存在"
|
||||
raise HTTPException(status_code=400, detail=detail)
|
||||
|
||||
|
||||
# ── Credit Ratio ─────────────────────────────────────────
|
||||
|
||||
@router.get("/credit-ratios", response_model=list[CreditRatioOut])
|
||||
@@ -668,7 +692,11 @@ async def create_credit_ratio(
|
||||
admin: User = Depends(get_admin_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
ratio = CreditRatio(id=generate_id(), **req.model_dump())
|
||||
await _validate_credit_ratio_engine(db, req)
|
||||
data = req.model_dump()
|
||||
data["gen_type"] = data["gen_type"].lower().strip()
|
||||
data["model_config_id"] = data["model_config_id"].strip()
|
||||
ratio = CreditRatio(id=generate_id(), **data)
|
||||
db.add(ratio)
|
||||
await db.flush()
|
||||
return ratio
|
||||
@@ -687,7 +715,11 @@ async def update_credit_ratio(
|
||||
ratio = result.scalar_one_or_none()
|
||||
if not ratio:
|
||||
raise HTTPException(status_code=404, detail="积分比例不存在")
|
||||
for k, v in req.model_dump().items():
|
||||
await _validate_credit_ratio_engine(db, req)
|
||||
data = req.model_dump()
|
||||
data["gen_type"] = data["gen_type"].lower().strip()
|
||||
data["model_config_id"] = data["model_config_id"].strip()
|
||||
for k, v in data.items():
|
||||
setattr(ratio, k, v)
|
||||
await db.flush()
|
||||
return ratio
|
||||
|
||||
Reference in New Issue
Block a user