054e81c3e7
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 3s
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / Check push changed paths (push) Successful in 1m1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 8s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 49s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m9s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 53s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m9s
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 / Integration Tests (push) Successful in 4m14s
PR Automation / Auto Merge on CI Green + Approved (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 / Validate - Python (mypy + alembic) (push) Successful in 4m27s
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 / PR Build API Image (pull_request) Successful in 1m26s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m48s
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 56s
CI/CD Pipeline / Validate - Style (push) Successful in 4m57s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 4m59s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m10s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
CI/CD Pipeline / Validate - Security (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
"""爆款视频 5 套 Prompt 模板种子脚本(#2040)。
|
||
|
||
幂等:以 (prompt_type, version) 为唯一键,存在则更新(UPSERT),重复执行结果一致。
|
||
用法:
|
||
python scripts/seed_viral_video_prompts.py # 自动用应用配置连库
|
||
DATABASE_URL=postgresql+psycopg2://... python scripts/seed_viral_video_prompts.py
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import sys
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
import sqlalchemy as sa # noqa: E402
|
||
|
||
from packages.application.viral_video.prompts import DEFAULT_TEMPLATES # noqa: E402
|
||
|
||
|
||
def _engine():
|
||
database_url = os.environ.get("DATABASE_URL")
|
||
if database_url:
|
||
return sa.create_engine(database_url)
|
||
# 复用应用自身配置
|
||
from packages.config import get_shared_settings
|
||
|
||
url = str(get_shared_settings().database_url)
|
||
return sa.create_engine(url.replace("postgresql+asyncpg://", "postgresql+psycopg2://"))
|
||
|
||
|
||
UPSERT_SQL = sa.text("""
|
||
INSERT INTO viral_video_prompt_templates
|
||
(name, prompt_type, version, system_prompt, user_prompt_template,
|
||
example_output, is_active, updated_at)
|
||
VALUES
|
||
(:name, :prompt_type, :version, :system_prompt, :user_prompt_template,
|
||
:example_output, TRUE, :now_ts)
|
||
ON CONFLICT (prompt_type, version) DO UPDATE SET
|
||
name = EXCLUDED.name,
|
||
system_prompt = EXCLUDED.system_prompt,
|
||
user_prompt_template = EXCLUDED.user_prompt_template,
|
||
example_output = EXCLUDED.example_output,
|
||
is_active = TRUE,
|
||
updated_at = :now_ts
|
||
""")
|
||
|
||
|
||
def seed(engine) -> int:
|
||
count = 0
|
||
from datetime import datetime, timezone
|
||
|
||
now_ts = datetime.now(timezone.utc)
|
||
with engine.begin() as conn:
|
||
for item in DEFAULT_TEMPLATES:
|
||
conn.execute(
|
||
UPSERT_SQL,
|
||
{
|
||
"name": item["name"],
|
||
"prompt_type": item["prompt_type"],
|
||
"version": item["version"],
|
||
"system_prompt": item["system_prompt"],
|
||
"user_prompt_template": item["user_prompt_template"],
|
||
"example_output": item["example_output"],
|
||
"now_ts": now_ts,
|
||
},
|
||
)
|
||
count += 1
|
||
return count
|
||
|
||
|
||
def main() -> int:
|
||
engine = _engine()
|
||
count = seed(engine)
|
||
print(f"seed 完成:{count} 套模板已写入/更新(image_analysis/intent_parsing/copy_fusion/storyboard/review)")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|