feat: add continue script functionality for AI-generated audiobook projects
This commit is contained in:
@@ -25,6 +25,7 @@ from schemas.audiobook import (
|
||||
AudiobookAnalyzeRequest,
|
||||
ScriptGenerationRequest,
|
||||
SynopsisGenerationRequest,
|
||||
ContinueScriptRequest,
|
||||
)
|
||||
from core.config import settings
|
||||
|
||||
@@ -230,6 +231,43 @@ async def create_ai_script_project(
|
||||
return _project_to_response(project)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/continue-script")
|
||||
async def continue_script(
|
||||
project_id: int,
|
||||
data: ContinueScriptRequest,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
project = crud.get_audiobook_project(db, project_id, current_user.id)
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
if project.source_type != "ai_generated":
|
||||
raise HTTPException(status_code=400, detail="Only AI-generated projects support this operation")
|
||||
if project.status not in ("ready", "done", "error"):
|
||||
raise HTTPException(status_code=400, detail=f"Project must be in 'ready' or 'done' state, current: {project.status}")
|
||||
|
||||
from db.crud import get_system_setting
|
||||
if not get_system_setting(db, "llm_api_key") or not get_system_setting(db, "llm_base_url") or not get_system_setting(db, "llm_model"):
|
||||
raise HTTPException(status_code=400, detail="LLM config not set. Please configure LLM API key first.")
|
||||
|
||||
from core.audiobook_service import continue_ai_script_chapters
|
||||
from core.database import SessionLocal
|
||||
|
||||
additional_chapters = max(1, min(20, data.additional_chapters))
|
||||
user_id = current_user.id
|
||||
|
||||
async def run():
|
||||
async_db = SessionLocal()
|
||||
try:
|
||||
db_user = crud.get_user_by_id(async_db, user_id)
|
||||
await continue_ai_script_chapters(project_id, additional_chapters, db_user, async_db)
|
||||
finally:
|
||||
async_db.close()
|
||||
|
||||
asyncio.create_task(run())
|
||||
return {"message": f"Continuing script generation ({additional_chapters} chapters)", "project_id": project_id}
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}", response_model=AudiobookProjectDetail)
|
||||
async def get_project(
|
||||
project_id: int,
|
||||
|
||||
Reference in New Issue
Block a user