feat: refactor LLM model retrieval to use system settings and improve error handling for LLM configuration

This commit is contained in:
2026-03-13 16:07:00 +08:00
parent cdb9d2ebb8
commit 786254cb81
2 changed files with 26 additions and 21 deletions

View File

@@ -777,7 +777,7 @@ async def analyze_project(project_id: int, user: User, db: Session, turbo: bool
previews_dir.mkdir(parents=True, exist_ok=True)
mode_label = "极速并发" if turbo else "顺序"
ps.append_line(key, f"\n[LLM] 模型:{user.llm_model},共 {n} 个采样段({mode_label}模式),正在分析角色...\n")
ps.append_line(key, f"\n[LLM] 模型:{crud.get_system_setting(db, 'llm_model')},共 {n} 个采样段({mode_label}模式),正在分析角色...\n")
ps.append_line(key, "")
def on_token(token: str) -> None:
@@ -1144,7 +1144,7 @@ async def generate_project(project_id: int, user: User, db: Session, chapter_ind
continue
indextts2 = IndexTTS2Backend()
audio_bytes = await indextts2.generate(
await indextts2.generate(
text=seg.text,
spk_audio_prompt=ref_audio,
output_path=str(audio_path),
@@ -1152,9 +1152,6 @@ async def generate_project(project_id: int, user: User, db: Session, chapter_ind
emo_alpha=seg.emo_alpha if seg.emo_alpha is not None else 0.3,
)
with open(audio_path, "wb") as f:
f.write(audio_bytes)
crud.update_audiobook_segment_status(db, seg.id, "done", audio_path=str(audio_path))
logger.info(f"Segment {seg.id} generated: {audio_path}")
@@ -1226,7 +1223,7 @@ async def generate_single_segment(segment_id: int, user: User, db: Session) -> N
return
indextts2 = IndexTTS2Backend()
audio_bytes = await indextts2.generate(
await indextts2.generate(
text=seg.text,
spk_audio_prompt=ref_audio,
output_path=str(audio_path),
@@ -1234,9 +1231,6 @@ async def generate_single_segment(segment_id: int, user: User, db: Session) -> N
emo_alpha=seg.emo_alpha if seg.emo_alpha is not None else 0.3,
)
with open(audio_path, "wb") as f:
f.write(audio_bytes)
crud.update_audiobook_segment_status(db, segment_id, "done", audio_path=str(audio_path))
logger.info(f"Single segment {segment_id} generated: {audio_path}")
@@ -1277,7 +1271,7 @@ async def parse_all_chapters(project_id: int, user: User, db: Session, statuses:
semaphore = asyncio.Semaphore(max_concurrent)
logger.info(f"parse_all_chapters: project={project_id}, {len(pending)} chapters, concurrency={max_concurrent}")
key = f"project_{project_id}"
key = str(project_id)
ps.append_line(key, f"\n[状态] 开启章节并发解析,共 {len(pending)} 章待处理,最大并发: {max_concurrent}...\n")
async def parse_with_limit(chapter):