419f5e3a89
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>
24 lines
560 B
Python
24 lines
560 B
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from openai import AsyncOpenAI
|
|
|
|
from app.config import settings
|
|
|
|
PROMPTS_DIR = Path(__file__).parent / "prompts"
|
|
|
|
|
|
@lru_cache
|
|
def get_dm_system_prompt() -> str:
|
|
return (PROMPTS_DIR / "dm_system_prompt.txt").read_text(encoding="utf-8")
|
|
|
|
|
|
@lru_cache
|
|
def get_game_setup_prompt() -> str:
|
|
return (PROMPTS_DIR / "game_setup_prompt.txt").read_text(encoding="utf-8")
|
|
|
|
|
|
@lru_cache
|
|
def get_llm_client() -> AsyncOpenAI:
|
|
return AsyncOpenAI(api_key=settings.xai_api_key, base_url=settings.xai_base_url)
|