Add rulebook RAG pipeline and LLM-driven game setup wizard
RAG: switch Postgres to pgvector, chunk and embed the three D&D rulebooks locally via sentence-transformers, and retrieve relevant excerpts per DM turn (query = latest player message) to ground the system prompt. Retrieval runs off the event loop and is capped by a relevance threshold and a max character budget so it can't blow up context size or cost. Game setup wizard: creating a game now opens a short chat where the DM asks about genre, length, and the player's experience level, then proposes a name and description via a tool call. The player can edit both before creating the game. Stateless endpoint — the frontend carries the conversation, no DB needed since the game doesn't exist yet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,11 +8,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.auth.users import current_active_user
|
||||
from app.db import get_async_session
|
||||
from app.llm.game_setup import run_game_setup_turn
|
||||
from app.models.character import Character
|
||||
from app.models.game import Game, GameParticipant
|
||||
from app.models.message import Message
|
||||
from app.models.user import User
|
||||
from app.schemas.game import GameCreate, GameJoin, GameRead
|
||||
from app.schemas.game_setup import GameSetupChatRequest, GameSetupChatResponse
|
||||
from app.schemas.message import MessageRead
|
||||
from app.ws_tickets import issue_ticket
|
||||
|
||||
@@ -108,6 +110,15 @@ async def create_game(
|
||||
return serialized[0]
|
||||
|
||||
|
||||
@router.post("/setup-chat", response_model=GameSetupChatResponse)
|
||||
async def game_setup_chat(
|
||||
payload: GameSetupChatRequest,
|
||||
user: User = Depends(current_active_user),
|
||||
) -> GameSetupChatResponse:
|
||||
result = await run_game_setup_turn(payload.messages)
|
||||
return GameSetupChatResponse(**result)
|
||||
|
||||
|
||||
@router.get("/{game_id}", response_model=GameRead)
|
||||
async def get_game(
|
||||
game_id: uuid.UUID,
|
||||
|
||||
Reference in New Issue
Block a user