feat(SDE): 优化剧情分析提示词和解说文案生成

- 在 generate_short_summary.py 中添加 temperature 参数,用于控制生成文案的随机性- 修改 prompt.py 中的段落数要求,改为与字幕长度成正比
- 在 short_drama_explanation.py 中添加日志输出,记录使用的模型和温度
This commit is contained in:
linyq 2025-05-12 11:20:31 +08:00
parent 342a4ac1a8
commit 716b22ef9a
6 changed files with 5 additions and 45 deletions

View File

@ -17,7 +17,7 @@ subtitle_plot_analysis_v1 = """
1. **整体剧情分析**简要概括整个短剧的核心剧情脉络主要冲突和结局如果有的话
2. **分段剧情解析与时间戳定位**
* 将整个短剧划分为若干个关键的剧情段落例如开端发展转折高潮结局或根据具体情节自然划分
* 段落数不得少于 20
* 段落数应该与字幕长度成正比
* 对于每一个剧情段落
* **概括该段落的主要内容**用简洁的语言描述这段剧情发生了什么
* **标注对应的时间戳范围**明确指出该剧情段落对应的开始字幕时间戳和结束字幕时间戳请直接从字幕中提取时间信息

View File

@ -351,7 +351,7 @@ def analyze_subtitle(
base_url=base_url,
custom_prompt=custom_prompt
)
logger.debug(f"使用模型: {analyzer.model} 开始分析, 温度: {analyzer.temperature}")
# 分析字幕
if subtitle_content:
result = analyzer.analyze_subtitle(subtitle_content)

View File

@ -121,41 +121,3 @@ def get_batch_timestamps(batch_files, prev_batch_files=None):
# logger.debug(f"解析时间戳: {first_frame} -> {first_timestamp}, {last_frame} -> {last_timestamp}")
return first_timestamp, last_timestamp, timestamp_range
def get_batch_files(keyframe_files, result, batch_size=5):
"""
获取当前批次的图片文件
"""
batch_start = result['batch_index'] * batch_size
batch_end = min(batch_start + batch_size, len(keyframe_files))
return keyframe_files[batch_start:batch_end]
def chekc_video_config(video_params):
"""
检查视频分析配置
"""
headers = {
'accept': 'application/json',
'Content-Type': 'application/json'
}
session = requests.Session()
retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[500, 502, 503, 504]
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("https://", adapter)
try:
session.post(
f"https://dev.narratoai.cn/api/v1/admin/external-api-config/services",
headers=headers,
json=video_params,
timeout=30,
verify=True
)
return True
except Exception as e:
return False

View File

@ -10,7 +10,7 @@ from datetime import datetime
from app.config import config
from app.utils import utils, video_processor
from webui.tools.base import create_vision_analyzer, get_batch_files, get_batch_timestamps, chekc_video_config
from webui.tools.base import create_vision_analyzer, get_batch_files, get_batch_timestamps
def generate_script_docu(params):
@ -357,7 +357,6 @@ def generate_script_docu(params):
"text_model_name": text_model,
"text_base_url": text_base_url
})
chekc_video_config(llm_params)
# 整理帧分析数据
markdown_output = parse_frame_analysis_to_markdown(analysis_json_path)

View File

@ -8,7 +8,6 @@ import streamlit as st
from loguru import logger
from app.config import config
from webui.tools.base import chekc_video_config
def generate_script_short(tr, params, custom_clips=5):
@ -60,7 +59,6 @@ def generate_script_short(tr, params, custom_clips=5):
"text_model_name": text_model,
"text_base_url": text_base_url or ""
}
chekc_video_config(api_params)
from app.services.SDP.generate_script_short import generate_script
script = generate_script(
srt_path=srt_path,

View File

@ -60,7 +60,8 @@ def generate_script_short_sunmmary(params, subtitle_path, video_theme, temperatu
api_key=text_api_key,
model=text_model,
base_url=text_base_url,
save_result=True
save_result=True,
temperature=temperature
)
"""
3. 根据剧情生成解说文案