first commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from models.schemas import PersonaCreate
|
||||
from services.personas import get_all_personas, get_persona, create_persona, delete_persona
|
||||
|
||||
router = APIRouter(prefix="/personas", tags=["personas"])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def list_personas():
|
||||
personas = await get_all_personas()
|
||||
return [{"persona_id": pid, **data} for pid, data in personas.items()]
|
||||
|
||||
|
||||
@router.get("/{persona_id}")
|
||||
async def get_one_persona(persona_id: str):
|
||||
persona = await get_persona(persona_id)
|
||||
if not persona:
|
||||
raise HTTPException(status_code=404, detail="Персонаж не найден")
|
||||
return {"persona_id": persona_id, **persona}
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def create_new_persona(data: PersonaCreate):
|
||||
persona = await create_persona(
|
||||
persona_id=data.persona_id,
|
||||
name=data.name,
|
||||
emoji=data.emoji,
|
||||
description=data.description,
|
||||
prompt=data.prompt,
|
||||
sd_enabled=data.sd_enabled,
|
||||
lora_name=data.lora_name,
|
||||
lora_weight=data.lora_weight,
|
||||
appearance_tags=data.appearance_tags,
|
||||
)
|
||||
return {"persona_id": data.persona_id, **persona}
|
||||
|
||||
|
||||
@router.delete("/{persona_id}")
|
||||
async def remove_persona(persona_id: str):
|
||||
if not await delete_persona(persona_id):
|
||||
raise HTTPException(status_code=400, detail="Нельзя удалить встроенного персонажа")
|
||||
return {"status": "deleted", "persona_id": persona_id}
|
||||
Reference in New Issue
Block a user