feat: add character regeneration endpoint and integrate emotion limits for AI-generated scripts
This commit is contained in:
@@ -245,6 +245,54 @@ async def create_ai_script_project(
|
||||
return _project_to_response(project)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/regenerate-characters")
|
||||
async def regenerate_characters(
|
||||
project_id: int,
|
||||
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 in ("analyzing", "generating"):
|
||||
raise HTTPException(status_code=400, detail=f"Project is currently {project.status}, please wait")
|
||||
|
||||
cfg = project.script_config or {}
|
||||
is_nsfw = cfg.get("nsfw_mode", False)
|
||||
|
||||
if is_nsfw:
|
||||
from db.crud import can_user_use_nsfw
|
||||
if not can_user_use_nsfw(current_user):
|
||||
raise HTTPException(status_code=403, detail="NSFW access not granted")
|
||||
from db.crud import get_system_setting
|
||||
if not get_system_setting(db, "grok_api_key") or not get_system_setting(db, "grok_base_url"):
|
||||
raise HTTPException(status_code=400, detail="Grok config not set. Please configure Grok API key first.")
|
||||
from core.audiobook_service import generate_ai_script_nsfw
|
||||
service_fn = generate_ai_script_nsfw
|
||||
else:
|
||||
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 generate_ai_script
|
||||
service_fn = generate_ai_script
|
||||
|
||||
from core.database import SessionLocal
|
||||
user_id = current_user.id
|
||||
|
||||
async def run():
|
||||
async_db = SessionLocal()
|
||||
try:
|
||||
db_user = crud.get_user_by_id(async_db, user_id)
|
||||
await service_fn(project_id, db_user, async_db)
|
||||
finally:
|
||||
async_db.close()
|
||||
|
||||
asyncio.create_task(run())
|
||||
return {"message": "Character regeneration started", "project_id": project_id}
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/continue-script")
|
||||
async def continue_script(
|
||||
project_id: int,
|
||||
|
||||
Reference in New Issue
Block a user