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..bead763e3 100755 --- a/apps/api/app/schemas/generation_task.py +++ b/apps/api/app/schemas/generation_task.py @@ -45,11 +45,9 @@ class CreateGenerationTaskRequest(BaseModel): # ── 素材库自动匹配 ── asset_select_mode: str = Field( default="all", - description="素材选取模式:all=全部ready视频, random=随机选取, smart=智能匹配(按质量/时长评分)", - ) - asset_select_count: int = Field( - default=0, ge=0, le=100, description="选取数量,0表示全部(仅 random/smart 模式有效)" + description="素材选取模式:all=全部ready视频, smart=智能匹配(按质量/时长评分)", ) + asset_select_count: int = Field(default=0, ge=0, le=100, description="选取数量,0表示全部(仅 smart 模式有效)") # ── 自动重试 ── auto_retry_enabled: bool = Field( default=False, 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"