From 05d75db0cf3cc7099dca8d273a812dc7ab17b3f1 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Sat, 29 Aug 2026 17:54:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E7=B4=A0?= =?UTF-8?q?=E6=9D=90=E9=80=89=E5=8F=96=20random=20=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - generation_tasks.py: 删除 import random、if mode==random 分支、docstring 中 random 描述 - generation_task.py schema: description 移除 random=随机选取,count 描述仅保留 smart - 选取入口条件 in ("random","smart") 改为 in ("smart",) - test_asset_select_mode.py: 删除 TestSelectAssetsRandomMode 类(3个用例) - domain/test_generation_task.py + test_wave77_generation_task.py: random→smart 不改:_calc_random_start_time(片段级随机)、smart_match.py、前端 --- apps/api/app/api/routes/generation_tasks.py | 15 ++++----------- apps/api/app/schemas/generation_task.py | 4 ++-- tests/unit/domain/test_generation_task.py | 4 ++-- tests/unit/test_asset_select_mode.py | 20 -------------------- tests/unit/test_wave77_generation_task.py | 4 ++-- 5 files changed, 10 insertions(+), 37 deletions(-) diff --git a/apps/api/app/api/routes/generation_tasks.py b/apps/api/app/api/routes/generation_tasks.py index df4d73e51..13e361ba0 100755 --- a/apps/api/app/api/routes/generation_tasks.py +++ b/apps/api/app/api/routes/generation_tasks.py @@ -1,5 +1,4 @@ import logging -import random import uuid from typing import Any @@ -116,8 +115,8 @@ def _select_assets_from_library( Args: assets: 素材库中所有素材(Asset 实体列表) - mode: 选取模式 — all=全部, random=随机, smart=智能匹配(多维度评分+多样性) - count: 选取数量,0 表示全部(仅 random/smart 模式有效) + mode: 选取模式 — all=全部, smart=智能匹配(多维度评分+多样性) + count: 选取数量,0 表示全部(仅 smart 模式有效) Returns: 选中的素材 ID 列表 @@ -127,12 +126,6 @@ def _select_assets_from_library( if not ready_video_assets: return [] - if mode == "random": - selected = ( - ready_video_assets if count <= 0 else random.sample(ready_video_assets, min(count, len(ready_video_assets))) - ) - return [a.id for a in selected] - if mode == "smart": # 智能匹配:统一使用 packages/domain/smart_match.py 的多维评分+多样性选取 # 评分维度:质量分(40%) + 时长适配(30%) + 新鲜度(20%) + 未使用加分(10%) @@ -292,8 +285,8 @@ def create_generation_task( mode=request.asset_select_mode, count=request.asset_select_count, ) - elif project_id and not resolved_asset_ids and request.asset_select_mode in ("random", "smart"): - # 项目级模式:未指定 asset_ids 且选择了 random/smart 模式时,也自动选取 + elif project_id and not resolved_asset_ids and request.asset_select_mode in ("smart",): + # 项目级模式:未指定 asset_ids 且选择了 smart 模式时,也自动选取 assets = asset_repository.find_by_project(project_id) if assets: resolved_asset_ids = _select_assets_from_library( diff --git a/apps/api/app/schemas/generation_task.py b/apps/api/app/schemas/generation_task.py index 814cc5a20..896228db1 100755 --- a/apps/api/app/schemas/generation_task.py +++ b/apps/api/app/schemas/generation_task.py @@ -45,10 +45,10 @@ class CreateGenerationTaskRequest(BaseModel): # ── 素材库自动匹配 ── asset_select_mode: str = Field( default="all", - description="素材选取模式:all=全部ready视频, random=随机选取, smart=智能匹配(按质量/时长评分)", + description="素材选取模式:all=全部ready视频, smart=智能匹配(按质量/时长评分)", ) asset_select_count: int = Field( - default=0, ge=0, le=100, description="选取数量,0表示全部(仅 random/smart 模式有效)" + default=0, ge=0, le=100, description="选取数量,0表示全部(仅 smart 模式有效)" ) # ── 自动重试 ── auto_retry_enabled: bool = Field( diff --git a/tests/unit/domain/test_generation_task.py b/tests/unit/domain/test_generation_task.py index edca75f5c..cb2c9a831 100644 --- a/tests/unit/domain/test_generation_task.py +++ b/tests/unit/domain/test_generation_task.py @@ -63,7 +63,7 @@ class TestGenerationTaskCreate: voice_ids=["v1"], created_by_user_id=" user1 ", source_edit_plan_id=" plan1 ", - asset_select_mode="random", + asset_select_mode="smart", batch_id="batch1", ) assert task.project_id == "proj1" @@ -76,7 +76,7 @@ class TestGenerationTaskCreate: assert task.voice_ids == ["v1"] assert task.created_by_user_id == "user1" assert task.source_edit_plan_id == "plan1" - assert task.asset_select_mode == "random" + assert task.asset_select_mode == "smart" assert task.batch_id == "batch1" def test_create_with_template_instead_of_project(self): diff --git a/tests/unit/test_asset_select_mode.py b/tests/unit/test_asset_select_mode.py index 86e3662b2..9e7f8ca3b 100644 --- a/tests/unit/test_asset_select_mode.py +++ b/tests/unit/test_asset_select_mode.py @@ -97,26 +97,6 @@ class TestSelectAssetsAllMode: assert result == [] -class TestSelectAssetsRandomMode: - """random 模式:随机选取 N 个。""" - - def test_random_selects_exact_count(self): - assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(10)] - result = _select_assets_from_library(assets, mode="random", count=3) - assert len(result) == 3 - assert all(rid in [a.id for a in assets] for rid in result) - - def test_random_count_zero_returns_all(self): - assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(5)] - result = _select_assets_from_library(assets, mode="random", count=0) - assert len(result) == 5 - - def test_random_count_exceeds_total_returns_all(self): - assets = [_asset(f"a{i}", f"v{i}.mp4") for i in range(3)] - result = _select_assets_from_library(assets, mode="random", count=100) - assert len(result) == 3 - - class TestSelectAssetsSmartMode: """smart 模式:使用 smart_match 多维评分(质量40%+时长30%+新鲜度20%+未使用10%)。""" diff --git a/tests/unit/test_wave77_generation_task.py b/tests/unit/test_wave77_generation_task.py index 5d9c24ebb..f7ed1d3b6 100755 --- a/tests/unit/test_wave77_generation_task.py +++ b/tests/unit/test_wave77_generation_task.py @@ -116,7 +116,7 @@ class TestGenerationTaskCreate: voice_ids=["v1"], created_by_user_id="u1", source_edit_plan_id="ep1", - asset_select_mode="random", + asset_select_mode="smart", batch_id="batch_001", video_title="测试视频", resolution="1080p", @@ -132,7 +132,7 @@ class TestGenerationTaskCreate: assert task.voice_ids == ["v1"] assert task.created_by_user_id == "u1" assert task.source_edit_plan_id == "ep1" - assert task.asset_select_mode == "random" + assert task.asset_select_mode == "smart" assert task.batch_id == "batch_001" assert task.video_title == "测试视频" assert task.resolution == "1080p" -- 2.54.0 From 5a00f8b8fb750c9f8e5fb40e58c5201a90feeb5c Mon Sep 17 00:00:00 2001 From: CI Bot Date: Sat, 29 Aug 2026 10:02:10 +0000 Subject: [PATCH 2/2] style: auto-format with black + isort + prettier [skip ci-format-check] --- apps/api/app/schemas/generation_task.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/api/app/schemas/generation_task.py b/apps/api/app/schemas/generation_task.py index 896228db1..bead763e3 100755 --- a/apps/api/app/schemas/generation_task.py +++ b/apps/api/app/schemas/generation_task.py @@ -47,9 +47,7 @@ class CreateGenerationTaskRequest(BaseModel): default="all", description="素材选取模式:all=全部ready视频, smart=智能匹配(按质量/时长评分)", ) - asset_select_count: int = Field( - default=0, ge=0, le=100, description="选取数量,0表示全部(仅 smart 模式有效)" - ) + asset_select_count: int = Field(default=0, ge=0, le=100, description="选取数量,0表示全部(仅 smart 模式有效)") # ── 自动重试 ── auto_retry_enabled: bool = Field( default=False, -- 2.54.0