This commit is contained in:
2026-06-09 11:26:28 +03:00
parent 94735fd540
commit 244935e4ac
21 changed files with 886 additions and 15 deletions
+2 -1
View File
@@ -1,8 +1,9 @@
from fastapi import APIRouter
from app.api.routes import chat, health, pomodoro
from app.api.routes import character, chat, health, pomodoro
api_router = APIRouter(prefix="/api/v1")
api_router.include_router(health.router, tags=["health"])
api_router.include_router(chat.router, prefix="/chat", tags=["chat"])
api_router.include_router(pomodoro.router, prefix="/pomodoro", tags=["pomodoro"])
api_router.include_router(character.router, tags=["character"])
+56
View File
@@ -0,0 +1,56 @@
from typing import Any
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, Field
from app.character.service import CharacterService
router = APIRouter()
class CharacterCardData(BaseModel):
name: str = "Ассистент"
description: str = ""
personality: str = ""
scenario: str = ""
first_mes: str = ""
mes_example: str = ""
system_prompt: str = ""
post_history_instructions: str = ""
tags: list[str] = Field(default_factory=list)
creator: str = ""
creator_notes: str = ""
alternate_greetings: list[str] = Field(default_factory=list)
character_version: str = "1.0"
class CharacterCardV2(BaseModel):
spec: str = "chara_card_v2"
spec_version: str = "2.0"
data: CharacterCardData
@router.get("/character")
def get_character() -> dict[str, Any]:
return CharacterService().get_card()
@router.put("/character")
def update_character(payload: CharacterCardV2) -> dict[str, Any]:
return CharacterService().save_card(payload.model_dump())
@router.get("/character/prompt")
def get_character_prompt() -> dict[str, str]:
service = CharacterService()
return {
"system_prompt": service.get_system_prompt(),
"first_mes": service.get_card().get("data", {}).get("first_mes", ""),
}
@router.post("/character/import")
def import_character(payload: dict[str, Any]) -> dict[str, Any]:
if not payload:
raise HTTPException(status_code=400, detail="Empty card")
return CharacterService().save_card(payload)