2a739dee17
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 51s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m7s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m27s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m0s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m9s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 4m41s
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 5m0s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 10m11s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 18m38s
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 2s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
问题7(generate-copy 提速,目标 30-40s):
- 新增 doubao_fast_model 配置(默认 doubao-1-5-pro-32k-250115),结构化输出任务(意图解析/编导脚本/合规审核)改用快模型,不再使用慢推理模型 doubao-seed-1-6
- call_llm 扩展支持 model/max_tokens/system_prompt 参数;chat_completion 同步支持 model 覆盖
- 编导脚本 temperature 0.8 + max_tokens 2500(从 4096 收紧);意图解析 max_tokens 800;审核 max_tokens 500
- _SCRIPT_GENERATION_PROMPT 精简冗余描述(前导说明和关键要求章节从 ~70 行压到 ~30 行),减少输入/输出 token
- 合规审核异步后置:阶段2 generate-copy 只做关键字黑名单快速检查(不调用 LLM),LLM 深度审核移到阶段3 confirm-copy TTS 之前执行,不再阻塞前端展示脚本
- 新增 _quick_compliance_blacklist_check 处理常见广告法绝对化用语
问题8(细粒度 phase + phase_message):
- ViralVideoJob 新增 phase_message 字段(中文提示文案,前端轮询直接展示)
- SQLAlchemy ViralVideoJobModel 新增 current_stage/phase_message 列(current_stage 原已有但未持久化更新)
- repo 层 _to_domain/save/update 同步处理新字段
- alembic 090 迁移:幂等 ADD COLUMN phase_message VARCHAR(500)
- 新增 _set_stage 辅助:统一设置 current_stage + phase_message + Redis 推送 + DB 持久化
- 所有 celery task(analyze/generate-copy/render/one-click/resume)在关键节点调用 _set_stage 持久化阶段信息
- 阶段文案:analyzing_images→正在分析商品特征 / parsing_intent→正在解析文案意图 / generating_script→正在编排分镜脚本 / reviewing→合规审核中 / tts→正在合成AI配音 / rendering→正在生成视频 / uploading→正在上传视频
- ViralVideoJobResponse schema + _to_response 增加 current_stage/phase_message,前端轮询 GET /{job_id} 直接拿到
配套:
- .env.example + render_env.sh SHARED_SECRETS 补 DOUBAO_FAST_MODEL
- tests _FakeSettings/_make_job 同步新增字段
- _run_render_pipeline 兜底补生成分支不再同步调用 _step_review(由出片前统一审核处理)
246 lines
9.7 KiB
Python
Executable File
246 lines
9.7 KiB
Python
Executable File
"""爆款视频任务 SQLAlchemy 仓储实现。"""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from packages.adapters.sqlalchemy_impl.models import (
|
|
ViralVideoJobModel,
|
|
ViralVideoPromptTemplateModel,
|
|
ViralVideoStyleTemplateModel,
|
|
)
|
|
from packages.domain.viral_video import ViralVideoJob, ViralVideoStatus
|
|
|
|
|
|
def _to_domain(model: ViralVideoJobModel) -> ViralVideoJob:
|
|
"""ORM → 领域实体。"""
|
|
return ViralVideoJob(
|
|
id=model.id,
|
|
user_id=model.user_id,
|
|
images=list(model.images or []),
|
|
industry=model.industry or "",
|
|
target_customer=model.target_customer or "",
|
|
persona_id=model.persona_id or "",
|
|
viral_structure=model.viral_structure or "",
|
|
marketing_purpose=model.marketing_purpose or "",
|
|
bgm_preference=model.bgm_preference or "",
|
|
duration=model.duration or 15,
|
|
user_copy_text=model.user_copy_text or "",
|
|
fusion_level=model.fusion_level or "ai_polish",
|
|
reference_audio_path=model.reference_audio_path or "",
|
|
reference_video_url=getattr(model, "reference_video_url", "") or "",
|
|
style_strength=getattr(model, "style_strength", "medium") or "medium",
|
|
style_guide=dict(model.style_guide) if model.style_guide else None,
|
|
style_template_id=getattr(model, "style_template_id", "") or "",
|
|
voice_id=getattr(model, "voice_id", "") or "",
|
|
voice_source=getattr(model, "voice_source", "") or "",
|
|
video_ratio=getattr(model, "video_ratio", "9:16") or "9:16",
|
|
video_model=getattr(model, "video_model", "") or "",
|
|
status=ViralVideoStatus(model.status) if model.status else ViralVideoStatus.PENDING,
|
|
current_stage=getattr(model, "current_stage", "") or "",
|
|
phase_message=getattr(model, "phase_message", "") or "",
|
|
intent_result=dict(model.intent_result) if model.intent_result else None,
|
|
image_analysis=dict(model.image_analysis) if getattr(model, "image_analysis", None) else None,
|
|
storyboard=list(model.storyboard) if getattr(model, "storyboard", None) else None,
|
|
generated_copy_text=getattr(model, "generated_copy_text", "") or "",
|
|
copy_result=dict(model.copy_result) if getattr(model, "copy_result", None) else None,
|
|
result_video_url=model.result_video_url or "",
|
|
credits_cost=model.credits_cost or 0,
|
|
error_msg=model.error_msg or "",
|
|
retry_count=model.retry_count or 0,
|
|
started_at=model.started_at,
|
|
completed_at=model.completed_at,
|
|
created_at=model.created_at,
|
|
updated_at=model.updated_at,
|
|
)
|
|
|
|
|
|
class SQLAlchemyViralVideoJobRepository:
|
|
"""爆款视频任务仓储。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def save(self, job: ViralVideoJob) -> ViralVideoJob:
|
|
model = ViralVideoJobModel(
|
|
id=job.id,
|
|
user_id=job.user_id,
|
|
images=job.images,
|
|
industry=job.industry,
|
|
target_customer=job.target_customer,
|
|
persona_id=job.persona_id,
|
|
viral_structure=job.viral_structure,
|
|
marketing_purpose=job.marketing_purpose,
|
|
bgm_preference=job.bgm_preference,
|
|
duration=job.duration,
|
|
user_copy_text=job.user_copy_text,
|
|
fusion_level=job.fusion_level,
|
|
reference_audio_path=job.reference_audio_path,
|
|
reference_video_url=job.reference_video_url,
|
|
style_strength=job.style_strength,
|
|
style_guide=job.style_guide,
|
|
style_template_id=job.style_template_id,
|
|
voice_id=job.voice_id,
|
|
voice_source=job.voice_source,
|
|
video_ratio=job.video_ratio,
|
|
video_model=job.video_model,
|
|
status=job.status,
|
|
current_stage=job.current_stage or "",
|
|
phase_message=job.phase_message or "",
|
|
intent_result=job.intent_result,
|
|
image_analysis=job.image_analysis,
|
|
storyboard=job.storyboard,
|
|
generated_copy_text=job.generated_copy_text,
|
|
copy_result=job.copy_result,
|
|
result_video_url=job.result_video_url,
|
|
credits_cost=job.credits_cost,
|
|
error_msg=job.error_msg,
|
|
retry_count=job.retry_count,
|
|
started_at=job.started_at,
|
|
completed_at=job.completed_at,
|
|
created_at=job.created_at,
|
|
updated_at=job.updated_at,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
return job
|
|
|
|
def update(self, job: ViralVideoJob) -> None:
|
|
model = self.session.query(ViralVideoJobModel).filter(ViralVideoJobModel.id == job.id).first()
|
|
if model is None:
|
|
raise ValueError(f"ViralVideoJob {job.id} not found")
|
|
model.status = job.status
|
|
model.current_stage = job.current_stage or ""
|
|
model.phase_message = job.phase_message or ""
|
|
model.intent_result = job.intent_result
|
|
model.image_analysis = job.image_analysis
|
|
model.storyboard = job.storyboard
|
|
model.generated_copy_text = job.generated_copy_text or ""
|
|
model.copy_result = job.copy_result
|
|
model.result_video_url = job.result_video_url
|
|
model.credits_cost = job.credits_cost
|
|
model.error_msg = job.error_msg
|
|
model.retry_count = job.retry_count
|
|
model.started_at = job.started_at
|
|
model.completed_at = job.completed_at
|
|
model.style_guide = job.style_guide
|
|
# v1.5 three-stage: persist user-editable params so resume uses latest values
|
|
model.user_copy_text = job.user_copy_text
|
|
model.industry = job.industry
|
|
model.target_customer = job.target_customer
|
|
model.persona_id = job.persona_id
|
|
model.viral_structure = job.viral_structure
|
|
model.marketing_purpose = job.marketing_purpose
|
|
model.bgm_preference = job.bgm_preference
|
|
model.duration = job.duration
|
|
model.fusion_level = job.fusion_level
|
|
model.reference_audio_path = job.reference_audio_path
|
|
model.reference_video_url = job.reference_video_url
|
|
model.style_strength = job.style_strength
|
|
model.style_template_id = job.style_template_id
|
|
model.voice_id = job.voice_id or ""
|
|
model.voice_source = job.voice_source or ""
|
|
model.video_ratio = job.video_ratio or "9:16"
|
|
model.video_model = job.video_model or ""
|
|
model.updated_at = datetime.now(timezone.utc)
|
|
self.session.commit()
|
|
|
|
def get(self, job_id: str) -> ViralVideoJob | None:
|
|
model = self.session.query(ViralVideoJobModel).filter(ViralVideoJobModel.id == job_id).first()
|
|
if model is None:
|
|
return None
|
|
return _to_domain(model)
|
|
|
|
def list_by_user(self, user_id: str, limit: int = 50, offset: int = 0) -> list[ViralVideoJob]:
|
|
models = (
|
|
self.session.query(ViralVideoJobModel)
|
|
.filter(ViralVideoJobModel.user_id == user_id)
|
|
.order_by(ViralVideoJobModel.created_at.desc())
|
|
.offset(offset)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
return [_to_domain(m) for m in models]
|
|
|
|
def count_pending_by_user(self, user_id: str) -> int:
|
|
return (
|
|
self.session.query(ViralVideoJobModel)
|
|
.filter(
|
|
ViralVideoJobModel.user_id == user_id,
|
|
ViralVideoJobModel.status.in_(
|
|
["pending", "running", "wait_user_confirm", "image_analyzed", "copy_generated"]
|
|
),
|
|
)
|
|
.count()
|
|
)
|
|
|
|
|
|
class SQLAlchemyViralVideoStyleTemplateRepository:
|
|
"""风格模板仓储。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def list_all(self) -> list[dict]:
|
|
models = (
|
|
self.session.query(ViralVideoStyleTemplateModel)
|
|
.order_by(ViralVideoStyleTemplateModel.sort_order.asc())
|
|
.all()
|
|
)
|
|
return [
|
|
{
|
|
"id": m.id,
|
|
"name": m.name,
|
|
"description": m.description or "",
|
|
"thumbnail_url": m.thumbnail_url or "",
|
|
"style_config": dict(m.style_config) if m.style_config else {},
|
|
"is_system": m.is_system,
|
|
}
|
|
for m in models
|
|
]
|
|
|
|
def get(self, template_id: str) -> dict | None:
|
|
model = (
|
|
self.session.query(ViralVideoStyleTemplateModel)
|
|
.filter(ViralVideoStyleTemplateModel.id == template_id)
|
|
.first()
|
|
)
|
|
if model is None:
|
|
return None
|
|
return {
|
|
"id": model.id,
|
|
"name": model.name,
|
|
"description": model.description or "",
|
|
"thumbnail_url": model.thumbnail_url or "",
|
|
"style_config": dict(model.style_config) if model.style_config else {},
|
|
"is_system": model.is_system,
|
|
}
|
|
|
|
|
|
class SQLAlchemyViralVideoPromptTemplateRepository:
|
|
"""Prompt 模板仓储(由 #2040 seed,这里只读取)。"""
|
|
|
|
def __init__(self, session: Session):
|
|
self.session = session
|
|
|
|
def get_active_by_type(self, prompt_type: str) -> dict | None:
|
|
model = (
|
|
self.session.query(ViralVideoPromptTemplateModel)
|
|
.filter(
|
|
ViralVideoPromptTemplateModel.prompt_type == prompt_type,
|
|
ViralVideoPromptTemplateModel.is_active.is_(True),
|
|
)
|
|
.order_by(ViralVideoPromptTemplateModel.version.desc())
|
|
.first()
|
|
)
|
|
if model is None:
|
|
return None
|
|
return {
|
|
"id": model.id,
|
|
"prompt_type": model.prompt_type,
|
|
"name": model.name,
|
|
"content": model.content,
|
|
"variables": list(model.variables or []),
|
|
"version": model.version,
|
|
}
|