This commit is contained in:
commit
46af290db3
100 files changed
+16663
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,95 @@
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from models.bible import StoryBible
|
||||
|
||||
|
||||
class GenerateRequest(BaseModel):
|
||||
prompt: str
|
||||
provider: Literal["ollama", "openrouter"] = "ollama"
|
||||
model: Optional[str] = None
|
||||
api_key: Optional[str] = None # Опционально, обычно берется из .env
|
||||
preset: Literal["creative_draft", "editor", "brainstorm"] = "creative_draft"
|
||||
options: Optional[Dict[str, Any]] = None
|
||||
story_bible: Optional[StoryBible] = None # Story Bible для контекста
|
||||
selected_text: Optional[str] = None # Текст, который будет обрабатываться
|
||||
|
||||
|
||||
class GenerateResponse(BaseModel):
|
||||
generated_text: str
|
||||
provider: str
|
||||
model: str
|
||||
preset: str
|
||||
|
||||
|
||||
class ExtractedEntities(BaseModel):
|
||||
new_characters: List[Dict[str, Any]] = []
|
||||
new_locations: List[Dict[str, Any]] = []
|
||||
new_events: List[Dict[str, Any]] = []
|
||||
updated_traits: List[Dict[str, Any]] = []
|
||||
|
||||
|
||||
class ExtractEntitiesRequest(BaseModel):
|
||||
text: str
|
||||
existing_bible: Optional[StoryBible] = None
|
||||
task_type: str = "background"
|
||||
|
||||
|
||||
class ExtractEntitiesResponse(BaseModel):
|
||||
entities: ExtractedEntities
|
||||
model_used: str
|
||||
provider: str
|
||||
|
||||
|
||||
class AutoUpdateBibleRequest(BaseModel):
|
||||
project_id: str
|
||||
scene_text: str
|
||||
auto_update_enabled: bool = True
|
||||
|
||||
|
||||
class AutoUpdateBibleResponse(BaseModel):
|
||||
updated: bool
|
||||
new_characters: int = 0
|
||||
new_locations: int = 0
|
||||
new_events: int = 0
|
||||
message: str = ""
|
||||
|
||||
|
||||
class CleanupDuplicatesResponse(BaseModel):
|
||||
removed_characters: int = 0
|
||||
removed_locations: int = 0
|
||||
removed_events: int = 0
|
||||
message: str = ""
|
||||
|
||||
|
||||
class PreviewContextRequest(BaseModel):
|
||||
text: str
|
||||
story_bible: StoryBible
|
||||
|
||||
|
||||
class PreviewContextResponse(BaseModel):
|
||||
context_string: str
|
||||
mentioned_characters: List[str]
|
||||
mentioned_locations: List[str]
|
||||
mentioned_events: List[str]
|
||||
|
||||
|
||||
class GenerateImageRequest(BaseModel):
|
||||
prompt: str
|
||||
project_id: str
|
||||
document_id: str # ID документа (книги или главы)
|
||||
document_type: str # 'book' или 'chapter'
|
||||
model: Optional[str] = None
|
||||
size: str = "1024x1024"
|
||||
|
||||
|
||||
class GenerateImageResponse(BaseModel):
|
||||
image_id: str
|
||||
filename: str
|
||||
path: str
|
||||
prompt: str
|
||||
model: str
|
||||
data_url: str # base64 изображение для немедленного отображения
|
||||
document_id: str # ID документа, к которому привязано изображение
|
||||
document_type: str # 'book' или 'chapter'
|
||||
@@ -0,0 +1,46 @@
|
||||
from typing import List, Literal, Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Character(BaseModel):
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
name: str
|
||||
description: str = ""
|
||||
traits: List[str] = [] # Характер, привычки
|
||||
appearance: str = "" # Внешность
|
||||
role: Literal["protagonist", "antagonist", "supporting", "minor"] = "supporting"
|
||||
|
||||
|
||||
class Location(BaseModel):
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
name: str
|
||||
description: str = ""
|
||||
atmosphere: str = "" # Атмосфера, ощущения
|
||||
type: Literal["city", "building", "nature", "interior", "other"] = "other"
|
||||
|
||||
|
||||
class Event(BaseModel):
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
title: str
|
||||
description: str = ""
|
||||
chapter: Optional[str] = None # В какой главе произошло
|
||||
importance: Literal["major", "minor", "background"] = "minor"
|
||||
|
||||
|
||||
class StoryThread(BaseModel):
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
title: str
|
||||
description: str = ""
|
||||
status: Literal["active", "resolved", "abandoned"] = "active"
|
||||
related_characters: List[str] = [] # ID персонажей
|
||||
related_events: List[str] = [] # ID событий
|
||||
|
||||
|
||||
class StoryBible(BaseModel):
|
||||
characters: List[Character] = []
|
||||
locations: List[Location] = []
|
||||
events: List[Event] = []
|
||||
threads: List[StoryThread] = []
|
||||
last_updated: Optional[str] = None # ISO timestamp
|
||||
@@ -0,0 +1,51 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class DocumentNode(BaseModel):
|
||||
"""Иерархическая модель документа: Книга → Глава → Сцена"""
|
||||
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
project_id: str
|
||||
parent_id: Optional[str] = None
|
||||
title: str = Field(..., min_length=1, max_length=200)
|
||||
content: str = ""
|
||||
type: str = Field(default="scene", pattern="^(book|chapter|scene)$")
|
||||
order: int = 0
|
||||
created_at: str = Field(default_factory=lambda: datetime.now().isoformat())
|
||||
updated_at: str = Field(default_factory=lambda: datetime.now().isoformat())
|
||||
|
||||
|
||||
# --- Модели для обратной совместимости (старый плоский формат) ---
|
||||
|
||||
|
||||
class DocumentBase(BaseModel):
|
||||
"""Базовая модель документа (legacy)"""
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=200)
|
||||
content: str = ""
|
||||
type: str = Field(default="scene", pattern="^(scene|chapter|bible)$")
|
||||
|
||||
|
||||
class DocumentCreate(DocumentBase):
|
||||
"""Модель для создания нового документа (legacy)"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DocumentUpdate(BaseModel):
|
||||
"""Модель для обновления контента документа (legacy)"""
|
||||
|
||||
content: str
|
||||
|
||||
|
||||
class DocumentResponse(DocumentBase):
|
||||
"""Модель ответа с документом (legacy)"""
|
||||
|
||||
id: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
@@ -0,0 +1,15 @@
|
||||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Project(BaseModel):
|
||||
id: str = Field(default_factory=lambda: str(uuid4()))
|
||||
user_id: str = (
|
||||
"" # Привязка к пользователю (пустой для старых проектов до миграции)
|
||||
)
|
||||
title: str
|
||||
description: str = ""
|
||||
created_at: str = Field(default_factory=lambda: datetime.now().isoformat())
|
||||
updated_at: str = Field(default_factory=lambda: datetime.now().isoformat())
|
||||
@@ -0,0 +1,28 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
email: str
|
||||
hashed_password: str
|
||||
|
||||
|
||||
class UserCreate(BaseModel):
|
||||
username: str
|
||||
email: str
|
||||
password: str
|
||||
|
||||
|
||||
class UserLogin(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
user_id: str
|
||||
username: str
|
||||
Reference in new issue
Block a user